[PATCH v1 2/2] perf report: Display titles in left frame of annotate browser

From: Jin Yao
Date: Thu May 04 2017 - 03:01:04 EST


The annotate browser is divided into 2 frames. Left frame
contains 3 columns (some platforms only have one column).

For example:

â26 int compute_flag()
â27 {
22.80 1.20 â sub $0x8,%rsp
â25 int i;
â
â27 i = rand() % 2;
22.78 1.20 1 â â callq rand@plt

While it's hard for user to understand what the data is.

This patch adds the titles "Percent", "IPC" and "Cycle"
on columns.

Percnt IPC Cycle â
â25 __attribute__((noinline))
â26 int compute_flag()
â27 {
22.80 1.20 â sub $0x8,%rsp
â25 int i;
â
â27 i = rand() % 2;
22.78 1.20 1 â â callq rand@plt

The titles are displayed at row 0 of annotate browser if row 0
doesn't have values of percent, ipc and cycle.

Signed-off-by: Jin Yao <yao.jin@xxxxxxxxxxxxxxx>
---
tools/perf/ui/browsers/annotate.c | 27 ++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 52c1e8d..b1da5fb 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -125,12 +125,21 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
int i, pcnt_width = annotate_browser__pcnt_width(ab);
double percent_max = 0.0;
char bf[256];
+ bool show_title = false;

for (i = 0; i < ab->nr_events; i++) {
if (bdl->samples[i].percent > percent_max)
percent_max = bdl->samples[i].percent;
}

+ if ((row == 0) && (dl->offset == -1 || percent_max == 0.0)) {
+ if (ab->have_cycles) {
+ if (dl->ipc == 0.0 && dl->cycles == 0)
+ show_title = true;
+ } else
+ show_title = true;
+ }
+
if (dl->offset != -1 && percent_max != 0.0) {
for (i = 0; i < ab->nr_events; i++) {
ui_browser__set_percent_color(browser,
@@ -146,18 +155,30 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
}
} else {
ui_browser__set_percent_color(browser, 0, current_entry);
- ui_browser__write_nstring(browser, " ", 7 * ab->nr_events);
+
+ if (!show_title)
+ ui_browser__write_nstring(browser, " ",
+ 7 * ab->nr_events);
+ else
+ ui_browser__printf(browser, "%*s ", 6, "Percnt");
}
if (ab->have_cycles) {
if (dl->ipc)
ui_browser__printf(browser, "%*.2f ", IPC_WIDTH - 1, dl->ipc);
- else
+ else if (!show_title)
ui_browser__write_nstring(browser, " ", IPC_WIDTH);
+ else
+ ui_browser__printf(browser, "%*s ",
+ IPC_WIDTH - 1, "IPC");
+
if (dl->cycles)
ui_browser__printf(browser, "%*" PRIu64 " ",
CYCLES_WIDTH - 1, dl->cycles);
- else
+ else if (!show_title)
ui_browser__write_nstring(browser, " ", CYCLES_WIDTH);
+ else
+ ui_browser__printf(browser, "%*s ",
+ CYCLES_WIDTH - 1, "Cycle");
}

SLsmg_write_char(' ');
--
2.7.4