aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui/hist.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@redhat.com>2012-10-04 08:49:37 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-10-04 12:28:49 -0400
commit5395a04841fcdd9220177f2c21353fe6d4cd0729 (patch)
tree5a382c4664dcda284c3aa963eca28148b419cb41 /tools/perf/ui/hist.c
parentdd464345f330c1103f93daad309e8b44845e96cf (diff)
perf hists: Separate overhead and baseline columns
Currently the overhead and baseline columns are handled within single function and the distinction is made by 'baseline hists' pointer passed by 'struct perf_hpp::ptr'. Since hists pointer is now part of each hist_entry, it's possible to locate paired hists pointer directly from the passed struct hist_entry pointer. Also separating those 2 columns makes the code more obvious. Signed-off-by: Jiri Olsa <jolsa@redhat.com> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Ingo Molnar <mingo@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1349354994-17853-4-git-send-email-namhyung@kernel.org Signed-off-by: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/ui/hist.c')
-rw-r--r--tools/perf/ui/hist.c74
1 files changed, 48 insertions, 26 deletions
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index 55b9ca8f084c..532a60177c32 100644
--- a/tools/perf/ui/hist.c
+++ b/tools/perf/ui/hist.c
@@ -8,9 +8,7 @@
8/* hist period print (hpp) functions */ 8/* hist period print (hpp) functions */
9static int hpp__header_overhead(struct perf_hpp *hpp) 9static int hpp__header_overhead(struct perf_hpp *hpp)
10{ 10{
11 const char *fmt = hpp->ptr ? "Baseline" : "Overhead"; 11 return scnprintf(hpp->buf, hpp->size, "Overhead");
12
13 return scnprintf(hpp->buf, hpp->size, fmt);
14} 12}
15 13
16static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused) 14static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused)
@@ -22,17 +20,6 @@ static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he)
22{ 20{
23 double percent = 100.0 * he->period / hpp->total_period; 21 double percent = 100.0 * he->period / hpp->total_period;
24 22
25 if (hpp->ptr) {
26 struct hists *old_hists = hpp->ptr;
27 u64 total_period = old_hists->stats.total_period;
28 u64 base_period = he->pair ? he->pair->period : 0;
29
30 if (total_period)
31 percent = 100.0 * base_period / total_period;
32 else
33 percent = 0.0;
34 }
35
36 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); 23 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);
37} 24}
38 25
@@ -41,17 +28,6 @@ static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he)
41 double percent = 100.0 * he->period / hpp->total_period; 28 double percent = 100.0 * he->period / hpp->total_period;
42 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; 29 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%";
43 30
44 if (hpp->ptr) {
45 struct hists *old_hists = hpp->ptr;
46 u64 total_period = old_hists->stats.total_period;
47 u64 base_period = he->pair ? he->pair->period : 0;
48
49 if (total_period)
50 percent = 100.0 * base_period / total_period;
51 else
52 percent = 0.0;
53 }
54
55 return scnprintf(hpp->buf, hpp->size, fmt, percent); 31 return scnprintf(hpp->buf, hpp->size, fmt, percent);
56} 32}
57 33
@@ -159,6 +135,47 @@ static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp,
159 return scnprintf(hpp->buf, hpp->size, fmt, percent); 135 return scnprintf(hpp->buf, hpp->size, fmt, percent);
160} 136}
161 137
138static int hpp__header_baseline(struct perf_hpp *hpp)
139{
140 return scnprintf(hpp->buf, hpp->size, "Baseline");
141}
142
143static int hpp__width_baseline(struct perf_hpp *hpp __maybe_unused)
144{
145 return 8;
146}
147
148static double baseline_percent(struct hist_entry *he)
149{
150 struct hist_entry *pair = he->pair;
151 struct hists *pair_hists = pair ? pair->hists : NULL;
152 double percent = 0.0;
153
154 if (pair) {
155 u64 total_period = pair_hists->stats.total_period;
156 u64 base_period = pair->period;
157
158 percent = 100.0 * base_period / total_period;
159 }
160
161 return percent;
162}
163
164static int hpp__color_baseline(struct perf_hpp *hpp, struct hist_entry *he)
165{
166 double percent = baseline_percent(he);
167
168 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);
169}
170
171static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he)
172{
173 double percent = baseline_percent(he);
174 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%";
175
176 return scnprintf(hpp->buf, hpp->size, fmt, percent);
177}
178
162static int hpp__header_samples(struct perf_hpp *hpp) 179static int hpp__header_samples(struct perf_hpp *hpp)
163{ 180{
164 const char *fmt = symbol_conf.field_sep ? "%s" : "%11s"; 181 const char *fmt = symbol_conf.field_sep ? "%s" : "%11s";
@@ -269,6 +286,7 @@ static int hpp__entry_displ(struct perf_hpp *hpp,
269 .entry = hpp__entry_ ## _name 286 .entry = hpp__entry_ ## _name
270 287
271struct perf_hpp_fmt perf_hpp__format[] = { 288struct perf_hpp_fmt perf_hpp__format[] = {
289 { .cond = false, HPP__COLOR_PRINT_FNS(baseline) },
272 { .cond = true, HPP__COLOR_PRINT_FNS(overhead) }, 290 { .cond = true, HPP__COLOR_PRINT_FNS(overhead) },
273 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_sys) }, 291 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_sys) },
274 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_us) }, 292 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_us) },
@@ -302,6 +320,8 @@ void perf_hpp__init(bool need_pair, bool show_displacement)
302 perf_hpp__format[PERF_HPP__PERIOD].cond = true; 320 perf_hpp__format[PERF_HPP__PERIOD].cond = true;
303 321
304 if (need_pair) { 322 if (need_pair) {
323 perf_hpp__format[PERF_HPP__OVERHEAD].cond = false;
324 perf_hpp__format[PERF_HPP__BASELINE].cond = true;
305 perf_hpp__format[PERF_HPP__DELTA].cond = true; 325 perf_hpp__format[PERF_HPP__DELTA].cond = true;
306 326
307 if (show_displacement) 327 if (show_displacement)
@@ -321,6 +341,7 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
321 const char *sep = symbol_conf.field_sep; 341 const char *sep = symbol_conf.field_sep;
322 char *start = hpp->buf; 342 char *start = hpp->buf;
323 int i, ret; 343 int i, ret;
344 bool first = true;
324 345
325 if (symbol_conf.exclude_other && !he->parent) 346 if (symbol_conf.exclude_other && !he->parent)
326 return 0; 347 return 0;
@@ -329,9 +350,10 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
329 if (!perf_hpp__format[i].cond) 350 if (!perf_hpp__format[i].cond)
330 continue; 351 continue;
331 352
332 if (!sep || i > 0) { 353 if (!sep || !first) {
333 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " "); 354 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
334 advance_hpp(hpp, ret); 355 advance_hpp(hpp, ret);
356 first = false;
335 } 357 }
336 358
337 if (color && perf_hpp__format[i].color) 359 if (color && perf_hpp__format[i].color)