perf tools: Fix missing top level callchain
authorFrederic Weisbecker <fweisbec@gmail.com>
Thu, 22 Oct 2009 21:23:22 +0000 (23:23 +0200)
committerIngo Molnar <mingo@elte.hu>
Fri, 23 Oct 2009 05:55:16 +0000 (07:55 +0200)
While recursively printing the branches of each callchains, we
forget to display the root. It is never printed.

Say we have:

    symbol
    f1
    f2
     |
     -------- f3
     |        f4
     |
     ---------f5
              f6

Actually we never see that, instead it displays:

    symbol
    |
    --------- f3
    |         f4
    |
    --------- f5
              f6

However f1 is always the same than "symbol" and if we are
sorting by symbols first then "symbol", f1 and f2 will be well
aligned like in the above example, so displaying f1 looks
redundant here.

But if we are sorting by something else first (dso, comm,
etc...), displaying f1 doesn't look redundant but rather
necessary because the symbol is not well aligned anymore with
its callchain:

     comm     dso        symbol
     f1
     f2
     |
     --------- [...]

And we want the callchain to be obvious.
So we fix the bug by printing the root branch, but we also
filter its first entry if we are sorting by symbols first.

Reported-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1256246604-17156-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/builtin-report.c
tools/perf/util/sort.c
tools/perf/util/sort.h

index bee207ce589a266c990eb2b40f13e8d8de05d654..3d8c52220f1ff2ec774e9f64b347b38c46ef6262 100644 (file)
@@ -122,8 +122,8 @@ static void init_rem_hits(void)
 }
 
 static size_t
-callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
-                       u64 total_samples, int depth, int depth_mask)
+__callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
+                          u64 total_samples, int depth, int depth_mask)
 {
        struct rb_node *node, *next;
        struct callchain_node *child;
@@ -174,9 +174,9 @@ callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
                                                      new_total,
                                                      cumul);
                }
-               ret += callchain__fprintf_graph(fp, child, new_total,
-                                               depth + 1,
-                                               new_depth_mask | (1 << depth));
+               ret += __callchain__fprintf_graph(fp, child, new_total,
+                                                 depth + 1,
+                                                 new_depth_mask | (1 << depth));
                node = next;
        }
 
@@ -196,6 +196,33 @@ callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
        return ret;
 }
 
+static size_t
+callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
+                        u64 total_samples)
+{
+       struct callchain_list *chain;
+       int i = 0;
+       int ret = 0;
+
+       list_for_each_entry(chain, &self->val, list) {
+               if (chain->ip >= PERF_CONTEXT_MAX)
+                       continue;
+
+               if (!i++ && sort_by_sym_first)
+                       continue;
+
+               if (chain->sym)
+                       ret += fprintf(fp, "                %s\n", chain->sym->name);
+               else
+                       ret += fprintf(fp, "                %p\n",
+                                       (void *)(long)chain->ip);
+       }
+
+       ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1);
+
+       return ret;
+}
+
 static size_t
 callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
                        u64 total_samples)
@@ -244,8 +271,7 @@ hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
                        break;
                case CHAIN_GRAPH_ABS: /* Falldown */
                case CHAIN_GRAPH_REL:
-                       ret += callchain__fprintf_graph(fp, chain,
-                                                       total_samples, 1, 1);
+                       ret += callchain__fprintf_graph(fp, chain, total_samples);
                case CHAIN_NONE:
                default:
                        break;
index 40c9acd41cad3d59cdc32788707567b50ddab159..60ced707bd6b5a88993fb206e098fe1fcee9cd72 100644 (file)
@@ -5,8 +5,9 @@ char            default_parent_pattern[] = "^sys_|^do_page_fault";
 char           *parent_pattern = default_parent_pattern;
 char           default_sort_order[] = "comm,dso,symbol";
 char           *sort_order = default_sort_order;
-int sort__need_collapse = 0;
-int sort__has_parent = 0;
+int            sort__need_collapse = 0;
+int            sort__has_parent = 0;
+int            sort_by_sym_first;
 
 unsigned int dsos__col_width;
 unsigned int comms__col_width;
@@ -265,6 +266,10 @@ int sort_dimension__add(const char *tok)
                        sort__has_parent = 1;
                }
 
+               if (list_empty(&hist_entry__sort_list) &&
+                   !strcmp(sd->name, "symbol"))
+                       sort_by_sym_first = true;
+
                list_add_tail(&sd->entry->list, &hist_entry__sort_list);
                sd->taken = 1;
 
@@ -273,4 +278,3 @@ int sort_dimension__add(const char *tok)
 
        return -ESRCH;
 }
-
index 13806d782af6b1c823d2886c73ad7acee6305148..24c2b709f0d3921c420c966fe53aad11f94280e3 100644 (file)
@@ -39,6 +39,7 @@ extern struct sort_entry sort_parent;
 extern unsigned int dsos__col_width;
 extern unsigned int comms__col_width;
 extern unsigned int threads__col_width;
+extern int sort_by_sym_first;
 
 struct hist_entry {
        struct rb_node          rb_node;