perf annotate: Separate objdump parsing from actual screen rendering
authorArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 5 Feb 2011 20:51:38 +0000 (18:51 -0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 6 Feb 2011 15:40:31 +0000 (13:40 -0200)
Because in 'perf top' we'll need to parse just once and then, as samples
come, render multiple times with evolving counter values.

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/annotate.c
tools/perf/util/annotate.h

index 072bc8d91aa1bf36b537fff58290e891c5186c24..10cdbad76058e169243c3a10b4d2c47f93023e7f 100644 (file)
@@ -421,21 +421,16 @@ static void symbol__annotate_hits(struct symbol *sym, int evidx)
        printf("%*s: %" PRIu64 "\n", BITS_PER_LONG / 2, "h->sum", h->sum);
 }
 
-int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
-                        bool print_lines, bool full_paths, int min_pcnt,
-                        int max_lines)
+void symbol__annotate_printf(struct symbol *sym, struct map *map,
+                            struct list_head *head, int evidx, bool full_paths,
+                            int min_pcnt, int max_lines)
 {
        struct dso *dso = map->dso;
        const char *filename = dso->long_name, *d_filename;
-       struct rb_root source_line = RB_ROOT;
-       struct objdump_line *pos, *n;
-       LIST_HEAD(head);
+       struct objdump_line *pos;
        int printed = 2;
        u64 len;
 
-       if (symbol__annotate(sym, map, &head, 0) < 0)
-               return -1;
-
        if (full_paths)
                d_filename = filename;
        else
@@ -443,28 +438,57 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
 
        len = sym->end - sym->start;
 
-       if (print_lines) {
-               symbol__get_source_line(sym, map, evidx, &source_line,
-                                       len, filename);
-               print_summary(&source_line, filename);
-       }
-
        printf(" Percent |      Source code & Disassembly of %s\n", d_filename);
        printf("------------------------------------------------\n");
 
        if (verbose)
                symbol__annotate_hits(sym, evidx);
 
-       list_for_each_entry_safe(pos, n, &head, node) {
-               objdump_line__print(pos, &head, sym, evidx, len, min_pcnt);
-               list_del(&pos->node);
-               objdump_line__free(pos);
+       list_for_each_entry(pos, head, node) {
+               objdump_line__print(pos, head, sym, evidx, len, min_pcnt);
                if (max_lines && ++printed >= max_lines)
                        break;
+
+       }
+}
+
+void objdump_line_list__purge(struct list_head *head)
+{
+       struct objdump_line *pos, *n;
+
+       list_for_each_entry_safe(pos, n, head, node) {
+               list_del(&pos->node);
+               objdump_line__free(pos);
+       }
+}
+
+int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
+                        bool print_lines, bool full_paths, int min_pcnt,
+                        int max_lines)
+{
+       struct dso *dso = map->dso;
+       const char *filename = dso->long_name;
+       struct rb_root source_line = RB_ROOT;
+       LIST_HEAD(head);
+       u64 len;
+
+       if (symbol__annotate(sym, map, &head, 0) < 0)
+               return -1;
+
+       len = sym->end - sym->start;
+
+       if (print_lines) {
+               symbol__get_source_line(sym, map, evidx, &source_line,
+                                       len, filename);
+               print_summary(&source_line, filename);
        }
 
+       symbol__annotate_printf(sym, map, &head, evidx, full_paths,
+                               min_pcnt, max_lines);
        if (print_lines)
                symbol__free_source_line(sym, len);
 
+       objdump_line_list__purge(&head);
+
        return 0;
 }
index 6b707324e66fa8ec16443f1a374633bdbdc6c099..53dd92de2615f4ebeb424fc84275784cd865af68 100644 (file)
@@ -67,6 +67,10 @@ int symbol__alloc_hist(struct symbol *sym, int nevents);
 
 int symbol__annotate(struct symbol *sym, struct map *map,
                     struct list_head *head, size_t privsize);
+void symbol__annotate_printf(struct symbol *sym, struct map *map,
+                            struct list_head *head, int evidx, bool full_paths,
+                            int min_pcnt, int max_lines);
+void objdump_line_list__purge(struct list_head *head);
 
 int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
                         bool print_lines, bool full_paths, int min_pcnt,