ustat: Graceful error handling
authorSasha Goldshtein <goldshtn@gmail.com>
Thu, 27 Oct 2016 22:58:14 +0000 (15:58 -0700)
committerSasha Goldshtein <goldshtn@gmail.com>
Mon, 19 Dec 2016 09:46:05 +0000 (09:46 +0000)
If the process in question doesn't have the USDT probes we
expect, handle the failure gracefully. After all, it could
be a binary compiled without USDT support, the pid could be
recycled to some other application, or -- the process name
could match, but by accident, and really belong to some
other runtime.

tools/ustat.py

index 55e8493..cc410df 100755 (executable)
@@ -64,7 +64,15 @@ class Probe(object):
         for pid in self.targets:
             usdt = USDT(pid=pid)
             for event in self.events:
-                usdt.enable_probe(event, "%s_%s" % (self.language, event))
+                try:
+                    usdt.enable_probe(event, "%s_%s" % (self.language, event))
+                except Exception:
+                    # This process might not have a recent version of the USDT
+                    # probes enabled, or might have been compiled without USDT
+                    # probes at all. The process could even have been shut down
+                    # and the pid been recycled. We have to gracefully handle
+                    # the possibility that we can't attach probes to it at all.
+                    pass
             self.usdts.append(usdt)
 
     def _generate_tables(self):
@@ -175,7 +183,7 @@ class Tool(object):
                 }
 
         if self.args.language:
-            self.probes = [probes_by_lang[args.language]]
+            self.probes = [probes_by_lang[self.args.language]]
         else:
             self.probes = probes_by_lang.values()