summaryrefslogtreecommitdiffstats
path: root/runtime/probes/scf/scf.c
blob: a8798f511c3bea3eccab7df01ed46e6833e5bb9f (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
#define STP_NETLINK_ONLY
#define STP_NUM_STRINGS 1
#include "runtime.h"

#define MAP_STRING_LENGTH 512
#define NEED_INT64_VALS
#define KEY1_TYPE STRING
#include "map-keys.c"

#include "map.c"
#include "sym.c"
#include "current.c"
#include "stack.c"
#include "probes.c"

MODULE_DESCRIPTION("SystemTap probe: scf");
MODULE_AUTHOR("Martin Hunt <hunt@redhat.com>");

MAP map1;

int inst_smp_call_function (struct kprobe *p, struct pt_regs *regs)
{
  String str = _stp_string_init (0);
  _stp_stack_sprint (str,regs);
  _stp_map_key_str(map1, _stp_string_ptr(str));
  _stp_map_add_int64 (map1, 1);
  return 0;
}

static struct kprobe stp_probes[] = {
  {
    .addr = (kprobe_opcode_t *)"smp_call_function",
    .pre_handler = inst_smp_call_function
  },
};

#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;
  }

  map1 = _stp_map_new_str (100, INT64);

  ret = _stp_register_kprobes (stp_probes, MAX_STP_ROUTINE);

  return ret;
}

static void probe_exit (void)
{
  _stp_unregister_kprobes (stp_probes, MAX_STP_ROUTINE);
  _stp_map_print (map1, "trace[%1s] = %d\n");
  _stp_map_del (map1);
}

void cleanup_module(void)
{
  _stp_transport_close();
}

MODULE_LICENSE("GPL");