forked from goldshtn/linux-tracing-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetsend.py
More file actions
executable file
·36 lines (28 loc) · 718 Bytes
/
netsend.py
File metadata and controls
executable file
·36 lines (28 loc) · 718 Bytes
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
#!/usr/bin/env python
#
# Example BPF program for aggregating outgoing network interface traffic
# using the net:net_dev_* kernel tracepoints and displaying a histogram.
#
# Copyright 2016 Sasha Goldshtein
from time import sleep
from bcc import BPF
text = """
#include <linux/netdevice.h>
struct key_t {
char devname[16]; // IFNAMSIZ
u64 slot;
};
BPF_HISTOGRAM(dist, struct key_t);
TRACEPOINT_PROBE(net, net_dev_start_xmit) {
struct key_t key = {0};
TP_DATA_LOC_READ_CONST(&key.devname, name, 16);
key.slot = bpf_log2l(args->len);
dist.increment(key);
return 0;
}
"""
bpf = BPF(text=text)
dist = bpf["dist"]
while True:
sleep(1)
dist.print_log2_hist("bytes", "device name")