Commit d5490b96 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf annotate: Move line/offset into annotation_line struct

Move the line/line_nr/offset menbers to the annotation_line struct to be
used as generic members for any annotation source.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20171011150158.11895-4-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a17c4ca0
...@@ -84,8 +84,9 @@ static bool disasm_line__filter(struct ui_browser *browser __maybe_unused, ...@@ -84,8 +84,9 @@ static bool disasm_line__filter(struct ui_browser *browser __maybe_unused,
void *entry) void *entry)
{ {
if (annotate_browser__opts.hide_src_code) { if (annotate_browser__opts.hide_src_code) {
struct disasm_line *dl = list_entry(entry, struct disasm_line, al.node); struct annotation_line *al = list_entry(entry, struct annotation_line, node);
return dl->offset == -1;
return al->offset == -1;
} }
return false; return false;
...@@ -141,7 +142,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -141,7 +142,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
percent_max = bdl->samples[i].percent; percent_max = bdl->samples[i].percent;
} }
if ((row == 0) && (dl->offset == -1 || percent_max == 0.0)) { if ((row == 0) && (dl->al.offset == -1 || percent_max == 0.0)) {
if (ab->have_cycles) { if (ab->have_cycles) {
if (dl->ipc == 0.0 && dl->cycles == 0) if (dl->ipc == 0.0 && dl->cycles == 0)
show_title = true; show_title = true;
...@@ -149,7 +150,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -149,7 +150,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
show_title = true; show_title = true;
} }
if (dl->offset != -1 && percent_max != 0.0) { if (dl->al.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, ui_browser__set_percent_color(browser,
bdl->samples[i].percent, bdl->samples[i].percent,
...@@ -199,19 +200,19 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -199,19 +200,19 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
if (!browser->navkeypressed) if (!browser->navkeypressed)
width += 1; width += 1;
if (!*dl->line) if (!*dl->al.line)
ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width); ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width);
else if (dl->offset == -1) { else if (dl->al.offset == -1) {
if (dl->line_nr && annotate_browser__opts.show_linenr) if (dl->al.line_nr && annotate_browser__opts.show_linenr)
printed = scnprintf(bf, sizeof(bf), "%-*d ", printed = scnprintf(bf, sizeof(bf), "%-*d ",
ab->addr_width + 1, dl->line_nr); ab->addr_width + 1, dl->al.line_nr);
else else
printed = scnprintf(bf, sizeof(bf), "%*s ", printed = scnprintf(bf, sizeof(bf), "%*s ",
ab->addr_width, " "); ab->addr_width, " ");
ui_browser__write_nstring(browser, bf, printed); ui_browser__write_nstring(browser, bf, printed);
ui_browser__write_nstring(browser, dl->line, width - printed - pcnt_width - cycles_width + 1); ui_browser__write_nstring(browser, dl->al.line, width - printed - pcnt_width - cycles_width + 1);
} else { } else {
u64 addr = dl->offset; u64 addr = dl->al.offset;
int color = -1; int color = -1;
if (!annotate_browser__opts.use_offset) if (!annotate_browser__opts.use_offset)
...@@ -247,7 +248,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -247,7 +248,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
ui_browser__set_color(browser, color); ui_browser__set_color(browser, color);
if (dl->ins.ops && dl->ins.ops->scnprintf) { if (dl->ins.ops && dl->ins.ops->scnprintf) {
if (ins__is_jump(&dl->ins)) { if (ins__is_jump(&dl->ins)) {
bool fwd = dl->ops.target.offset > dl->offset; bool fwd = dl->ops.target.offset > dl->al.offset;
ui_browser__write_graph(browser, fwd ? SLSMG_DARROW_CHAR : ui_browser__write_graph(browser, fwd ? SLSMG_DARROW_CHAR :
SLSMG_UARROW_CHAR); SLSMG_UARROW_CHAR);
...@@ -452,7 +453,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, ...@@ -452,7 +453,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
double max_percent = 0.0; double max_percent = 0.0;
int i; int i;
if (pos->offset == -1) { if (pos->al.offset == -1) {
RB_CLEAR_NODE(&bpos->rb_node); RB_CLEAR_NODE(&bpos->rb_node);
continue; continue;
} }
...@@ -464,8 +465,8 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser, ...@@ -464,8 +465,8 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
bpos->samples[i].percent = disasm__calc_percent(notes, bpos->samples[i].percent = disasm__calc_percent(notes,
evsel->idx + i, evsel->idx + i,
pos->offset, pos->al.offset,
next ? next->offset : len, next ? next->al.offset : len,
&path, &sample); &path, &sample);
bpos->samples[i].he = sample; bpos->samples[i].he = sample;
...@@ -590,7 +591,7 @@ struct disasm_line *annotate_browser__find_offset(struct annotate_browser *brows ...@@ -590,7 +591,7 @@ struct disasm_line *annotate_browser__find_offset(struct annotate_browser *brows
*idx = 0; *idx = 0;
list_for_each_entry(pos, &notes->src->source, al.node) { list_for_each_entry(pos, &notes->src->source, al.node) {
if (pos->offset == offset) if (pos->al.offset == offset)
return pos; return pos;
if (!disasm_line__filter(&browser->b, &pos->al.node)) if (!disasm_line__filter(&browser->b, &pos->al.node))
++*idx; ++*idx;
...@@ -636,7 +637,7 @@ struct disasm_line *annotate_browser__find_string(struct annotate_browser *brows ...@@ -636,7 +637,7 @@ struct disasm_line *annotate_browser__find_string(struct annotate_browser *brows
++*idx; ++*idx;
if (pos->line && strstr(pos->line, s) != NULL) if (pos->al.line && strstr(pos->al.line, s) != NULL)
return pos; return pos;
} }
...@@ -675,7 +676,7 @@ struct disasm_line *annotate_browser__find_string_reverse(struct annotate_browse ...@@ -675,7 +676,7 @@ struct disasm_line *annotate_browser__find_string_reverse(struct annotate_browse
--*idx; --*idx;
if (pos->line && strstr(pos->line, s) != NULL) if (pos->al.line && strstr(pos->al.line, s) != NULL)
return pos; return pos;
} }
...@@ -901,7 +902,7 @@ static int annotate_browser__run(struct annotate_browser *browser, ...@@ -901,7 +902,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
case K_RIGHT: case K_RIGHT:
if (browser->selection == NULL) if (browser->selection == NULL)
ui_helpline__puts("Huh? No selection. Report to linux-kernel@vger.kernel.org"); ui_helpline__puts("Huh? No selection. Report to linux-kernel@vger.kernel.org");
else if (browser->selection->offset == -1) else if (browser->selection->al.offset == -1)
ui_helpline__puts("Actions are only available for assembly lines."); ui_helpline__puts("Actions are only available for assembly lines.");
else if (!browser->selection->ins.ops) else if (!browser->selection->ins.ops)
goto show_sup_ins; goto show_sup_ins;
...@@ -1136,13 +1137,13 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, ...@@ -1136,13 +1137,13 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
list_for_each_entry(pos, &notes->src->source, al.node) { list_for_each_entry(pos, &notes->src->source, al.node) {
struct browser_disasm_line *bpos; struct browser_disasm_line *bpos;
size_t line_len = strlen(pos->line); size_t line_len = strlen(pos->al.line);
if (browser.b.width < line_len) if (browser.b.width < line_len)
browser.b.width = line_len; browser.b.width = line_len;
bpos = disasm_line__browser(pos); bpos = disasm_line__browser(pos);
bpos->idx = browser.nr_entries++; bpos->idx = browser.nr_entries++;
if (pos->offset != -1) { if (pos->al.offset != -1) {
bpos->idx_asm = browser.nr_asm_entries++; bpos->idx_asm = browser.nr_asm_entries++;
/* /*
* FIXME: short term bandaid to cope with assembly * FIXME: short term bandaid to cope with assembly
...@@ -1151,8 +1152,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, ...@@ -1151,8 +1152,8 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
* *
* E.g. copy_user_generic_unrolled * E.g. copy_user_generic_unrolled
*/ */
if (pos->offset < (s64)size) if (pos->al.offset < (s64)size)
browser.offsets[pos->offset] = pos; browser.offsets[pos->al.offset] = pos;
} else } else
bpos->idx_asm = -1; bpos->idx_asm = -1;
} }
......
...@@ -31,14 +31,14 @@ static int perf_gtk__get_percent(char *buf, size_t size, struct symbol *sym, ...@@ -31,14 +31,14 @@ static int perf_gtk__get_percent(char *buf, size_t size, struct symbol *sym,
strcpy(buf, ""); strcpy(buf, "");
if (dl->offset == (s64) -1) if (dl->al.offset == (s64) -1)
return 0; return 0;
symhist = annotation__histogram(symbol__annotation(sym), evidx); symhist = annotation__histogram(symbol__annotation(sym), evidx);
if (!symbol_conf.event_group && !symhist->addr[dl->offset].nr_samples) if (!symbol_conf.event_group && !symhist->addr[dl->al.offset].nr_samples)
return 0; return 0;
percent = 100.0 * symhist->addr[dl->offset].nr_samples / symhist->nr_samples; percent = 100.0 * symhist->addr[dl->al.offset].nr_samples / symhist->nr_samples;
markup = perf_gtk__get_percent_color(percent); markup = perf_gtk__get_percent_color(percent);
if (markup) if (markup)
...@@ -57,16 +57,16 @@ static int perf_gtk__get_offset(char *buf, size_t size, struct symbol *sym, ...@@ -57,16 +57,16 @@ static int perf_gtk__get_offset(char *buf, size_t size, struct symbol *sym,
strcpy(buf, ""); strcpy(buf, "");
if (dl->offset == (s64) -1) if (dl->al.offset == (s64) -1)
return 0; return 0;
return scnprintf(buf, size, "%"PRIx64, start + dl->offset); return scnprintf(buf, size, "%"PRIx64, start + dl->al.offset);
} }
static int perf_gtk__get_line(char *buf, size_t size, struct disasm_line *dl) static int perf_gtk__get_line(char *buf, size_t size, struct disasm_line *dl)
{ {
int ret = 0; int ret = 0;
char *line = g_markup_escape_text(dl->line, -1); char *line = g_markup_escape_text(dl->al.line, -1);
const char *markup = "<span fgcolor='gray'>"; const char *markup = "<span fgcolor='gray'>";
strcpy(buf, ""); strcpy(buf, "");
...@@ -74,7 +74,7 @@ static int perf_gtk__get_line(char *buf, size_t size, struct disasm_line *dl) ...@@ -74,7 +74,7 @@ static int perf_gtk__get_line(char *buf, size_t size, struct disasm_line *dl)
if (!line) if (!line)
return 0; return 0;
if (dl->offset != (s64) -1) if (dl->al.offset != (s64) -1)
markup = NULL; markup = NULL;
if (markup) if (markup)
......
...@@ -886,14 +886,15 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line, ...@@ -886,14 +886,15 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line,
struct disasm_line *dl = zalloc(sizeof(*dl) + privsize); struct disasm_line *dl = zalloc(sizeof(*dl) + privsize);
if (dl != NULL) { if (dl != NULL) {
dl->offset = offset; dl->al.offset = offset;
dl->line = strdup(line); dl->al.line = strdup(line);
dl->line_nr = line_nr; dl->al.line_nr = line_nr;
if (dl->line == NULL)
if (dl->al.line == NULL)
goto out_delete; goto out_delete;
if (offset != -1) { if (offset != -1) {
if (disasm_line__parse(dl->line, &dl->ins.name, &dl->ops.raw) < 0) if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) < 0)
goto out_free_line; goto out_free_line;
disasm_line__init_ins(dl, arch, map); disasm_line__init_ins(dl, arch, map);
...@@ -903,7 +904,7 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line, ...@@ -903,7 +904,7 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line,
return dl; return dl;
out_free_line: out_free_line:
zfree(&dl->line); zfree(&dl->al.line);
out_delete: out_delete:
free(dl); free(dl);
return NULL; return NULL;
...@@ -911,7 +912,7 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line, ...@@ -911,7 +912,7 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line,
void disasm_line__free(struct disasm_line *dl) void disasm_line__free(struct disasm_line *dl)
{ {
zfree(&dl->line); zfree(&dl->al.line);
if (dl->ins.ops && dl->ins.ops->free) if (dl->ins.ops && dl->ins.ops->free)
dl->ins.ops->free(&dl->ops); dl->ins.ops->free(&dl->ops);
else else
...@@ -937,7 +938,7 @@ static void disasm__add(struct list_head *head, struct disasm_line *line) ...@@ -937,7 +938,7 @@ static void disasm__add(struct list_head *head, struct disasm_line *line)
struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos) struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos)
{ {
list_for_each_entry_continue(pos, head, al.node) list_for_each_entry_continue(pos, head, al.node)
if (pos->offset >= 0) if (pos->al.offset >= 0)
return pos; return pos;
return NULL; return NULL;
...@@ -1077,7 +1078,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -1077,7 +1078,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
static const char *prev_line; static const char *prev_line;
static const char *prev_color; static const char *prev_color;
if (dl->offset != -1) { if (dl->al.offset != -1) {
const char *path = NULL; const char *path = NULL;
double percent, max_percent = 0.0; double percent, max_percent = 0.0;
double *ppercents = &percent; double *ppercents = &percent;
...@@ -1086,7 +1087,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -1086,7 +1087,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
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);
s64 offset = dl->offset; s64 offset = dl->al.offset;
const u64 addr = start + offset; const u64 addr = start + offset;
struct disasm_line *next; struct disasm_line *next;
struct block_range *br; struct block_range *br;
...@@ -1106,7 +1107,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -1106,7 +1107,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
percent = disasm__calc_percent(notes, percent = disasm__calc_percent(notes,
notes->src->lines ? i : evsel->idx + i, notes->src->lines ? i : evsel->idx + i,
offset, offset,
next ? next->offset : (s64) len, next ? next->al.offset : (s64) len,
&path, &sample); &path, &sample);
ppercents[i] = percent; ppercents[i] = percent;
...@@ -1165,7 +1166,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -1165,7 +1166,7 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st
br = block_range__find(addr); br = block_range__find(addr);
color_fprintf(stdout, annotate__address_color(br), " %" PRIx64 ":", addr); color_fprintf(stdout, annotate__address_color(br), " %" PRIx64 ":", addr);
color_fprintf(stdout, annotate__asm_color(br), "%s", dl->line); color_fprintf(stdout, annotate__asm_color(br), "%s", dl->al.line);
annotate__branch_printf(br, addr); annotate__branch_printf(br, addr);
printf("\n"); printf("\n");
...@@ -1186,10 +1187,10 @@ static int disasm_line__print(struct disasm_line *dl, struct symbol *sym, u64 st ...@@ -1186,10 +1187,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))
width *= evsel->nr_members; width *= evsel->nr_members;
if (!*dl->line) if (!*dl->al.line)
printf(" %*s:\n", width, " "); printf(" %*s:\n", width, " ");
else else
printf(" %*s: %s\n", width, " ", dl->line); printf(" %*s: %s\n", width, " ", dl->al.line);
} }
return 0; return 0;
...@@ -1311,9 +1312,9 @@ static void delete_last_nop(struct symbol *sym) ...@@ -1311,9 +1312,9 @@ static void delete_last_nop(struct symbol *sym)
if (dl->ins.ops != &nop_ops) if (dl->ins.ops != &nop_ops)
return; return;
} else { } else {
if (!strstr(dl->line, " nop ") && if (!strstr(dl->al.line, " nop ") &&
!strstr(dl->line, " nopl ") && !strstr(dl->al.line, " nopl ") &&
!strstr(dl->line, " nopw ")) !strstr(dl->al.line, " nopw "))
return; return;
} }
...@@ -1921,10 +1922,10 @@ static size_t disasm_line__fprintf(struct disasm_line *dl, FILE *fp) ...@@ -1921,10 +1922,10 @@ static size_t disasm_line__fprintf(struct disasm_line *dl, FILE *fp)
{ {
size_t printed; size_t printed;
if (dl->offset == -1) if (dl->al.offset == -1)
return fprintf(fp, "%s\n", dl->line); return fprintf(fp, "%s\n", dl->al.line);
printed = fprintf(fp, "%#" PRIx64 " %s", dl->offset, dl->ins.name); printed = fprintf(fp, "%#" PRIx64 " %s", dl->al.offset, dl->ins.name);
if (dl->ops.raw[0] != '\0') { if (dl->ops.raw[0] != '\0') {
printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ", printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ",
......
...@@ -61,14 +61,14 @@ struct annotation; ...@@ -61,14 +61,14 @@ struct annotation;
struct annotation_line { struct annotation_line {
struct list_head node; struct list_head node;
s64 offset;
char *line;
int line_nr;
}; };
struct disasm_line { struct disasm_line {
struct annotation_line al; struct annotation_line al;
s64 offset;
char *line;
struct ins ins; struct ins ins;
int line_nr;
float ipc; float ipc;
u64 cycles; u64 cycles;
struct ins_operands ops; struct ins_operands ops;
......
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