Commit 82f2b9a1 authored by Alexey Ivanov's avatar Alexey Ivanov Committed by yonghong-song

ustat: added basic race condition protection (#2103)

added basic race condition protection for ustat.py
parent dccc4f28
......@@ -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
......@@ -62,7 +63,12 @@ class Probe(object):
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))
......@@ -111,6 +117,9 @@ int %s_%s(void *ctx) {
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment