Skip to content

Commit bc1e5d6

Browse files
committed
perf annotate TUI: Clarify calculation of column header widths
In commit f8f4aae ("perf annotate: Finally display IPC and cycle accounting") the 'pcnt_width' variable was abused in a few places to also include the optional width of the "IPC" and "cycles" columns, while in other places we stopped using 'pcnt_width' and instead its previous equation... Now that we need to tap into annotate_browser__pcnt_width() to consider if --show-total-period is being used and instead of that hardcoded 7 (strlen("Percent")) we need to use it or strlen("Event count") we need this properly clarified to avoid having to touch all the (7 * nr_events) places. Clarify this by introducing a separate annotate_browser__cycles_width() to leave the pcnt_width calculate just what its name implies. Cc: Taeung Song <[email protected]> Cc: Milian Wolff <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Andi Kleen <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 29dc267 commit bc1e5d6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

tools/perf/ui/browsers/annotate.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ static int annotate_browser__set_jumps_percent_color(struct annotate_browser *br
110110

111111
static int annotate_browser__pcnt_width(struct annotate_browser *ab)
112112
{
113-
int w = 7 * ab->nr_events;
113+
return 7 * ab->nr_events;
114+
}
114115

115-
if (ab->have_cycles)
116-
w += IPC_WIDTH + CYCLES_WIDTH;
117-
return w;
116+
static int annotate_browser__cycles_width(struct annotate_browser *ab)
117+
{
118+
return ab->have_cycles ? IPC_WIDTH + CYCLES_WIDTH : 0;
118119
}
119120

120121
static void annotate_browser__write(struct ui_browser *browser, void *entry, int row)
@@ -127,7 +128,8 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
127128
(!current_entry || (browser->use_navkeypressed &&
128129
!browser->navkeypressed)));
129130
int width = browser->width, printed;
130-
int i, pcnt_width = annotate_browser__pcnt_width(ab);
131+
int i, pcnt_width = annotate_browser__pcnt_width(ab),
132+
cycles_width = annotate_browser__cycles_width(ab);
131133
double percent_max = 0.0;
132134
char bf[256];
133135
bool show_title = false;
@@ -162,7 +164,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
162164
ui_browser__set_percent_color(browser, 0, current_entry);
163165

164166
if (!show_title)
165-
ui_browser__write_nstring(browser, " ", 7 * ab->nr_events);
167+
ui_browser__write_nstring(browser, " ", pcnt_width);
166168
else
167169
ui_browser__printf(browser, "%*s", 7, "Percent");
168170
}
@@ -190,7 +192,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
190192
width += 1;
191193

192194
if (!*dl->line)
193-
ui_browser__write_nstring(browser, " ", width - pcnt_width);
195+
ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width);
194196
else if (dl->offset == -1) {
195197
if (dl->line_nr && annotate_browser__opts.show_linenr)
196198
printed = scnprintf(bf, sizeof(bf), "%-*d ",
@@ -199,7 +201,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
199201
printed = scnprintf(bf, sizeof(bf), "%*s ",
200202
ab->addr_width, " ");
201203
ui_browser__write_nstring(browser, bf, printed);
202-
ui_browser__write_nstring(browser, dl->line, width - printed - pcnt_width + 1);
204+
ui_browser__write_nstring(browser, dl->line, width - printed - pcnt_width - cycles_width + 1);
203205
} else {
204206
u64 addr = dl->offset;
205207
int color = -1;
@@ -256,7 +258,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
256258
}
257259

258260
disasm_line__scnprintf(dl, bf, sizeof(bf), !annotate_browser__opts.use_offset);
259-
ui_browser__write_nstring(browser, bf, width - pcnt_width - 3 - printed);
261+
ui_browser__write_nstring(browser, bf, width - pcnt_width - cycles_width - 3 - printed);
260262
}
261263

262264
if (current_entry)

0 commit comments

Comments
 (0)