aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui/browsers/annotate.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-07-27 11:05:58 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-07-28 11:53:07 -0400
commitbc1e5d60cebb711ca3783a87a969d18db376d357 (patch)
tree2d0b19b14ce107efef214858f282089d57e9cf5c /tools/perf/ui/browsers/annotate.c
parent29dc267f270a4ad5ae1341e7fdc8539ac7dc907a (diff)
perf annotate TUI: Clarify calculation of column header widths
In commit f8f4aaead579 ("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 <treeze.taeung@gmail.com> Cc: Milian Wolff <milian.wolff@kdab.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Andi Kleen <ak@linux.intel.com> Link: http://lkml.kernel.org/n/tip-szgb07t4k5wtvks8nzwkg710@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui/browsers/annotate.c')
-rw-r--r--tools/perf/ui/browsers/annotate.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index c382b1d8af42..0f4bcc0d140c 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -110,11 +110,12 @@ static int annotate_browser__set_jumps_percent_color(struct annotate_browser *br
110 110
111static int annotate_browser__pcnt_width(struct annotate_browser *ab) 111static int annotate_browser__pcnt_width(struct annotate_browser *ab)
112{ 112{
113 int w = 7 * ab->nr_events; 113 return 7 * ab->nr_events;
114}
114 115
115 if (ab->have_cycles) 116static int annotate_browser__cycles_width(struct annotate_browser *ab)
116 w += IPC_WIDTH + CYCLES_WIDTH; 117{
117 return w; 118 return ab->have_cycles ? IPC_WIDTH + CYCLES_WIDTH : 0;
118} 119}
119 120
120static void annotate_browser__write(struct ui_browser *browser, void *entry, int row) 121static 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
127 (!current_entry || (browser->use_navkeypressed && 128 (!current_entry || (browser->use_navkeypressed &&
128 !browser->navkeypressed))); 129 !browser->navkeypressed)));
129 int width = browser->width, printed; 130 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);
131 double percent_max = 0.0; 133 double percent_max = 0.0;
132 char bf[256]; 134 char bf[256];
133 bool show_title = false; 135 bool show_title = false;
@@ -162,7 +164,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
162 ui_browser__set_percent_color(browser, 0, current_entry); 164 ui_browser__set_percent_color(browser, 0, current_entry);
163 165
164 if (!show_title) 166 if (!show_title)
165 ui_browser__write_nstring(browser, " ", 7 * ab->nr_events); 167 ui_browser__write_nstring(browser, " ", pcnt_width);
166 else 168 else
167 ui_browser__printf(browser, "%*s", 7, "Percent"); 169 ui_browser__printf(browser, "%*s", 7, "Percent");
168 } 170 }
@@ -190,7 +192,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
190 width += 1; 192 width += 1;
191 193
192 if (!*dl->line) 194 if (!*dl->line)
193 ui_browser__write_nstring(browser, " ", width - pcnt_width); 195 ui_browser__write_nstring(browser, " ", width - pcnt_width - cycles_width);
194 else if (dl->offset == -1) { 196 else if (dl->offset == -1) {
195 if (dl->line_nr && annotate_browser__opts.show_linenr) 197 if (dl->line_nr && annotate_browser__opts.show_linenr)
196 printed = scnprintf(bf, sizeof(bf), "%-*d ", 198 printed = scnprintf(bf, sizeof(bf), "%-*d ",
@@ -199,7 +201,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
199 printed = scnprintf(bf, sizeof(bf), "%*s ", 201 printed = scnprintf(bf, sizeof(bf), "%*s ",
200 ab->addr_width, " "); 202 ab->addr_width, " ");
201 ui_browser__write_nstring(browser, bf, printed); 203 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);
203 } else { 205 } else {
204 u64 addr = dl->offset; 206 u64 addr = dl->offset;
205 int color = -1; 207 int color = -1;
@@ -256,7 +258,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
256 } 258 }
257 259
258 disasm_line__scnprintf(dl, bf, sizeof(bf), !annotate_browser__opts.use_offset); 260 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);
260 } 262 }
261 263
262 if (current_entry) 264 if (current_entry)