Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

dtr.c

00001 #define HASH_TABLE_BITS 8
00002 #define HASH_TABLE_SIZE (1<<HASH_TABLE_BITS)
00003 #define BUCKETS 16 /* largest histogram width */
00004 #include <linux/module.h>
00005 #include <linux/interrupt.h>
00006 #include <net/sock.h>
00007 
00008 #include "runtime.h"
00009 #include "io.c"
00010 #include "map.c"
00011 #include "probes.c"
00012 #include "stack.c"
00013 
00014 MODULE_DESCRIPTION("SystemTap probe: test4");
00015 MODULE_AUTHOR("Martin Hunt <hunt@redhat.com>");
00016 
00017 static char tbuffer[2][50000];
00018 static void stp_helper(void *);
00019 static DECLARE_WORK(stp_work, stp_helper, tbuffer);
00020 
00021 MAP opens, reads, writes, traces;
00022 static int bufcount = 0;
00023 
00024 static void stp_helper (void *data)
00025 {
00026   dlog ("HELPER\n");
00027 }
00028 
00029 asmlinkage long inst_sys_open (const char __user * filename, int flags, int mode)
00030 {
00031   _stp_map_key_str (opens, current->comm);
00032   _stp_map_add_int64 (opens, 1);
00033   jprobe_return();
00034   return 0;
00035 }
00036 
00037 asmlinkage ssize_t inst_sys_read (unsigned int fd, char __user * buf, size_t count)
00038 {
00039   _stp_map_key_str (reads, current->comm);
00040   _stp_map_stat_add (reads, count);
00041   jprobe_return();
00042   return 0;
00043 }
00044 
00045 asmlinkage ssize_t inst_sys_write (unsigned int fd, const char __user * buf, size_t count)
00046 {
00047   _stp_map_key_str (writes, current->comm);
00048   _stp_map_stat_add (writes, count);
00049   jprobe_return();
00050   return 0;
00051 }
00052 
00053 int inst_show_cpuinfo(struct seq_file *m, void *v)
00054 {
00055   _stp_stack_print (0,0);
00056   _stp_stack_print (1,0);
00057 
00058   _stp_scbuf_clear();
00059   _stp_list_add (traces, _stp_stack_sprint(0,0));
00060   if (bufcount++ == 0)
00061     schedule_work (&stp_work);
00062 
00063   jprobe_return();
00064   return 0;
00065 }
00066 
00067 
00068 static struct jprobe dtr_probes[] = {
00069   {
00070     .kp.addr = (kprobe_opcode_t *)"sys_open",
00071     .entry = (kprobe_opcode_t *) inst_sys_open
00072   },
00073   {
00074     .kp.addr = (kprobe_opcode_t *)"sys_read",
00075     .entry = (kprobe_opcode_t *) inst_sys_read
00076   },
00077   {
00078     .kp.addr = (kprobe_opcode_t *)"sys_write",
00079     .entry = (kprobe_opcode_t *) inst_sys_write
00080   },
00081   {
00082     .kp.addr = (kprobe_opcode_t *)"show_cpuinfo",
00083     .entry = (kprobe_opcode_t *) inst_show_cpuinfo,
00084   },
00085 };
00086 
00087 #define MAX_DTR_ROUTINE (sizeof(dtr_probes)/sizeof(struct jprobe))
00088 
00089 static int init_dtr(void)
00090 {
00091   int ret;
00092   
00093   opens = _stp_map_new (1000, INT64);
00094   reads = _stp_map_new (1000, STAT);
00095   writes = _stp_map_new (1000, STAT);
00096   traces = _stp_list_new (1000, STRING);
00097 
00098   ret = _stp_register_jprobes (dtr_probes, MAX_DTR_ROUTINE);
00099 
00100   dlog("instrumentation is enabled...\n");
00101   return ret;
00102 
00103 }
00104 
00105 static void cleanup_dtr(void)
00106 {
00107   struct map_node_stat *st;
00108   struct map_node_int64 *ptr;
00109   struct map_node_str *sptr;
00110 
00111   _stp_unregister_jprobes (dtr_probes, MAX_DTR_ROUTINE);
00112 
00113   foreach (traces, sptr)
00114     dlog ("trace: %s\n", sptr->str);
00115 
00116   foreach (opens, ptr)
00117     dlog ("opens[%s] = %lld\n", key1str(ptr), ptr->val); 
00118   dlog ("\n");
00119 
00120   foreach (reads, st)
00121     dlog ("reads[%s] = [count=%lld  sum=%lld   min=%lld   max=%lld]\n", key1str(st), 
00122           st->stats.count, st->stats.sum, st->stats.min, st->stats.max);
00123   dlog ("\n");
00124   
00125   foreach (writes, st)
00126     dlog ("writes[%s] = [count=%lld  sum=%lld   min=%lld   max=%lld]\n", key1str(st), 
00127           st->stats.count, st->stats.sum, st->stats.min, st->stats.max);
00128   dlog ("\n");
00129 
00130   _stp_map_del (opens);
00131   _stp_map_del (reads);
00132   _stp_map_del (writes);
00133 
00134   dlog("EXIT\n");
00135 }
00136 
00137 module_init(init_dtr);
00138 module_exit(cleanup_dtr);
00139 MODULE_LICENSE("GPL");
00140