Skip to content

Commit f8f4aae

Browse files
Andi Kleenacmel
authored andcommitted
perf annotate: Finally display IPC and cycle accounting
Add two new columns to the annotate display and display the average cycles and the compute IPC if available. When the LBR was not in any branch mode the IPC computation is automatically disabled. We still display the cycle information. Example output (with made up numbers): The second column is the IPC and third average cycles. │ __attribute__((noinline)) f2() │ { 5.15 0.07 │ push %rbp 0.01 0.07 │ mov %rsp,%rbp │ c = a / b; 9.87 0.07 │ mov a,%eax 0.07 │ mov b,%ecx 0.07 │ cltd 4.92 0.07 123│ idiv %ecx 70.79 0.07 │ mov %eax,__TMC_END__ │ } 9.25 0.07 │ pop %rbp 0.01 0.07 123│ ← retq v2: Fix display problems. Signed-off-by: Andi Kleen <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 30e863b commit f8f4aae

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

tools/perf/ui/browsers/annotate.c

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ struct disasm_line_samples {
1616
u64 nr;
1717
};
1818

19+
#define IPC_WIDTH 6
20+
#define CYCLES_WIDTH 6
21+
1922
struct browser_disasm_line {
2023
struct rb_node rb_node;
2124
u32 idx;
@@ -97,6 +100,15 @@ static int annotate_browser__set_jumps_percent_color(struct annotate_browser *br
97100
return ui_browser__set_color(&browser->b, color);
98101
}
99102

103+
static int annotate_browser__pcnt_width(struct annotate_browser *ab)
104+
{
105+
int w = 7 * ab->nr_events;
106+
107+
if (ab->have_cycles)
108+
w += IPC_WIDTH + CYCLES_WIDTH;
109+
return w;
110+
}
111+
100112
static void annotate_browser__write(struct ui_browser *browser, void *entry, int row)
101113
{
102114
struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
@@ -107,7 +119,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
107119
(!current_entry || (browser->use_navkeypressed &&
108120
!browser->navkeypressed)));
109121
int width = browser->width, printed;
110-
int i, pcnt_width = 7 * ab->nr_events;
122+
int i, pcnt_width = annotate_browser__pcnt_width(ab);
111123
double percent_max = 0.0;
112124
char bf[256];
113125

@@ -117,19 +129,34 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
117129
}
118130

119131
if (dl->offset != -1 && percent_max != 0.0) {
120-
for (i = 0; i < ab->nr_events; i++) {
121-
ui_browser__set_percent_color(browser,
122-
bdl->samples[i].percent,
123-
current_entry);
124-
if (annotate_browser__opts.show_total_period)
125-
slsmg_printf("%6" PRIu64 " ",
126-
bdl->samples[i].nr);
127-
else
128-
slsmg_printf("%6.2f ", bdl->samples[i].percent);
132+
if (percent_max != 0.0) {
133+
for (i = 0; i < ab->nr_events; i++) {
134+
ui_browser__set_percent_color(browser,
135+
bdl->samples[i].percent,
136+
current_entry);
137+
if (annotate_browser__opts.show_total_period)
138+
slsmg_printf("%6" PRIu64 " ",
139+
bdl->samples[i].nr);
140+
else
141+
slsmg_printf("%6.2f ", bdl->samples[i].percent);
142+
}
143+
} else {
144+
slsmg_write_nstring(" ", 7 * ab->nr_events);
129145
}
130146
} else {
131147
ui_browser__set_percent_color(browser, 0, current_entry);
132-
slsmg_write_nstring(" ", pcnt_width);
148+
slsmg_write_nstring(" ", 7 * ab->nr_events);
149+
}
150+
if (ab->have_cycles) {
151+
if (dl->ipc)
152+
slsmg_printf("%*.2f ", IPC_WIDTH - 1, dl->ipc);
153+
else
154+
slsmg_write_nstring(" ", IPC_WIDTH);
155+
if (dl->cycles)
156+
slsmg_printf("%*" PRIu64 " ",
157+
CYCLES_WIDTH - 1, dl->cycles);
158+
else
159+
slsmg_write_nstring(" ", CYCLES_WIDTH);
133160
}
134161

135162
SLsmg_write_char(' ');
@@ -232,7 +259,7 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
232259
unsigned int from, to;
233260
struct map_symbol *ms = ab->b.priv;
234261
struct symbol *sym = ms->sym;
235-
u8 pcnt_width = 7;
262+
u8 pcnt_width = annotate_browser__pcnt_width(ab);
236263

237264
/* PLT symbols contain external offsets */
238265
if (strstr(sym->name, "@plt"))
@@ -256,8 +283,6 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
256283
to = (u64)btarget->idx;
257284
}
258285

259-
pcnt_width *= ab->nr_events;
260-
261286
ui_browser__set_color(browser, HE_COLORSET_CODE);
262287
__ui_browser__line_arrow(browser, pcnt_width + 2 + ab->addr_width,
263288
from, to);
@@ -267,9 +292,7 @@ static unsigned int annotate_browser__refresh(struct ui_browser *browser)
267292
{
268293
struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
269294
int ret = ui_browser__list_head_refresh(browser);
270-
int pcnt_width;
271-
272-
pcnt_width = 7 * ab->nr_events;
295+
int pcnt_width = annotate_browser__pcnt_width(ab);
273296

274297
if (annotate_browser__opts.jump_arrows)
275298
annotate_browser__draw_current_jump(browser);

0 commit comments

Comments
 (0)