Skip to content

Commit 82f2b9a

Browse files
SaveTheRbtzyonghong-song
authored andcommitted
ustat: added basic race condition protection (iovisor#2103)
added basic race condition protection for ustat.py
1 parent dccc4f2 commit 82f2b9a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

tools/lib/ustat.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
from __future__ import print_function
2222
import argparse
23-
from bcc import BPF, USDT
23+
from bcc import BPF, USDT, USDTException
2424
import os
25+
import sys
2526
from subprocess import call
2627
from time import sleep, strftime
2728

@@ -62,7 +63,12 @@ def _find_targets(self):
6263
def _enable_probes(self):
6364
self.usdts = []
6465
for pid in self.targets:
65-
usdt = USDT(pid=pid)
66+
try:
67+
usdt = USDT(pid=pid)
68+
except USDTException:
69+
# avoid race condition on pid going away.
70+
print("failed to instrument %d" % pid, file=sys.stderr)
71+
continue
6672
for event in self.events:
6773
try:
6874
usdt.enable_probe(event, "%s_%s" % (self.language, event))
@@ -111,6 +117,9 @@ def get_counts(self, bpf):
111117
for event, category in self.events.items():
112118
counts = bpf["%s_%s_counts" % (self.language, event)]
113119
for pid, count in counts.items():
120+
if pid.value not in result:
121+
print("result was not found for %d" % pid.value, file=sys.stderr)
122+
continue
114123
result[pid.value][category] = count.value
115124
counts.clear()
116125
return result

0 commit comments

Comments
 (0)