[PATCH 15/17] perf annotate browser: Show extra title line with event information

From: Arnaldo Carvalho de Melo
Date: Tue Apr 03 2018 - 22:24:06 EST


From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

So at the top we'll have two lines, like this, from 'perf report':

# perf report --group --ignore-vmlinux
=====================================================================================================
Samples: 46 of events 'cycles', 4000 Hz, Event count (approx.): 5154895
_raw_spin_lock_irqsave /proc/kcore
Percent â nop
â push %rbx
0.00 14.29 0.00 â pushfq
9.09 0.00 0.00 â pop %rax
9.09 0.00 20.00 â nop
â mov %rax,%rbx
â cli
4.55 7.14 0.00 â nop
â xor %eax,%eax
â mov $0x1,%edx
â lock cmpxchg %edx,(%rdi)
77.27 78.57 70.00 â test %eax,%eax
â â jne 2b
â mov %rbx,%rax
0.00 0.00 10.00 â pop %rbx
â â retq
â2b: mov %eax,%esi
â â callq queued_spin_lock_slowpath
â mov %rbx,%rax
â pop %rbx
Press 'h' for help onâkey bindings
=====================================================================================================

9.09 + 9.09 + 4.55 + 77.27 = 100
14.29 + 7.14 + 78.57 = 100
20 + 70 + 10 = 100

We can do the math by using 't' to toggle from 'percent' to nr

=====================================================================================================
Samples: 46 of events 'cycles', 4000 Hz, Event count (approx.): 5154895
_raw_spin_lock_irqsave /proc/kcore
Period â nop
â push %rbx
0 79273 0 â pushfq
190455 0 0 â pop %rax
198038 0 3045 â nop
â mov %rax,%rbx
â cli
217233 32562 0 â nop
â xor %eax,%eax
â mov $0x1,%edx
â lock cmpxchg %edx,(%rdi)
3421649 979174 28273 â test %eax,%eax
â â jne 2b
â mov %rbx,%rax
0 0 5193 â pop %rbx
â â retq
â2b: mov %eax,%esi
â â callq queued_spin_lock_slowpath
â mov %rbx,%rax
â pop %rbx
Press 'h' for help onâkey bindings
=====================================================================================================

79273 + 190455 + 198038 + 3045 + 217233 + 32562 + 3421649 + 979174 + 28273 + 5193 = 5154895

Or number of samples:

=====================================================================================================
ooSamples: 46 of events 'cycles', 4000 Hz, Event count (approx.): 5154895
_raw_spin_lock_irqsave /proc/kcore
Samples â nop
â push %rbx
0 2 0 â pushfq
2 0 0 â pop %rax
2 0 2 â nop
â mov %rax,%rbx
â cli
1 1 0 â nop
â xor %eax,%eax
â mov $0x1,%edx
â lock cmpxchg %edx,(%rdi)
17 11 7 â test %eax,%eax
â â jne 2b
â mov %rbx,%rax
0 0 1 â pop %rbx
â â retq
â2b: mov %eax,%esi
â â callq queued_spin_lock_slowpath
â mov %rbx,%rax
â pop %rbx
Press 'h' for help on key bindings
=====================================================================================================

2 + 2 + 2 + 2 + 1 + 1 + 17 + 11 + 7 + 1 = 46

Suggested-by: Martin LiÅka <mliska@xxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Wang Nan <wangnan0@xxxxxxxxxx>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=196935
Link: https://lkml.kernel.org/n/tip-ezccyxld50wtwyt66np6aomo@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/ui/browsers/annotate.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index c02fb437ac8e..78bcd220f1b6 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -592,21 +592,40 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser,
return __annotate_browser__search_reverse(browser);
}

+static int annotate_browser__show(struct ui_browser *browser, char *title, const char *help)
+{
+ struct map_symbol *ms = browser->priv;
+ struct symbol *sym = ms->sym;
+ char symbol_dso[SYM_TITLE_MAX_SIZE];
+
+ if (ui_browser__show(browser, title, help) < 0)
+ return -1;
+
+ sym_title(sym, ms->map, symbol_dso, sizeof(symbol_dso));
+
+ ui_browser__gotorc_title(browser, 0, 0);
+ ui_browser__set_color(browser, HE_COLORSET_ROOT);
+ ui_browser__write_nstring(browser, symbol_dso, browser->width + 1);
+ return 0;
+}
+
static int annotate_browser__run(struct annotate_browser *browser,
struct perf_evsel *evsel,
struct hist_browser_timer *hbt)
{
struct rb_node *nd = NULL;
+ struct hists *hists = evsel__hists(evsel);
struct map_symbol *ms = browser->b.priv;
struct symbol *sym = ms->sym;
struct annotation *notes = symbol__annotation(ms->sym);
const char *help = "Press 'h' for help on key bindings";
int delay_secs = hbt ? hbt->refresh : 0;
+ char title[256];
int key;
- char title[SYM_TITLE_MAX_SIZE];

- sym_title(sym, ms->map, title, sizeof(title));
- if (ui_browser__show(&browser->b, title, help) < 0)
+ annotation__scnprintf_samples_period(notes, title, sizeof(title), evsel);
+
+ if (annotate_browser__show(&browser->b, title, help) < 0)
return -1;

annotate_browser__calc_percent(browser, evsel);
@@ -637,8 +656,11 @@ static int annotate_browser__run(struct annotate_browser *browser,
if (hbt)
hbt->timer(hbt->arg);

- if (delay_secs != 0)
+ if (delay_secs != 0) {
symbol__annotate_decay_histogram(sym, evsel->idx);
+ hists__scnprintf_title(hists, title, sizeof(title));
+ annotate_browser__show(&browser->b, title, help);
+ }
continue;
case K_TAB:
if (nd != NULL) {
@@ -812,6 +834,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
.seek = ui_browser__list_head_seek,
.write = annotate_browser__write,
.filter = disasm_line__filter,
+ .extra_title_lines = 1, /* for hists__scnprintf_title() */
.priv = &ms,
.use_navkeypressed = true,
},
--
2.14.3