perf annotate browser: Align jump labels
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 19 Apr 2012 16:15:24 +0000 (13:15 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 19 Apr 2012 16:15:24 +0000 (13:15 -0300)
Find out at browser startup the max width and use it when rendering jump
labels on the screen.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-7dxjiwqb77wz6f5lc05e0i0x@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/ui/browsers/annotate.c
tools/perf/util/util.c
tools/perf/util/util.h

index a1e942bb903b5a21dd0a03b506d722fdb70b16be..c5ab21c50a74a4cf3110aad79a57612ec5e93be7 100644 (file)
@@ -31,6 +31,7 @@ struct annotate_browser {
        bool                hide_src_code;
        bool                use_offset;
        bool                searching_backwards;
+       u8                  offset_width;
        char                search_bf[128];
 };
 
@@ -92,10 +93,17 @@ static void annotate_browser__write(struct ui_browser *self, void *entry, int ro
                if (!ab->use_offset)
                        addr += ab->start;
 
-               if (bdl->jump_target || !ab->use_offset)
-                       printed = scnprintf(bf, sizeof(bf), " %" PRIx64 ":", addr);
-               else
-                       printed = scnprintf(bf, sizeof(bf), "    ");
+               if (!ab->use_offset) {
+                       printed = scnprintf(bf, sizeof(bf), "%" PRIx64 ":", addr);
+               } else {
+                       if (bdl->jump_target) {
+                               printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ":",
+                                                   ab->offset_width, addr);
+                       } else {
+                               printed = scnprintf(bf, sizeof(bf), "%*s ",
+                                                   ab->offset_width, " ");
+                       }
+               }
 
                if (change_color)
                        color = ui_browser__set_color(self, HE_COLORSET_ADDR);
@@ -687,6 +695,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, int evidx,
 
        annotate_browser__mark_jump_targets(&browser, size);
 
+       browser.offset_width = hex_width(size);
        browser.b.nr_entries = browser.nr_entries;
        browser.b.entries = &notes->src->source,
        browser.b.width += 18; /* Percentage */
index 8109a907841e63edb56020abd6e03aca8c463eb7..d03599fbe78bab080e59a096c3629b650bc12e84 100644 (file)
@@ -148,3 +148,13 @@ int readn(int fd, void *buf, size_t n)
 
        return buf - buf_start;
 }
+
+size_t hex_width(u64 v)
+{
+       size_t n = 1;
+
+       while ((v >>= 4))
+               ++n;
+
+       return n;
+}
index 0f99f394d8e089db67d38584660b57e903049709..6121e24fefc03e4932de81343ac700ff1da7443f 100644 (file)
@@ -265,4 +265,6 @@ bool is_power_of_2(unsigned long n)
        return (n != 0 && ((n & (n - 1)) == 0));
 }
 
+size_t hex_width(u64 v);
+
 #endif