Add 6 tools tracking dbus.
[platform/upstream/bcc.git] / tools / dbus-message-size.c
1 #include <uapi/linux/ptrace.h>
2 #include <linux/sched.h>
3
4 #define COUNTS COUNTS_T
5
6 struct data_t {
7         int pid;
8         char comm[TASK_COMM_LEN];
9 };
10
11 struct bytes_t {
12         u32 bytes;
13 };
14
15 BPF_HASH(size_sent, struct data_t, struct bytes_t)
16
17 BPF_HISTOGRAM(sizes);
18
19 int do_write_exit(struct pt_regs *ctx) {
20         struct data_t data = {};
21         data.pid = bpf_get_current_pid_tgid();
22         bpf_get_current_comm(&data.comm, sizeof(data.comm));
23         struct bytes_t *bytes;
24         bytes = size_sent.lookup(&data);
25         if (bytes != 0 & bytes->bytes > 0) {
26                 sizes.increment(bpf_log2l(bytes->bytes));
27         }
28         size_sent.delete(&data);
29         return 0;
30 }
31
32 int do_return(struct pt_regs *ctx){
33         struct bytes_t size = {};
34         size.bytes = PT_REGS_RC(ctx);
35         struct bytes_t zero = {0}, *val;
36         if (size.bytes > 0) {
37                 struct data_t data = {};
38                 bpf_get_current_comm(&data.comm, sizeof(data.comm));
39                 data.pid = bpf_get_current_pid_tgid();
40                 val = size_sent.lookup_or_init(&data, &zero);
41                 size.bytes += val->bytes;
42                 size_sent.update(&data, &size);
43         }
44         return 0;
45 }