-
Notifications
You must be signed in to change notification settings - Fork 0
/
lnlat.stp
187 lines (164 loc) · 4.13 KB
/
lnlat.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/stap
# GPLv2 (C) Red Hat Inc.
# Arnaldo Carvalho de Melo <[email protected]>
#
# Run it with
# stap -I tapset/ lnlat.stp
# on RHEL kernels where the above fails, try with:
# stap -I tapset/ -D RHEL_KERNEL=1 lnlat.stp
global stats_latency
global stats_bufsize
probe new_packet = kernel.function("__alloc_skb").return
{
skb = $return
}
probe tcp_in = kernel.function("tcp_v4_rcv")
{
skb = $skb
sport = skb_tcphdr_sport(skb)
dport = skb_tcphdr_dport(skb)
saddr = skb_iphdr_saddr(skb)
daddr = skb_iphdr_daddr(skb)
len = $skb->len
timestamp = skb_tstamp(skb)
}
probe tcp_out = kernel.function("tcp_transmit_skb")
{
sk = $sk
len = $skb->len
timestamp = skb_tstamp($skb)
sport = inet_sk_sport(sk)
dport = inet_sk_dport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
}
probe ip_in = kernel.function("ip_rcv")
{
skb = $skb
saddr = skb_iphdr_saddr(skb)
daddr = skb_iphdr_daddr(skb)
protocol = skb_iphdr_protocol(skb)
len = $skb->len
timestamp = skb_tstamp(skb)
}
probe ip_out = kernel.function("ip_queue_xmit")
{
sk = $skb->sk
len = $skb->len
protocol = sk_protocol(sk)
timestamp = skb_tstamp($skb)
sport = inet_sk_sport(sk)
dport = inet_sk_dport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
}
probe dev_out = kernel.function("dev_hard_start_xmit")
{
skb = $skb
sk = $skb->sk
len = $skb->len
timestamp = skb_tstamp(skb)
if (sk) {
protocol = sk_protocol(sk)
sport = inet_sk_sport(sk)
dport = inet_sk_dport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
}
}
probe dev_in = kernel.function("netif_rx"), kernel.function("netif_receive_skb")
{
skb = $skb
}
probe user_in = kernel.function("skb_copy_datagram_iovec"),
kernel.function("skb_copy_and_csum_datagram")
{
skb = $skb
sk = $skb->sk
len = len
timestamp = skb_tstamp(skb)
protocol = 0
if (sk) {
protocol = sk_protocol(sk)
dport = inet_sk_dport(sk)
sport = inet_sk_sport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
}
}
probe new_packet
{
if (skb)
skb_take_tstamp(skb)
}
probe dev_in
{
if (skb)
skb_take_tstamp(skb)
}
function add_sample(table_id, saddr, sport, daddr, dport, timestamp, len)
{
/* We're only interested in loopback
if (daddr != 0x100007f)
return 0 */
delay = gettimeofday_ns() - timestamp
if (delay < 0) {
printf("delay < 0! timestamp=%d\n", timestamp)
return 0
}
stats_latency[table_id, saddr, sport, daddr, dport] <<< delay
stats_bufsize[table_id, saddr, sport, daddr, dport] <<< len
}
probe dev_out
{
if (protocol == IPPROTO_TCP)
add_sample("dev_out", saddr, sport, daddr, dport, timestamp, len)
}
probe tcp_out
{
add_sample("tcp_out", saddr, sport, daddr, dport, timestamp, len)
}
probe ip_in
{
if (protocol == IPPROTO_TCP) {
sport = skb_iphdr_tcp_sport(skb)
dport = skb_iphdr_tcp_dport(skb)
add_sample("ip_in", daddr, dport, saddr, sport, timestamp, len)
}
}
probe ip_out
{
if (protocol == IPPROTO_TCP)
add_sample("ip_out", daddr, dport, saddr, sport, timestamp, len)
}
probe tcp_in
{
add_sample("tcp_in", daddr, dport, saddr, sport, timestamp, len)
}
probe user_in
{
if (protocol == IPPROTO_TCP)
add_sample("user_in", saddr, sport, daddr, dport, timestamp, len)
}
probe begin
{
print("press control+C to exit and display local network stack latency stats\n")
}
probe end
{
printf("%8s %15.15s %5s %15s %5s %23s %18s\n",
"", "", "", "", "", "latency(ns)", "buffer size")
printf("%8.8s %15.15s %5s %15.15s %5s %8s %7s %9s %5s %5s %5s\n",
"entry", "local address", "port", "remote address", "port",
"avg", "min", "max", "avg", "min", "max")
foreach ([table_id-, saddr, sport, daddr, dport] in stats_latency) {
printf("%-8.8s %15.15s %5d %15.15s %5d %8d %7d %9d %5d %5d %5d\n",
table_id, inet_sk_ntop(saddr), sport, inet_sk_ntop(daddr), dport,
@avg(stats_latency[table_id, saddr, sport, daddr, dport]),
@min(stats_latency[table_id, saddr, sport, daddr, dport]),
@max(stats_latency[table_id, saddr, sport, daddr, dport]),
@avg(stats_bufsize[table_id, saddr, sport, daddr, dport]),
@min(stats_bufsize[table_id, saddr, sport, daddr, dport]),
@max(stats_bufsize[table_id, saddr, sport, daddr, dport]))
}
}