| 1 |
#! stap |
| 2 |
global uids, pidnames, send_bytes, recv_bytes, pid_ports, pid_src_ips, pid_rtos |
| 3 |
global pid_state, pid_mss, pid_ssthresh, pid_cwnd, totalbytes |
| 4 |
|
| 5 |
probe begin { |
| 6 |
log("systemtap starting probe") |
| 7 |
} |
| 8 |
|
| 9 |
probe end { |
| 10 |
log("systemtap ending probe") |
| 11 |
if (totalbytes > 0) { |
| 12 |
printf("TCP totalbytes: %d\n",totalbytes) |
| 13 |
print_report() |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
function print_report() |
| 18 |
{ |
| 19 |
lines = 0; |
| 20 |
log ("UID\tPID\tSIZE\tNAME\t\t\tPORT\tSOURCE\t\tRTO\tRCVMSS\tSSTHRES\tCWND\tSTATE") |
| 21 |
for (lines = 0; lines <= 5; lines ++) { |
| 22 |
if (!lines) { |
| 23 |
foreach (_pid_ in pidnames) { |
| 24 |
printf("%d\t%d\t%d\t%s\t\t\t%d\t%s\t%d\t%d\t%d\t%d\t%d\n", |
| 25 |
uids[_pid_],_pid_,send_bytes[_pid_] + recv_bytes[_pid_], |
| 26 |
pidnames[_pid_],pid_ports[_pid_], |
| 27 |
pid_src_ips[_pid_],pid_rtos[_pid_], pid_mss[_pid_], |
| 28 |
pid_ssthresh[_pid_],pid_cwnd[_pid_],pid_state[_pid_]); |
| 29 |
lines++ |
| 30 |
} |
| 31 |
} else { |
| 32 |
print("\n") |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
probe tcp.sendmsg { |
| 38 |
pid_ports[pid()] = inet_get_local_port(sock) |
| 39 |
pid_src_ips[pid()] = inet_get_ip_source(sock) |
| 40 |
pid_rtos[pid()] = tcp_get_info_rto(sock) |
| 41 |
} |
| 42 |
|
| 43 |
probe tcp.recvmsg { |
| 44 |
pid_cwnd[pid()] = tcp_get_info_snd_cwnd(sock) |
| 45 |
pid_mss[pid()] = tcp_ts_get_info_rcv_mss(sock) |
| 46 |
pid_ssthresh[pid()] = tcp_ts_get_info_snd_ssthresh(sock) |
| 47 |
pid_state[pid()] = tcp_ts_get_info_state(sock) |
| 48 |
} |
| 49 |
|
| 50 |
probe tcp.sendmsg.return { |
| 51 |
if (size > 0) { |
| 52 |
send_bytes[pid()] += size |
| 53 |
totalbytes += size |
| 54 |
pidnames[pid()] = execname() |
| 55 |
uids[pid()] = uid() |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
probe tcp.recvmsg.return { |
| 60 |
if (size > 0) { |
| 61 |
recv_bytes[pid()] += size |
| 62 |
totalbytes += size |
| 63 |
pidnames[pid()] = execname() |
| 64 |
uids[pid()] = uid() |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
probe tcp.disconnect { |
| 69 |
delete pidnames[pid()] |
| 70 |
} |