5 from ctypes import c_ushort, c_int, c_ulonglong
9 print("Hit Ctrl-C to end.")
14 bpf_text="""#include <uapi/linux/ptrace.h>
15 #include <linux/sched.h>
22 BPF_HASH(counter, struct p_name);
25 int sending_message(struct pt_regs *ctx, void *ptri, void *message){
26 struct p_name process = {' ', 0};
28 u32 ret = PT_REGS_RC(ctx);
29 process.pid = bpf_get_current_pid_tgid();
30 bpf_get_current_comm(&(process.buf), sizeof(process.buf));
31 counter.increment(process);
36 bpf_text = bpf_text.replace('INTERVAL', '%d' % interval)
37 b = BPF(text=bpf_text)
39 b.attach_uprobe(name="dbus-1", sym="dbus_connection_send", fn_name="sending_message")
40 b.attach_uprobe(name="dbus-1", sym="dbus_connection_send_preallocated", fn_name="sending_message")
41 b.attach_uprobe(name="dbus-1", sym="dbus_connection_send_with_reply", fn_name="sending_message")
42 b.attach_uprobe(name="dbus-1", sym="dbus_connection_send_with_reply_and_block", fn_name="sending_message")
53 print("%10s %20s %20s" % ("PID", "NAME", "MESSAGES SENT"))
54 for k, v in stats.items():
55 print("%10d %20s %20d\n" % (k.pid, k.buf.encode('string-escape'), v.value ))