-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathnettop.stp
72 lines (63 loc) · 1.8 KB
/
nettop.stp
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
#!/usr/bin/env stap
##############usage#################
# sudo stap nettop.stp
#
global ifxmit, ifrecv
global ifmerged
probe netdev.transmit
{
ifxmit[pid(), dev_name, execname(), uid()] <<< length
}
probe netdev.receive
{
ifrecv[pid(), dev_name, execname(), uid()] <<< length
}
function print_activity()
{
ansi_clear_screen()
printf("%5s %5s %-7s %7s %7s %7s %7s %-15s\n",
"PID", "UID", "DEV", "XMIT_PK", "RECV_PK",
"XMIT_B", "RECV_B", "COMMAND")
foreach ([pid, dev, exec, uid] in ifrecv) {
ifmerged[pid, dev, exec, uid] += @count(ifrecv[pid,dev,exec,uid]);
}
foreach ([pid, dev, exec, uid] in ifxmit) {
ifmerged[pid, dev, exec, uid] += @count(ifxmit[pid,dev,exec,uid]);
}
foreach ([pid, dev, exec, uid] in ifmerged-) {
n_xmit = @count(ifxmit[pid, dev, exec, uid])
n_recv = @count(ifrecv[pid, dev, exec, uid])
if(n_xmit) {
t_xmit = @sum(ifxmit[pid, dev, exec, uid]);
if(t_xmit > 1024){
t_xmit = t_xmit / 1024;
str_txmit = sprint(t_xmit) . "K";
} else {
str_txmit = sprint(t_recv);
}
} else {
str_txmit = "0";
}
if(n_recv) {
t_recv = @sum(ifrecv[pid, dev, exec, uid]);
if(t_recv > 1024){
t_recv = t_recv / 1024;
str_trecv = sprint(t_recv) . "K";
} else {
str_trecv = sprint(t_recv);
}
} else {
str_trecv = "0";
}
printf("%5d %5d %-7s %7d %7d %7s %7s %-15s\n",
pid, uid, dev, n_xmit, n_recv, str_txmit, str_trecv, exec)
}
print("\n")
delete ifxmit
delete ifrecv
delete ifmerged
}
probe timer.ms(5000), end, error
{
print_activity()
}