funccount: Bail early if there are no matching functions (#792)
authorSasha Goldshtein <goldshtn@gmail.com>
Fri, 28 Oct 2016 20:45:08 +0000 (23:45 +0300)
committer4ast <alexei.starovoitov@gmail.com>
Fri, 28 Oct 2016 20:45:08 +0000 (13:45 -0700)
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

index 71aa0dd..66aa011 100755 (executable)
@@ -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