Commit 0c4a5bce authored by Martin Liška's avatar Martin Liška Committed by Arnaldo Carvalho de Melo

perf annotate: Display total number of samples with --show-total-period

To compare two records on an instruction base, with --show-total-period
option provided, display total number of samples that belong to a line
in assembly language.

New hot key 't' is introduced for 'perf annotate' TUI.
Signed-off-by: default avatarMartin Liska <mliska@suse.cz>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/5583E26D.1040407@suse.czSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a5499b37
...@@ -329,6 +329,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused) ...@@ -329,6 +329,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
"objdump binary to use for disassembly and annotations"), "objdump binary to use for disassembly and annotations"),
OPT_BOOLEAN(0, "group", &symbol_conf.event_group, OPT_BOOLEAN(0, "group", &symbol_conf.event_group,
"Show event group information together"), "Show event group information together"),
OPT_BOOLEAN(0, "show-total-period", &symbol_conf.show_total_period,
"Show a column with the sum of periods"),
OPT_END() OPT_END()
}; };
int ret = hists__init(); int ret = hists__init();
......
...@@ -11,16 +11,21 @@ ...@@ -11,16 +11,21 @@
#include "../../util/evsel.h" #include "../../util/evsel.h"
#include <pthread.h> #include <pthread.h>
struct disasm_line_samples {
double percent;
u64 nr;
};
struct browser_disasm_line { struct browser_disasm_line {
struct rb_node rb_node; struct rb_node rb_node;
u32 idx; u32 idx;
int idx_asm; int idx_asm;
int jump_sources; int jump_sources;
/* /*
* actual length of this array is saved on the nr_events field * actual length of this array is saved on the nr_events field
* of the struct annotate_browser * of the struct annotate_browser
*/ */
double percent[1]; struct disasm_line_samples samples[1];
}; };
static struct annotate_browser_opt { static struct annotate_browser_opt {
...@@ -28,7 +33,8 @@ static struct annotate_browser_opt { ...@@ -28,7 +33,8 @@ static struct annotate_browser_opt {
use_offset, use_offset,
jump_arrows, jump_arrows,
show_linenr, show_linenr,
show_nr_jumps; show_nr_jumps,
show_total_period;
} annotate_browser__opts = { } annotate_browser__opts = {
.use_offset = true, .use_offset = true,
.jump_arrows = true, .jump_arrows = true,
...@@ -105,15 +111,20 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -105,15 +111,20 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
char bf[256]; char bf[256];
for (i = 0; i < ab->nr_events; i++) { for (i = 0; i < ab->nr_events; i++) {
if (bdl->percent[i] > percent_max) if (bdl->samples[i].percent > percent_max)
percent_max = bdl->percent[i]; percent_max = bdl->samples[i].percent;
} }
if (dl->offset != -1 && percent_max != 0.0) { if (dl->offset != -1 && percent_max != 0.0) {
for (i = 0; i < ab->nr_events; i++) { for (i = 0; i < ab->nr_events; i++) {
ui_browser__set_percent_color(browser, bdl->percent[i], ui_browser__set_percent_color(browser,
bdl->samples[i].percent,
current_entry); current_entry);
slsmg_printf("%6.2f ", bdl->percent[i]); if (annotate_browser__opts.show_total_period)
slsmg_printf("%6" PRIu64 " ",
bdl->samples[i].nr);
else
slsmg_printf("%6.2f ", bdl->samples[i].percent);
} }
} else { } else {
ui_browser__set_percent_color(browser, 0, current_entry); ui_browser__set_percent_color(browser, 0, current_entry);
...@@ -273,9 +284,9 @@ static int disasm__cmp(struct browser_disasm_line *a, ...@@ -273,9 +284,9 @@ static int disasm__cmp(struct browser_disasm_line *a,
int i; int i;
for (i = 0; i < nr_pcnt; i++) { for (i = 0; i < nr_pcnt; i++) {
if (a->percent[i] == b->percent[i]) if (a->samples[i].percent == b->samples[i].percent)
continue; continue;
return a->percent[i] < b->percent[i]; return a->samples[i].percent < b->samples[i].percent;
} }
return 0; return 0;
} }
...@@ -366,14 +377,17 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, ...@@ -366,14 +377,17 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
next = disasm__get_next_ip_line(&notes->src->source, pos); next = disasm__get_next_ip_line(&notes->src->source, pos);
for (i = 0; i < browser->nr_events; i++) { for (i = 0; i < browser->nr_events; i++) {
bpos->percent[i] = disasm__calc_percent(notes, u64 nr_samples;
bpos->samples[i].percent = disasm__calc_percent(notes,
evsel->idx + i, evsel->idx + i,
pos->offset, pos->offset,
next ? next->offset : len, next ? next->offset : len,
&path); &path, &nr_samples);
bpos->samples[i].nr = nr_samples;
if (max_percent < bpos->percent[i]) if (max_percent < bpos->samples[i].percent)
max_percent = bpos->percent[i]; max_percent = bpos->samples[i].percent;
} }
if (max_percent < 0.01) { if (max_percent < 0.01) {
...@@ -737,6 +751,7 @@ static int annotate_browser__run(struct annotate_browser *browser, ...@@ -737,6 +751,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
"n Search next string\n" "n Search next string\n"
"o Toggle disassembler output/simplified view\n" "o Toggle disassembler output/simplified view\n"
"s Toggle source code view\n" "s Toggle source code view\n"
"t Toggle total period view\n"
"/ Search string\n" "/ Search string\n"
"k Toggle line numbers\n" "k Toggle line numbers\n"
"r Run available scripts\n" "r Run available scripts\n"
...@@ -812,6 +827,11 @@ static int annotate_browser__run(struct annotate_browser *browser, ...@@ -812,6 +827,11 @@ static int annotate_browser__run(struct annotate_browser *browser,
ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions."); ui_helpline__puts("Actions are only available for 'callq', 'retq' & jump instructions.");
} }
continue; continue;
case 't':
annotate_browser__opts.show_total_period =
!annotate_browser__opts.show_total_period;
annotate_browser__update_addr_width(browser);
continue;
case K_LEFT: case K_LEFT:
case K_ESC: case K_ESC:
case 'q': case 'q':
...@@ -832,6 +852,10 @@ static int annotate_browser__run(struct annotate_browser *browser, ...@@ -832,6 +852,10 @@ static int annotate_browser__run(struct annotate_browser *browser,
int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel, int map_symbol__tui_annotate(struct map_symbol *ms, struct perf_evsel *evsel,
struct hist_browser_timer *hbt) struct hist_browser_timer *hbt)
{ {
/* Set default value for show_total_period. */
annotate_browser__opts.show_total_period =
symbol_conf.show_total_period;
return symbol__tui_annotate(ms->sym, ms->map, evsel, hbt); return symbol__tui_annotate(ms->sym, ms->map, evsel, hbt);
} }
...@@ -929,7 +953,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, ...@@ -929,7 +953,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
if (perf_evsel__is_group_event(evsel)) { if (perf_evsel__is_group_event(evsel)) {
nr_pcnt = evsel->nr_members; nr_pcnt = evsel->nr_members;
sizeof_bdl += sizeof(double) * (nr_pcnt - 1); sizeof_bdl += sizeof(struct disasm_line_samples) *
(nr_pcnt - 1);
} }
if (symbol__annotate(sym, map, sizeof_bdl) < 0) { if (symbol__annotate(sym, map, sizeof_bdl) < 0) {
...@@ -1006,6 +1031,7 @@ static struct annotate_config { ...@@ -1006,6 +1031,7 @@ static struct annotate_config {
ANNOTATE_CFG(show_linenr), ANNOTATE_CFG(show_linenr),
ANNOTATE_CFG(show_nr_jumps), ANNOTATE_CFG(show_nr_jumps),
ANNOTATE_CFG(use_offset), ANNOTATE_CFG(use_offset),
ANNOTATE_CFG(show_total_period),
}; };
#undef ANNOTATE_CFG #undef ANNOTATE_CFG
......
...@@ -654,10 +654,11 @@ struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disa ...@@ -654,10 +654,11 @@ struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disa
} }
double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
s64 end, const char **path) s64 end, const char **path, u64 *nr_samples)
{ {
struct source_line *src_line = notes->src->lines; struct source_line *src_line = notes->src->lines;
double percent = 0.0; double percent = 0.0;
*nr_samples = 0;
if (src_line) { if (src_line) {
size_t sizeof_src_line = sizeof(*src_line) + size_t sizeof_src_line = sizeof(*src_line) +
...@@ -671,6 +672,7 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, ...@@ -671,6 +672,7 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
*path = src_line->path; *path = src_line->path;
percent += src_line->p[evidx].percent; percent += src_line->p[evidx].percent;
*nr_samples += src_line->p[evidx].samples;
offset++; offset++;
} }
} else { } else {
...@@ -680,8 +682,10 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, ...@@ -680,8 +682,10 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
while (offset < end) while (offset < end)
hits += h->addr[offset++]; hits += h->addr[offset++];
if (h->sum) if (h->sum) {
*nr_samples = hits;
percent = 100.0 * hits / h->sum; percent = 100.0 * hits / h->sum;
}
} }
return percent; return percent;
...@@ -696,8 +700,10 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -696,8 +700,10 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
if (dl->offset != -1) { if (dl->offset != -1) {
const char *path = NULL; const char *path = NULL;
u64 nr_samples;
double percent, max_percent = 0.0; double percent, max_percent = 0.0;
double *ppercents = &percent; double *ppercents = &percent;
u64 *psamples = &nr_samples;
int i, nr_percent = 1; int i, nr_percent = 1;
const char *color; const char *color;
struct annotation *notes = symbol__annotation(sym); struct annotation *notes = symbol__annotation(sym);
...@@ -710,8 +716,10 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -710,8 +716,10 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
if (perf_evsel__is_group_event(evsel)) { if (perf_evsel__is_group_event(evsel)) {
nr_percent = evsel->nr_members; nr_percent = evsel->nr_members;
ppercents = calloc(nr_percent, sizeof(double)); ppercents = calloc(nr_percent, sizeof(double));
if (ppercents == NULL) psamples = calloc(nr_percent, sizeof(u64));
if (ppercents == NULL || psamples == NULL) {
return -1; return -1;
}
} }
for (i = 0; i < nr_percent; i++) { for (i = 0; i < nr_percent; i++) {
...@@ -719,9 +727,10 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -719,9 +727,10 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
notes->src->lines ? i : evsel->idx + i, notes->src->lines ? i : evsel->idx + i,
offset, offset,
next ? next->offset : (s64) len, next ? next->offset : (s64) len,
&path); &path, &nr_samples);
ppercents[i] = percent; ppercents[i] = percent;
psamples[i] = nr_samples;
if (percent > max_percent) if (percent > max_percent)
max_percent = percent; max_percent = percent;
} }
...@@ -759,8 +768,14 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -759,8 +768,14 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
for (i = 0; i < nr_percent; i++) { for (i = 0; i < nr_percent; i++) {
percent = ppercents[i]; percent = ppercents[i];
nr_samples = psamples[i];
color = get_percent_color(percent); color = get_percent_color(percent);
color_fprintf(stdout, color, " %7.2f", percent);
if (symbol_conf.show_total_period)
color_fprintf(stdout, color, " %7" PRIu64,
nr_samples);
else
color_fprintf(stdout, color, " %7.2f", percent);
} }
printf(" : "); printf(" : ");
...@@ -770,6 +785,9 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -770,6 +785,9 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
if (ppercents != &percent) if (ppercents != &percent)
free(ppercents); free(ppercents);
if (psamples != &nr_samples)
free(psamples);
} else if (max_lines && printed >= max_lines) } else if (max_lines && printed >= max_lines)
return 1; return 1;
else { else {
......
...@@ -72,7 +72,7 @@ struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disa ...@@ -72,7 +72,7 @@ struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disa
int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw); int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
size_t disasm__fprintf(struct list_head *head, FILE *fp); size_t disasm__fprintf(struct list_head *head, FILE *fp);
double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
s64 end, const char **path); s64 end, const char **path, u64 *nr_samples);
struct sym_hist { struct sym_hist {
u64 sum; u64 sum;
...@@ -82,6 +82,7 @@ struct sym_hist { ...@@ -82,6 +82,7 @@ struct sym_hist {
struct source_line_percent { struct source_line_percent {
double percent; double percent;
double percent_sum; double percent_sum;
double samples;
}; };
struct source_line { struct source_line {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment