diff options
-rw-r--r-- | runtime/probes/where_func/Makefile | 18 | ||||
-rwxr-xr-x | runtime/probes/where_func/build | 16 | ||||
-rw-r--r-- | runtime/probes/where_func/kprobe_where_funct.c | 57 |
3 files changed, 31 insertions, 60 deletions
diff --git a/runtime/probes/where_func/Makefile b/runtime/probes/where_func/Makefile index 431ddc4f..30a3a41f 100644 --- a/runtime/probes/where_func/Makefile +++ b/runtime/probes/where_func/Makefile @@ -1,11 +1,23 @@ # Makefile -# -# -# make -C path/to/kernel/src M=`pwd` modules STP_RUNTIME=path_to_systemtap_rt + +PWD := $(shell pwd) +KVERSION := $(shell uname -r) +KDIR := /lib/modules/$(KVERSION)/build include + +KALLSYMS_LOOKUP_NAME := $(firstword $(shell grep " kallsyms_lookup_name" /boot/System.map-$(KVERSION))) +KALLSYMS_LOOKUP := $(firstword $(shell grep " kallsyms_lookup$$" /boot/System.map-$(KVERSION))) +KTA := $(firstword $(shell grep "__kernel_text_address" /boot/System.map-$(KVERSION))) CFLAGS += -I $(STP_RUNTIME) -I $(STP_RUNTIME)/relayfs -D KALLSYMS_LOOKUP_NAME=$(KALLSYMS_LOOKUP_NAME) \ -D KALLSYMS_LOOKUP=$(KALLSYMS_LOOKUP) + obj-m := kprobe_where_funct.o +default: + $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules \ + KALLSYMS_LOOKUP_NAME=0x$(KALLSYMS_LOOKUP_NAME) \ + KALLSYMS_LOOKUP=0x$(KALLSYMS_LOOKUP) KTA=0x$(KTA)\ + STP_RUNTIME=$(PWD)/../.. + clean: /bin/rm -rf *.o *.ko *~ *.mod.c .*.cmd .tmp_versions diff --git a/runtime/probes/where_func/build b/runtime/probes/where_func/build deleted file mode 100755 index 3713f08a..00000000 --- a/runtime/probes/where_func/build +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -KVERSION=`uname -r` -echo $KVERSION -KALLSYMS_LOOKUP_NAME=`grep " kallsyms_lookup_name" /boot/System.map-$KVERSION |awk '{print $1}'` -KALLSYMS_LOOKUP=`grep " kallsyms_lookup$" /boot/System.map-$KVERSION |awk '{print $1}'` - -make V=1 -C /lib/modules/`uname -r`/build M=`pwd` modules \ - KALLSYMS_LOOKUP_NAME=0x$KALLSYMS_LOOKUP_NAME \ - KALLSYMS_LOOKUP=0x$KALLSYMS_LOOKUP \ - STP_RUNTIME=`pwd`/../.. - - - - - diff --git a/runtime/probes/where_func/kprobe_where_funct.c b/runtime/probes/where_func/kprobe_where_funct.c index 960f2290..d75d70f9 100644 --- a/runtime/probes/where_func/kprobe_where_funct.c +++ b/runtime/probes/where_func/kprobe_where_funct.c @@ -1,19 +1,23 @@ /* kprobe_where_funct.c - this is a simple module to get information about calls to a function that is passed as a module option + this is a simple module to get information about calls to a function + that is passed as a module option Will Cohen */ -#define HASH_TABLE_BITS 8 -#define HASH_TABLE_SIZE (1<<HASH_TABLE_BITS) -#define BUCKETS 16 /* largest histogram width */ #define STP_NETLINK_ONLY #define STP_NUM_STRINGS 1 - #include "runtime.h" + +#define KEY1_TYPE INT64 +#include "map-keys.c" + +#define VALUE_TYPE INT64 +#include "map-values.c" + #include "map.c" #include "probes.c" -#include "current.c" #include "sym.c" +#include "current.c" MODULE_DESCRIPTION("SystemTap probe: where_func"); MODULE_AUTHOR("Will Cohen and Martin Hunt"); @@ -23,17 +27,14 @@ static char *funct_name = default_name; module_param(funct_name, charp, 0); MODULE_PARM_DESC(funct_name, "function entry name.\n"); -static int count_funct = 0; - MAP funct_locations; static int inst_funct(struct kprobe *p, struct pt_regs *regs) { - long ret_addr = _stp_ret_addr(regs); - ++count_funct; - _stp_map_key_long(funct_locations, ret_addr); - _stp_map_add_int64(funct_locations, 1); - return 0; + long ret_addr = _stp_ret_addr(regs); + _stp_map_key_int64(funct_locations, ret_addr); + _stp_map_add_int64(funct_locations, 1); + return 0; } /*For each probe you need to allocate a kprobe structure*/ @@ -45,13 +46,6 @@ static struct kprobe kp[] = { }; #define MAX_KPROBES (sizeof(kp)/sizeof(struct kprobe)) -static unsigned n_subbufs = 4; -module_param(n_subbufs, uint, 0); -MODULE_PARM_DESC(n_subbufs, "number of sub-buffers per per-cpu buffer"); - -static unsigned subbuf_size = 65536; -module_param(subbuf_size, uint, 0); -MODULE_PARM_DESC(subbuf_size, "size of each per-cpu sub-buffers"); static int pid; module_param(pid, int, 0); @@ -71,7 +65,7 @@ int init_module(void) return -1; } - funct_locations = _stp_map_new(1000, INT64); + funct_locations = _stp_map_new_int64 (1000, INT64); if (funct_name) kp[0].addr = funct_name; @@ -81,35 +75,16 @@ int init_module(void) return ret; } -static int exited; /* FIXME: this is a stopgap - if we don't do this - * and are manually removed, bad things happen */ - static void probe_exit (void) { - struct map_node_int64 *ptr; - - exited = 1; - _stp_unregister_kprobes (kp, MAX_KPROBES); - _stp_printf("%s() called %d times.\n", funct_name, count_funct); - _stp_printf("NUM\tCaller\n", funct_name); - - /* now walk the hash table and print out all the information */ - foreach(funct_locations, ptr) { - _stp_printf("%lld\t", ptr->val); - _stp_symbol_print (key1int(ptr)); - _stp_print_flush(); - } - + _stp_map_print (funct_locations, "locations"); _stp_map_del(funct_locations); } void cleanup_module(void) { - if (!exited) - probe_exit(); - _stp_transport_close(); } |