00001 #define HASH_TABLE_BITS 8
00002 #define HASH_TABLE_SIZE (1<<HASH_TABLE_BITS)
00003 #define BUCKETS 16
00004
00005 #include "runtime.h"
00006 #include "io.c"
00007 #include "map.c"
00008 #include "probes.c"
00009
00010 MODULE_DESCRIPTION("SystemTap probe: test4");
00011 MODULE_AUTHOR("Martin Hunt <hunt@redhat.com>");
00012
00013 MAP opens, reads, writes;
00014
00015 asmlinkage long inst_sys_open (const char __user * filename, int flags, int mode)
00016 {
00017 _stp_map_key_str (opens, current->comm);
00018 _stp_map_add_int64 (opens, 1);
00019 jprobe_return();
00020 return 0;
00021 }
00022
00023 asmlinkage ssize_t inst_sys_read (unsigned int fd, char __user * buf, size_t count)
00024 {
00025 _stp_map_key_str (reads, current->comm);
00026 _stp_map_stat_add (reads, count);
00027 jprobe_return();
00028 return 0;
00029 }
00030
00031 asmlinkage ssize_t inst_sys_write (unsigned int fd, const char __user * buf, size_t count)
00032 {
00033 _stp_map_key_str (writes, current->comm);
00034 _stp_map_stat_add (writes, count);
00035 jprobe_return();
00036 return 0;
00037 }
00038
00039 static struct jprobe dtr_probes[] = {
00040 {
00041 .kp.addr = (kprobe_opcode_t *)"sys_open",
00042 .entry = (kprobe_opcode_t *) inst_sys_open
00043 },
00044 {
00045 .kp.addr = (kprobe_opcode_t *)"sys_read",
00046 .entry = (kprobe_opcode_t *) inst_sys_read
00047 },
00048 {
00049 .kp.addr = (kprobe_opcode_t *)"sys_write",
00050 .entry = (kprobe_opcode_t *) inst_sys_write
00051 },
00052 };
00053
00054 #define MAX_DTR_ROUTINE (sizeof(dtr_probes)/sizeof(struct jprobe))
00055
00056 static int init_dtr(void)
00057 {
00058 int ret;
00059
00060 opens = _stp_map_new (1000, INT64);
00061 reads = _stp_map_new (1000, STAT);
00062 writes = _stp_map_new (1000, STAT);
00063
00064 ret = _stp_register_jprobes (dtr_probes, MAX_DTR_ROUTINE);
00065
00066 dlog("instrumentation is enabled...\n");
00067 return ret;
00068
00069 }
00070
00071 static void cleanup_dtr(void)
00072 {
00073 struct map_node_stat *st;
00074 struct map_node_int64 *ptr;
00075
00076 _stp_unregister_jprobes (dtr_probes, MAX_DTR_ROUTINE);
00077
00078 for (ptr = (struct map_node_int64 *)_stp_map_start(opens); ptr;
00079 ptr = (struct map_node_int64 *)_stp_map_iter (opens,(struct map_node *)ptr))
00080 dlog ("opens[%s] = %lld\n", key1str(ptr), ptr->val);
00081 dlog ("\n");
00082
00083 for (st = (struct map_node_stat *)_stp_map_start(reads); st;
00084 st = (struct map_node_stat *)_stp_map_iter (reads,(struct map_node *)st))
00085 dlog ("reads[%s] = [count=%lld sum=%lld min=%lld max=%lld]\n", key1str(st), st->stats.count, st->stats.sum,
00086 st->stats.min, st->stats.max);
00087 dlog ("\n");
00088
00089 for (st = (struct map_node_stat *)_stp_map_start(writes); st;
00090 st = (struct map_node_stat *)_stp_map_iter (writes,(struct map_node *)st))
00091 dlog ("writes[%s] = [count=%lld sum=%lld min=%lld max=%lld]\n", key1str(st), st->stats.count, st->stats.sum,
00092 st->stats.min, st->stats.max);
00093 dlog ("\n");
00094
00095 _stp_map_del (opens);
00096 _stp_map_del (reads);
00097 _stp_map_del (writes);
00098
00099 dlog("EXIT\n");
00100 }
00101
00102 module_init(init_dtr);
00103 module_exit(cleanup_dtr);
00104 MODULE_LICENSE("GPL");
00105