| 1 |
#! /usr/bin/env stap |
| 2 |
|
| 3 |
global ifxmit, ifrecv |
| 4 |
global ifmerged |
| 5 |
|
| 6 |
probe netdev.transmit |
| 7 |
{ |
| 8 |
ifxmit[pid(), dev_name, execname(), uid()] <<< length |
| 9 |
ifmerged[pid(), dev_name, execname(), uid()] <<< 1 |
| 10 |
} |
| 11 |
|
| 12 |
probe netdev.receive |
| 13 |
{ |
| 14 |
ifrecv[pid(), dev_name, execname(), uid()] <<< length |
| 15 |
ifmerged[pid(), dev_name, execname(), uid()] <<< 1 |
| 16 |
} |
| 17 |
|
| 18 |
function print_activity() |
| 19 |
{ |
| 20 |
printf("%5s %5s %-12s %7s %7s %7s %7s %-15s\n", |
| 21 |
"PID", "UID", "DEV", "XMIT_PK", "RECV_PK", |
| 22 |
"XMIT_KB", "RECV_KB", "COMMAND") |
| 23 |
|
| 24 |
foreach ([pid, dev, exec, uid] in ifmerged-) { |
| 25 |
n_xmit = @count(ifxmit[pid, dev, exec, uid]) |
| 26 |
n_recv = @count(ifrecv[pid, dev, exec, uid]) |
| 27 |
printf("%5d %5d %-12s %7d %7d %7d %7d %-15s\n", |
| 28 |
pid, uid, dev, n_xmit, n_recv, |
| 29 |
@sum(ifxmit[pid, dev, exec, uid])/1024, |
| 30 |
@sum(ifrecv[pid, dev, exec, uid])/1024, |
| 31 |
exec) |
| 32 |
} |
| 33 |
|
| 34 |
print("\n") |
| 35 |
|
| 36 |
delete ifxmit |
| 37 |
delete ifrecv |
| 38 |
delete ifmerged |
| 39 |
} |
| 40 |
|
| 41 |
probe timer.ms(5000), end, error |
| 42 |
{ |
| 43 |
print_activity() |
| 44 |
} |