summaryrefslogtreecommitdiffstats
path: root/runtime/probes/agg/stat1.c
blob: 1d3cb3b0e761625640644f0e632d1b32654693b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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");