perf: Fix various display bugs with parent filtering
authorFrederic Weisbecker <fweisbec@gmail.com>
Fri, 16 Jul 2010 02:02:14 +0000 (04:02 +0200)
committerFrederic Weisbecker <fweisbec@gmail.com>
Fri, 16 Jul 2010 02:56:09 +0000 (04:56 +0200)
Hists that have been filtered, because they don't have callchains
matching the parent filter, won't be printed. As such,
hist_entry__snprintf() returns 0 for them, but we don't control
this value and we always print the buffer, which might be
untouched and then only made of random stack garbage.

Not only does it paint the screen with barf, it also prints
the callchains for these hists, even though they have been filtered,
since the hist has been filtered as well.

We need to check the return value of hist_entry__snprintf() and
ignore the hist if it is 0, which means it didn't get any callchain
matching the parent filter. This fixes the barf and the undesired
callchains.

Reported-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
tools/perf/util/hist.c

index 07f89b66b318e43748f666f495f87b75f6a34462..699cf81ea0828dd5a36c09c5a4a7a4670e353c3c 100644 (file)
@@ -631,9 +631,14 @@ int hist_entry__fprintf(struct hist_entry *self, struct hists *pair_hists,
                        u64 session_total)
 {
        char bf[512];
-       hist_entry__snprintf(self, bf, sizeof(bf), pair_hists,
-                            show_displacement, displacement,
-                            true, session_total);
+       int ret;
+
+       ret = hist_entry__snprintf(self, bf, sizeof(bf), pair_hists,
+                                  show_displacement, displacement,
+                                  true, session_total);
+       if (!ret)
+               return 0;
+
        return fprintf(fp, "%s\n", bf);
 }
 
@@ -762,6 +767,7 @@ size_t hists__fprintf(struct hists *self, struct hists *pair,
 print_entries:
        for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
                struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
+               int cnt;
 
                if (show_displacement) {
                        if (h->pair != NULL)
@@ -771,8 +777,13 @@ print_entries:
                                displacement = 0;
                        ++position;
                }
-               ret += hist_entry__fprintf(h, pair, show_displacement,
-                                          displacement, fp, self->stats.total_period);
+               cnt = hist_entry__fprintf(h, pair, show_displacement,
+                                         displacement, fp, self->stats.total_period);
+               /* Ignore those that didn't match the parent filter */
+               if (!cnt)
+                       continue;
+
+               ret += cnt;
 
                if (symbol_conf.use_callchain)
                        ret += hist_entry__fprintf_callchain(h, fp, self->stats.total_period);