From 8e6109bfec75918c39e56ebdbd5c0ad6ac0bde17 Mon Sep 17 00:00:00 2001 From: Sasha Goldshtein Date: Fri, 28 Oct 2016 23:45:08 +0300 Subject: [PATCH] funccount: Bail early if there are no matching functions (#792) funccount now bails early with an error if there are no functions matching the specified pattern (the same applies to tracepoints and USDT probes). For example: ``` No functions matched by pattern ^sched:sched_fork$ ``` Fixes #789. --- tools/funccount.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/funccount.py b/tools/funccount.py index 71aa0dd..66aa011 100755 --- a/tools/funccount.py +++ b/tools/funccount.py @@ -107,10 +107,6 @@ class Probe(object): elif self.type == "u": pass # Nothing to do -- attach already happened in `load` - if self.matched == 0: - raise Exception("No functions matched by pattern %s" % - self.pattern) - def _add_function(self, template, probe_name): new_func = "trace_count_%d" % self.matched text = template.replace("PROBE_FUNCTION", new_func) @@ -199,6 +195,10 @@ BPF_TABLE("array", int, u64, counts, NUMLOCATIONS); if debug: print(bpf_text) + if self.matched == 0: + raise Exception("No functions matched by pattern %s" % + self.pattern) + self.bpf = BPF(text=bpf_text, usdt_contexts=[self.usdt] if self.usdt else []) self.clear() # Initialize all array items to zero -- 2.7.4