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