-
Notifications
You must be signed in to change notification settings - Fork 0
/
drill.stp
259 lines (223 loc) · 6.04 KB
/
drill.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/stap
global buffer_sizes
global packet_sizes
global tid_name
global tcp_nagle_setting
global tcp_delack_timer_cnt
global tcp_keepalive_timer_cnt
global tcp_write_timer_cnt
global sys_writev_cnt
global sys_poll_cnt
global sys_select_cnt
global sys_sched_yield_cnt
global thread_thislock # short
global thread_blocktime #
global FUTEX_WAIT = 0, FUTEX_WAKE = 1
global lock_waits # long-lived stats on (tid,lock) blockage elapsed time
probe syscall.futex {
if (op != FUTEX_WAIT)
next /* we don't care about originators of WAKE events */
tid = tid()
tid_name[tid] = execname()
thread_thislock[tid] = $uaddr
thread_blocktime[tid] = gettimeofday_us()
}
probe syscall.futex.return {
tid = tid()
ts = thread_blocktime[tid]
if (ts) {
elapsed = gettimeofday_us() - ts
lock_waits[tid, thread_thislock[tid]] <<< elapsed
delete thread_blocktime[tid]
delete thread_thislock[tid]
}
}
probe syscall.poll
{
tid = tid()
if (sys_poll_cnt[tid])
sys_poll_cnt[tid] += 1
else
sys_poll_cnt[tid] = 1
}
probe syscall.sched_yield
{
tid = tid()
if (sys_sched_yield_cnt[tid])
sys_sched_yield_cnt[tid] += 1
else
sys_sched_yield_cnt[tid] = 1
}
probe syscall.select
{
tid = tid()
if (sys_select_cnt[tid])
sys_select_cnt[tid] += 1
else
sys_select_cnt[tid] = 1
}
probe syscall.writev
{
tid = tid()
if (sys_writev_cnt[tid])
sys_writev_cnt[tid] += 1
else
sys_writev_cnt[tid] = 1
}
probe tcp.delack_timer
{
dport = inet_sk_dport(sk)
sport = inet_sk_sport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
if (tcp_delack_timer_cnt[saddr, sport, daddr, dport])
tcp_delack_timer_cnt[saddr, sport, daddr, dport] += 1
else
tcp_delack_timer_cnt[saddr, sport, daddr, dport] = 1
}
probe tcp.keepalive_timer
{
dport = inet_sk_dport(sk)
sport = inet_sk_sport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
if (tcp_keepalive_timer_cnt[saddr, sport, daddr, dport])
tcp_keepalive_timer_cnt[saddr, sport, daddr, dport] += 1
else
tcp_keepalive_timer_cnt[saddr, sport, daddr, dport] = 1
}
probe tcp.write_timer
{
dport = inet_sk_dport(sk)
sport = inet_sk_sport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
if (tcp_write_timer_cnt[saddr, sport, daddr, dport])
tcp_write_timer_cnt[saddr, sport, daddr, dport] += 1
else
tcp_write_timer_cnt[saddr, sport, daddr, dport] = 1
}
probe tcp_sendmsg = kernel.function("tcp_sendmsg")
{
sk = %( kernel_v < "2.6.23" %? $sk %: $sock->sk %)
size = $size
}
probe tcp_sendmsg
{
dport = inet_sk_dport(sk)
sport = inet_sk_sport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
buffer_sizes[tid(), saddr, sport, daddr, dport] <<< size
tcp_nagle_setting[saddr, sport, daddr, dport] = tcp_nagle(sk)
tid_name[tid()] = execname()
}
probe tcp_transmit_skb = kernel.function("tcp_transmit_skb")
{
sk = $sk
dport = inet_sk_dport(sk)
sport = inet_sk_sport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
size = $skb->len
}
/*
* TCP passing packet to IP
*/
probe tcp_transmit_skb
{
packet_sizes[tid(), saddr, sport, daddr, dport] <<< size
}
/*
* Routine used when closing any of the INET protocols
*/
probe inet_release = kernel.function("inet_release")
{
sk = $sock->sk
dport = inet_sk_dport(sk)
sport = inet_sk_sport(sk)
saddr = inet_sk_saddr(sk)
daddr = inet_sk_daddr(sk)
}
probe inet_release
{
tid = tid()
printf("tid=%d, saddr=%s, sport=%d, daddr=%s, dport=%d\n",
tid, inet_sk_ntop(saddr), sport, inet_sk_ntop(daddr), dport)
delete packet_sizes[tid, saddr, sport, daddr, dport]
delete buffer_sizes[tid, saddr, sport, daddr, dport]
delete tcp_nagle_setting[saddr, sport, daddr, dport]
delete tcp_delack_timer_cnt[saddr, sport, daddr, dport]
delete tcp_delack_timer_cnt[saddr, sport, daddr, dport]
delete tcp_write_timer_cnt[saddr, sport, daddr, dport]
}
function dump_stats()
{
print("thread: tid name nrwritev nrpoll nrselect nrsched_yield\n")
foreach ([tid+] in tid_name)
printf("thread: %d %s %d %d %d %d\n",
tid,
tid_name[tid],
sys_writev_cnt[tid],
sys_poll_cnt[tid],
sys_select_cnt[tid],
sys_sched_yield_cnt[tid])
print("lock: tid futex nrcontentions avg min max\n")
foreach ([tid+, lock] in lock_waits)
printf("lock: %u %p %u %u %u %u\n",
tid,
lock,
@count(lock_waits[tid, lock]),
@avg(lock_waits[tid, lock]),
@min(lock_waits[tid, lock]),
@max(lock_waits[tid, lock]))
print("connection: tid saddr sport daddr dport nrbf avgbfsz minbfsz maxbfsz nrpkts avgpktsz minpktsz maxpktsz nagle da ka wr\n")
foreach ([tid+, saddr, sport, daddr, dport] in buffer_sizes) {
if (daddr != 0x100007f)
continue
printf("connection: %u %s %u %s %u %u %u %u %u",
tid,
inet_sk_ntop(saddr),
sport,
inet_sk_ntop(daddr),
dport,
@count(buffer_sizes[tid, saddr, sport, daddr, dport]),
@avg(buffer_sizes[tid, saddr, sport, daddr, dport]),
@min(buffer_sizes[tid, saddr, sport, daddr, dport]),
@max(buffer_sizes[tid, saddr, sport, daddr, dport]))
if ([tid, saddr, sport, daddr, dport] in packet_sizes)
printf(" %u %u %u %u",
@count(packet_sizes[tid, saddr, sport, daddr, dport]),
@avg(packet_sizes[tid, saddr, sport, daddr, dport]),
@min(packet_sizes[tid, saddr, sport, daddr, dport]),
@max(packet_sizes[tid, saddr, sport, daddr, dport]))
else
print(" 0 0 0 0")
if ([saddr, sport, daddr, dport] in tcp_nagle_setting)
printf(" %s", tcp_nagle_str(tcp_nagle_setting[saddr, sport, daddr, dport]))
else
print(" -")
if ([saddr, sport, daddr, dport] in tcp_delack_timer_cnt)
printf(" %u", tcp_delack_timer_cnt[saddr, sport, daddr, dport])
else
print(" 0")
if ([saddr, sport, daddr, dport] in tcp_keepalive_timer_cnt)
printf(" %u", tcp_keepalive_timer_cnt[saddr, sport, daddr, dport])
else
print(" 0")
if ([saddr, sport, daddr, dport] in tcp_write_timer_cnt)
printf(" %u", tcp_write_timer_cnt[saddr, sport, daddr, dport])
else
print(" 0")
print("\n")
}
print("end:\n")
}
probe timer.ms(5000)
{
dump_stats()
}
probe end
{
dump_stats()
}