diff options
author | hunt <hunt> | 2005-06-18 07:06:38 +0000 |
---|---|---|
committer | hunt <hunt> | 2005-06-18 07:06:38 +0000 |
commit | 22ccaa9985211ad13e8486bf2845114f409df55d (patch) | |
tree | dc4c286990a692ef0b5991b81405bb7b10292392 /runtime/probes/agg/count1.c | |
parent | b55bc428b7e03ce7bcf6ec1eb502f5f443fbd0b8 (diff) | |
download | systemtap-steved-22ccaa9985211ad13e8486bf2845114f409df55d.tar.gz systemtap-steved-22ccaa9985211ad13e8486bf2845114f409df55d.tar.xz systemtap-steved-22ccaa9985211ad13e8486bf2845114f409df55d.zip |
2005-06-18 Martin Hunt <hunt@redhat.com>
* build: Modified to use build_probe.
* build_probe: New file. This does the work of building
a single probe or set of probes in a directory.
* Makefile.template: New file. Template used by
build_probe to create Makefiles.
* agg: New set of probes to test/demonstrate
Counter and Stat aggregations.
* all probes modified for latest changes and new build
process.
Diffstat (limited to 'runtime/probes/agg/count1.c')
-rw-r--r-- | runtime/probes/agg/count1.c | 127 |
1 files changed, 127 insertions, 0 deletions
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"); + |