diff options
Diffstat (limited to 'runtime/probes/agg')
-rw-r--r-- | runtime/probes/agg/README | 3 | ||||
-rwxr-xr-x | runtime/probes/agg/build | 2 | ||||
-rw-r--r-- | runtime/probes/agg/count1.c | 127 | ||||
-rw-r--r-- | runtime/probes/agg/count2.c | 107 | ||||
-rw-r--r-- | runtime/probes/agg/stat1.c | 97 | ||||
-rwxr-xr-x | runtime/probes/agg/stp | 45 | ||||
-rw-r--r-- | runtime/probes/agg/targets | 3 |
7 files changed, 384 insertions, 0 deletions
diff --git a/runtime/probes/agg/README b/runtime/probes/agg/README new file mode 100644 index 00000000..b48db1b8 --- /dev/null +++ b/runtime/probes/agg/README @@ -0,0 +1,3 @@ +/** @dir agg +Test probes to use the Counter and Stat aggregations. +*/ diff --git a/runtime/probes/agg/build b/runtime/probes/agg/build new file mode 100755 index 00000000..f3e83244 --- /dev/null +++ b/runtime/probes/agg/build @@ -0,0 +1,2 @@ +#!/bin/bash +../build_probe $* diff --git a/runtime/probes/agg/count1.c b/runtime/probes/agg/count1.c new file mode 100644 index 00000000..870dc32e --- /dev/null +++ b/runtime/probes/agg/count1.c @@ -0,0 +1,127 @@ +#define STP_NETLINK_ONLY +#define STP_NUM_STRINGS 1 + +#include "runtime.h" + +#include "counter.c" +#include "probes.c" + +MODULE_DESCRIPTION("SystemTap probe: count1"); +MODULE_AUTHOR("Martin Hunt <hunt@redhat.com>"); + +Counter opens; +Counter reads; +Counter writes; +Counter sched; +Counter idle; + +static int inst_sys_open (struct kprobe *p, struct pt_regs *regs) +{ + _stp_counter_add (opens, 1); + return 0; +} + +static int inst_sys_read (struct kprobe *p, struct pt_regs *regs) +{ + _stp_counter_add (reads, 1); + return 0; +} + +static int inst_sys_write (struct kprobe *p, struct pt_regs *regs) +{ + _stp_counter_add (writes, 1); + return 0; +} + +static int inst_schedule(struct kprobe *p, struct pt_regs *regs) +{ + _stp_counter_add (sched, 1); + return 0; +} + +static int inst_idle_cpu(struct kprobe *p, struct pt_regs *regs) +{ + _stp_counter_add (idle, 1); + return 0; +} + +static struct kprobe stp_probes[] = { + { + .addr = "sys_open", + .pre_handler = inst_sys_open + }, + { + .addr = "sys_read", + .pre_handler = inst_sys_read + }, + { + .addr = "sys_write", + .pre_handler = inst_sys_write + }, + { + .addr = "schedule", + .pre_handler = inst_schedule + }, + { + .addr = "idle_cpu", + .pre_handler = inst_idle_cpu + }, +}; + +#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; + } + + opens = _stp_counter_init(); + reads = _stp_counter_init(); + writes = _stp_counter_init(); + sched = _stp_counter_init(); + idle = _stp_counter_init(); + + ret = _stp_register_kprobes (stp_probes, MAX_STP_ROUTINE); + + return ret; +} + +static void probe_exit (void) +{ + int i; + + _stp_unregister_kprobes (stp_probes, MAX_STP_ROUTINE); + + for_each_cpu(i) + _stp_printf ("sched calls for cpu %d = %lld\n", i, _stp_counter_get_cpu(sched, i, 0)); + + _stp_print ("\n\n"); + + _stp_printf ("open calls: %lld\n", _stp_counter_get(opens, 0)); + _stp_printf ("read calls: %lld\n", _stp_counter_get(reads, 0)); + _stp_printf ("write calls: %lld\n", _stp_counter_get(writes, 0)); + _stp_printf ("sched calls: %lld\n", _stp_counter_get(sched, 0)); + _stp_printf ("idle calls: %lld\n", _stp_counter_get(idle, 0)); + _stp_print_flush(); +} + +void cleanup_module(void) +{ + _stp_transport_close(); +} + +MODULE_LICENSE("GPL"); + diff --git a/runtime/probes/agg/count2.c b/runtime/probes/agg/count2.c new file mode 100644 index 00000000..ab13f5af --- /dev/null +++ b/runtime/probes/agg/count2.c @@ -0,0 +1,107 @@ +#define STP_NETLINK_ONLY +#define STP_NUM_STRINGS 1 +#include "runtime.h" + +#include "counter.c" +#include "probes.c" + +MODULE_DESCRIPTION("SystemTap probe: count1"); +MODULE_AUTHOR("Martin Hunt <hunt@redhat.com>"); + +Counter opens; +Counter reads; +Counter writes; +Counter read_bytes; +Counter write_bytes; + +asmlinkage long inst_sys_open (const char __user * filename, int flags, int mode) +{ + _stp_counter_add (opens, 1); + jprobe_return(); + return 0; +} + +asmlinkage ssize_t inst_sys_read (unsigned int fd, char __user * buf, size_t count) +{ + _stp_counter_add (reads, 1); + _stp_counter_add (read_bytes, count); + jprobe_return(); + return 0; +} + +asmlinkage ssize_t inst_sys_write (unsigned int fd, const char __user * buf, size_t count) +{ + _stp_counter_add (writes, 1); + _stp_counter_add (write_bytes, count); + jprobe_return(); + return 0; +} + +static struct jprobe stp_probes[] = { + { + .kp.addr = (kprobe_opcode_t *)"sys_open", + .entry = (kprobe_opcode_t *) inst_sys_open + }, + { + .kp.addr = (kprobe_opcode_t *)"sys_read", + .entry = (kprobe_opcode_t *) inst_sys_read + }, + { + .kp.addr = (kprobe_opcode_t *)"sys_write", + .entry = (kprobe_opcode_t *) inst_sys_write + }, +}; + +#define MAX_STP_ROUTINE (sizeof(stp_probes)/sizeof(struct jprobe)) + +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; + } + + opens = _stp_counter_init(); + reads = _stp_counter_init(); + writes = _stp_counter_init(); + read_bytes = _stp_counter_init(); + write_bytes = _stp_counter_init(); + + ret = _stp_register_jprobes (stp_probes, MAX_STP_ROUTINE); + + return ret; +} + +static void probe_exit (void) +{ + int i; + + _stp_unregister_jprobes (stp_probes, MAX_STP_ROUTINE); + + _stp_printf ("open calls: %lld\n", _stp_counter_get(opens, 0)); + _stp_printf ("read calls: %lld\n", _stp_counter_get(reads, 0)); + _stp_printf ("read bytes: %lld\n", _stp_counter_get(read_bytes, 0)); + _stp_printf ("write calls: %lld\n", _stp_counter_get(writes, 0)); + _stp_printf ("write bytes: %lld\n", _stp_counter_get(write_bytes, 0)); + + _stp_print_flush(); +} + +void cleanup_module(void) +{ + _stp_transport_close(); +} + +MODULE_LICENSE("GPL"); + diff --git a/runtime/probes/agg/stat1.c b/runtime/probes/agg/stat1.c new file mode 100644 index 00000000..1d3cb3b0 --- /dev/null +++ b/runtime/probes/agg/stat1.c @@ -0,0 +1,97 @@ +#define STP_NETLINK_ONLY +#define STP_NUM_STRINGS 1 +#include "runtime.h" +#include "stat.c" +#include "counter.c" +#include "probes.c" + +MODULE_DESCRIPTION("SystemTap probe: count1"); +MODULE_AUTHOR("Martin Hunt <hunt@redhat.com>"); + + +Counter opens; +Stat reads; +Stat writes; + +asmlinkage long inst_sys_open (const char __user * filename, int flags, int mode) +{ + _stp_counter_add (opens, 1); + jprobe_return(); + return 0; +} + +asmlinkage ssize_t inst_sys_read (unsigned int fd, char __user * buf, size_t count) +{ + _stp_stat_add (reads, count); + jprobe_return(); + return 0; +} + +asmlinkage ssize_t inst_sys_write (unsigned int fd, const char __user * buf, size_t count) +{ + _stp_stat_add (writes, count); + jprobe_return(); + return 0; +} + +static struct jprobe stp_probes[] = { + { + .kp.addr = (kprobe_opcode_t *)"sys_open", + .entry = (kprobe_opcode_t *) inst_sys_open + }, + { + .kp.addr = (kprobe_opcode_t *)"sys_read", + .entry = (kprobe_opcode_t *) inst_sys_read + }, + { + .kp.addr = (kprobe_opcode_t *)"sys_write", + .entry = (kprobe_opcode_t *) inst_sys_write + }, +}; + +#define MAX_STP_ROUTINE (sizeof(stp_probes)/sizeof(struct jprobe)) + +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; + } + + opens = _stp_counter_init(); + reads = _stp_stat_init(HIST_LOG,24); + writes = _stp_stat_init(HIST_LINEAR,0,1000,50); + + ret = _stp_register_jprobes (stp_probes, MAX_STP_ROUTINE); + return ret; +} + +static void probe_exit (void) +{ + _stp_unregister_jprobes (stp_probes, MAX_STP_ROUTINE); + + _stp_printf ("OPENS: %lld\n", _stp_counter_get(opens, 0)); + _stp_stat_print (reads, "READS: count:%C sum:%S avg:%A min:%m max:%M\n%H", 0); + _stp_stat_print (writes, "WRITES: count:%C sum:%S avg:%A min:%m max:%M\n%H", 0); + + _stp_print_flush(); +} + +void cleanup_module(void) +{ + _stp_transport_close(); +} + +MODULE_LICENSE("GPL"); + diff --git a/runtime/probes/agg/stp b/runtime/probes/agg/stp new file mode 100755 index 00000000..185a5905 --- /dev/null +++ b/runtime/probes/agg/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 diff --git a/runtime/probes/agg/targets b/runtime/probes/agg/targets new file mode 100644 index 00000000..614a00d2 --- /dev/null +++ b/runtime/probes/agg/targets @@ -0,0 +1,3 @@ +count1 +count2 +stat1 |