perf annotate: Move the column widths from the TUI to generic lib

This also will be used in other output formats, such as --stdio2.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-86h6ftebc62ij1rx8q9zkpwk@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 5bc49f61
...@@ -36,11 +36,6 @@ struct annotate_browser { ...@@ -36,11 +36,6 @@ struct annotate_browser {
struct annotation_line *selection; struct annotation_line *selection;
struct arch *arch; struct arch *arch;
bool searching_backwards; bool searching_backwards;
u8 addr_width;
u8 jumps_width;
u8 target_width;
u8 min_addr_width;
u8 max_addr_width;
char search_bf[128]; char search_bf[128];
}; };
...@@ -194,10 +189,10 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -194,10 +189,10 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
else if (al->offset == -1) { else if (al->offset == -1) {
if (al->line_nr && notes->options->show_linenr) if (al->line_nr && notes->options->show_linenr)
printed = scnprintf(bf, sizeof(bf), "%-*d ", printed = scnprintf(bf, sizeof(bf), "%-*d ",
ab->addr_width + 1, al->line_nr); notes->widths.addr + 1, al->line_nr);
else else
printed = scnprintf(bf, sizeof(bf), "%*s ", printed = scnprintf(bf, sizeof(bf), "%*s ",
ab->addr_width, " "); notes->widths.addr, " ");
ui_browser__write_nstring(browser, bf, printed); ui_browser__write_nstring(browser, bf, printed);
ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1); ui_browser__write_nstring(browser, al->line, width - printed - pcnt_width - cycles_width + 1);
} else { } else {
...@@ -214,7 +209,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -214,7 +209,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
if (notes->options->show_nr_jumps) { if (notes->options->show_nr_jumps) {
int prev; int prev;
printed = scnprintf(bf, sizeof(bf), "%*d ", printed = scnprintf(bf, sizeof(bf), "%*d ",
ab->jumps_width, notes->widths.jumps,
al->jump_sources); al->jump_sources);
prev = ui_browser__set_jumps_percent_color(browser, al->jump_sources, prev = ui_browser__set_jumps_percent_color(browser, al->jump_sources,
current_entry); current_entry);
...@@ -223,10 +218,10 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int ...@@ -223,10 +218,10 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
} }
printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ", printed = scnprintf(bf, sizeof(bf), "%*" PRIx64 ": ",
ab->target_width, addr); notes->widths.target, addr);
} else { } else {
printed = scnprintf(bf, sizeof(bf), "%*s ", printed = scnprintf(bf, sizeof(bf), "%*s ",
ab->addr_width, " "); notes->widths.addr, " ");
} }
} }
...@@ -322,12 +317,12 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser) ...@@ -322,12 +317,12 @@ static void annotate_browser__draw_current_jump(struct ui_browser *browser)
ui_browser__set_color(browser, HE_COLORSET_JUMP_ARROWS); ui_browser__set_color(browser, HE_COLORSET_JUMP_ARROWS);
__ui_browser__line_arrow(browser, __ui_browser__line_arrow(browser,
pcnt_width + 2 + ab->addr_width + width, pcnt_width + 2 + notes->widths.addr + width,
from, to); from, to);
if (is_fused(ab, cursor)) { if (is_fused(ab, cursor)) {
ui_browser__mark_fused(browser, ui_browser__mark_fused(browser,
pcnt_width + 3 + ab->addr_width + width, pcnt_width + 3 + notes->widths.addr + width,
from - 1, from - 1,
to > from ? true : false); to > from ? true : false);
} }
...@@ -703,19 +698,17 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser, ...@@ -703,19 +698,17 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser,
return __annotate_browser__search_reverse(browser); return __annotate_browser__search_reverse(browser);
} }
static void annotate_browser__update_addr_width(struct annotate_browser *browser) static void annotation__update_column_widths(struct annotation *notes)
{ {
struct annotation *notes = browser__annotation(&browser->b);
if (notes->options->use_offset) if (notes->options->use_offset)
browser->target_width = browser->min_addr_width; notes->widths.target = notes->widths.min_addr;
else else
browser->target_width = browser->max_addr_width; notes->widths.target = notes->widths.max_addr;
browser->addr_width = browser->target_width; notes->widths.addr = notes->widths.target;
if (notes->options->show_nr_jumps) if (notes->options->show_nr_jumps)
browser->addr_width += browser->jumps_width + 1; notes->widths.addr += notes->widths.jumps + 1;
} }
static int annotate_browser__run(struct annotate_browser *browser, static int annotate_browser__run(struct annotate_browser *browser,
...@@ -820,14 +813,14 @@ static int annotate_browser__run(struct annotate_browser *browser, ...@@ -820,14 +813,14 @@ static int annotate_browser__run(struct annotate_browser *browser,
continue; continue;
case 'o': case 'o':
notes->options->use_offset = !notes->options->use_offset; notes->options->use_offset = !notes->options->use_offset;
annotate_browser__update_addr_width(browser); annotation__update_column_widths(notes);
continue; continue;
case 'j': case 'j':
notes->options->jump_arrows = !notes->options->jump_arrows; notes->options->jump_arrows = !notes->options->jump_arrows;
continue; continue;
case 'J': case 'J':
notes->options->show_nr_jumps = !notes->options->show_nr_jumps; notes->options->show_nr_jumps = !notes->options->show_nr_jumps;
annotate_browser__update_addr_width(browser); annotation__update_column_widths(notes);
continue; continue;
case '/': case '/':
if (annotate_browser__search(browser, delay_secs)) { if (annotate_browser__search(browser, delay_secs)) {
...@@ -884,7 +877,7 @@ static int annotate_browser__run(struct annotate_browser *browser, ...@@ -884,7 +877,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
notes->options->show_nr_samples = false; notes->options->show_nr_samples = false;
else else
notes->options->show_total_period = true; notes->options->show_total_period = true;
annotate_browser__update_addr_width(browser); annotation__update_column_widths(notes);
continue; continue;
case K_LEFT: case K_LEFT:
case K_ESC: case K_ESC:
...@@ -995,9 +988,9 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, ...@@ -995,9 +988,9 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
annotation__mark_jump_targets(notes, sym); annotation__mark_jump_targets(notes, sym);
annotation__compute_ipc(notes, size); annotation__compute_ipc(notes, size);
browser.addr_width = browser.target_width = browser.min_addr_width = hex_width(size); notes->widths.addr = notes->widths.target = notes->widths.min_addr = hex_width(size);
browser.max_addr_width = hex_width(sym->end); notes->widths.max_addr = hex_width(sym->end);
browser.jumps_width = width_jumps(notes->max_jump_sources); notes->widths.jumps = width_jumps(notes->max_jump_sources);
notes->nr_events = nr_pcnt; notes->nr_events = nr_pcnt;
browser.b.nr_entries = notes->nr_entries; browser.b.nr_entries = notes->nr_entries;
browser.b.entries = &notes->src->source, browser.b.entries = &notes->src->source,
...@@ -1006,7 +999,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map, ...@@ -1006,7 +999,7 @@ int symbol__tui_annotate(struct symbol *sym, struct map *map,
if (notes->options->hide_src_code) if (notes->options->hide_src_code)
ui_browser__init_asm_mode(&browser.b); ui_browser__init_asm_mode(&browser.b);
annotate_browser__update_addr_width(&browser); annotation__update_column_widths(notes);
ret = annotate_browser__run(&browser, evsel, hbt); ret = annotate_browser__run(&browser, evsel, hbt);
......
...@@ -178,6 +178,13 @@ struct annotation { ...@@ -178,6 +178,13 @@ struct annotation {
int nr_entries; int nr_entries;
int nr_asm_entries; int nr_asm_entries;
u16 max_line_len; u16 max_line_len;
struct {
u8 addr;
u8 jumps;
u8 target;
u8 min_addr;
u8 max_addr;
} widths;
bool have_cycles; bool have_cycles;
struct annotated_source *src; struct annotated_source *src;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册