Skip to content

Commit

Permalink
ustat: added basic race condition protection (iovisor#2103)
Browse files Browse the repository at this point in the history
added basic race condition protection for ustat.py
  • Loading branch information
SaveTheRbtz authored and yonghong-song committed Jan 3, 2019
1 parent dccc4f2 commit 82f2b9a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tools/lib/ustat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

from __future__ import print_function
import argparse
from bcc import BPF, USDT
from bcc import BPF, USDT, USDTException
import os
import sys
from subprocess import call
from time import sleep, strftime

Expand Down Expand Up @@ -62,7 +63,12 @@ def _find_targets(self):
def _enable_probes(self):
self.usdts = []
for pid in self.targets:
usdt = USDT(pid=pid)
try:
usdt = USDT(pid=pid)
except USDTException:
# avoid race condition on pid going away.
print("failed to instrument %d" % pid, file=sys.stderr)
continue
for event in self.events:
try:
usdt.enable_probe(event, "%s_%s" % (self.language, event))
Expand Down Expand Up @@ -111,6 +117,9 @@ def get_counts(self, bpf):
for event, category in self.events.items():
counts = bpf["%s_%s_counts" % (self.language, event)]
for pid, count in counts.items():
if pid.value not in result:
print("result was not found for %d" % pid.value, file=sys.stderr)
continue
result[pid.value][category] = count.value
counts.clear()
return result
Expand Down

0 comments on commit 82f2b9a

Please sign in to comment.