diff options
author | hunt <hunt> | 2005-05-31 20:14:03 +0000 |
---|---|---|
committer | hunt <hunt> | 2005-05-31 20:14:03 +0000 |
commit | a7b49c5a613f185067ed07f7bfcbb02d14a5ed1f (patch) | |
tree | ba94a055804a57c4e1a6d3a629e1a88026933147 /runtime | |
parent | 9c5d496e200d5476b126bc5ff9806365a77a2c7e (diff) | |
download | systemtap-steved-a7b49c5a613f185067ed07f7bfcbb02d14a5ed1f.tar.gz systemtap-steved-a7b49c5a613f185067ed07f7bfcbb02d14a5ed1f.tar.xz systemtap-steved-a7b49c5a613f185067ed07f7bfcbb02d14a5ed1f.zip |
New probe.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/probes/scf/Makefile | 22 | ||||
-rw-r--r-- | runtime/probes/scf/README | 12 | ||||
-rw-r--r-- | runtime/probes/scf/scf.c | 79 | ||||
-rwxr-xr-x | runtime/probes/scf/stp | 45 |
4 files changed, 158 insertions, 0 deletions
diff --git a/runtime/probes/scf/Makefile b/runtime/probes/scf/Makefile new file mode 100644 index 00000000..0a456a00 --- /dev/null +++ b/runtime/probes/scf/Makefile @@ -0,0 +1,22 @@ +# Makefile + +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) -D KTA=$(KTA) + +obj-m := scf.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/scf/README b/runtime/probes/scf/README new file mode 100644 index 00000000..39fcfda8 --- /dev/null +++ b/runtime/probes/scf/README @@ -0,0 +1,12 @@ +/** @dir scf +This example probe instruments smp_call_function(). + +It demonstrates using stack backtraces as map keys to compute the most +common path to a function. + +kernel.function("smp_call_function") +{ + traces[stack()] += 1 +} + +*/ diff --git a/runtime/probes/scf/scf.c b/runtime/probes/scf/scf.c new file mode 100644 index 00000000..dfdb7b0a --- /dev/null +++ b/runtime/probes/scf/scf.c @@ -0,0 +1,79 @@ +#define STP_NETLINK_ONLY +#define STP_NUM_STRINGS 2 +#include "runtime.h" + +#define MAP_STRING_LENGTH 512 +#define KEY1_TYPE STRING +#include "map-keys.c" + +#define VALUE_TYPE INT64 +#include "map-values.c" + +#include "map.c" +#include "sym.c" +#include "current.c" +#include "stack.c" +#include "probes.c" + +MODULE_DESCRIPTION("SystemTap probe: scf"); +MODULE_AUTHOR("Martin Hunt <hunt@redhat.com>"); + +MAP map1; + +int inst_smp_call_function (struct kprobe *p, struct pt_regs *regs) +{ + String str = _stp_string_init (0); + _stp_stack_sprint (str,regs); + _stp_map_key_str(map1, _stp_string_ptr(str)); + _stp_map_add_int64 (map1, 1); + return 0; +} + +static struct kprobe stp_probes[] = { + { + .addr = (kprobe_opcode_t *)"smp_call_function", + .pre_handler = inst_smp_call_function + }, +}; + +#define MAX_STP_ROUTINE (sizeof(stp_probes)/sizeof(struct kprobe)) + +static int pid; +module_param(pid, int, 0); +MODULE_PARM_DESC(pid, "daemon pid"); + +int init_module(void) +{ + int ret; + + if (!pid) { + printk("init: Can't start without daemon pid\n"); + return -1; + } + + if (_stp_transport_open(n_subbufs, subbuf_size, pid) < 0) { + printk("init: Couldn't open transport\n"); + return -1; + } + + map1 = _stp_map_new_str (100, INT64); + + ret = _stp_register_kprobes (stp_probes, MAX_STP_ROUTINE); + + return ret; +} + +static void probe_exit (void) +{ + _stp_unregister_kprobes (stp_probes, MAX_STP_ROUTINE); + _stp_map_print (map1, "trace[%1s] = %d\n"); + _stp_map_del (map1); +} + +void cleanup_module(void) +{ + _stp_transport_close(); +} + +MODULE_LICENSE("GPL"); + diff --git a/runtime/probes/scf/stp b/runtime/probes/scf/stp new file mode 100755 index 00000000..185a5905 --- /dev/null +++ b/runtime/probes/scf/stp @@ -0,0 +1,45 @@ +#!/bin/bash +if [ -n "$1" ] +then + modulename=$1 +else + echo "Usage: stp modulename" + exit +fi + +RELAYFS=`lsmod | grep relayfs |awk '{print $1}'` +if [ "$RELAYFS" != "relayfs" ] +then + /sbin/insmod ../../relayfs/relayfs.ko +fi + +if [ ! -d "/mnt/relay" ] +then + mkdir /mnt/relay +fi + +MOUNT=`mount | grep relayfs |awk '{print $1}'` +if [ "$MOUNT" != "relayfs" ] +then + mount -t relayfs relayfs /mnt/relay +fi + +STP_CONTROL=`lsmod | grep stp_control |awk '{print $1}'` +if [ "$STP_CONTROL" != "stp_control" ] +then + /sbin/insmod ../../transport/stp-control.ko +fi + +#/sbin/insmod $modulename + +# print to screen only, 4 8K buffers +#../../stpd/stpd -p -b 8192 -n 4 + +# print to screen and log to files, 4 8K buffers +../../stpd/stpd -b 8192 -n 4 $modulename + +# no screen or log +#../../stpd/stpd -q -b 8192 -n 4 + +# stpd will remove module when it exits +#/sbin/rmmod $modulename |