aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/ui
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/ui')
-rw-r--r--tools/perf/ui/browsers/hists.c12
-rw-r--r--tools/perf/ui/gtk/browser.c6
-rw-r--r--tools/perf/ui/gtk/util.c2
-rw-r--r--tools/perf/ui/helpline.h18
-rw-r--r--tools/perf/ui/hist.c145
-rw-r--r--tools/perf/ui/setup.c2
-rw-r--r--tools/perf/ui/stdio/hist.c45
7 files changed, 127 insertions, 103 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index a21f40bebbac..0568536ecf67 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -569,7 +569,8 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
569static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \ 569static int hist_browser__hpp_color_ ## _name(struct perf_hpp *hpp, \
570 struct hist_entry *he) \ 570 struct hist_entry *he) \
571{ \ 571{ \
572 double percent = 100.0 * he->_field / hpp->total_period; \ 572 struct hists *hists = he->hists; \
573 double percent = 100.0 * he->stat._field / hists->stats.total_period; \
573 *(double *)hpp->ptr = percent; \ 574 *(double *)hpp->ptr = percent; \
574 return scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent); \ 575 return scnprintf(hpp->buf, hpp->size, "%6.2f%%", percent); \
575} 576}
@@ -584,7 +585,7 @@ HPP__COLOR_FN(overhead_guest_us, period_guest_us)
584 585
585void hist_browser__init_hpp(void) 586void hist_browser__init_hpp(void)
586{ 587{
587 perf_hpp__init(false, false); 588 perf_hpp__init();
588 589
589 perf_hpp__format[PERF_HPP__OVERHEAD].color = 590 perf_hpp__format[PERF_HPP__OVERHEAD].color =
590 hist_browser__hpp_color_overhead; 591 hist_browser__hpp_color_overhead;
@@ -624,7 +625,6 @@ static int hist_browser__show_entry(struct hist_browser *browser,
624 struct perf_hpp hpp = { 625 struct perf_hpp hpp = {
625 .buf = s, 626 .buf = s,
626 .size = sizeof(s), 627 .size = sizeof(s),
627 .total_period = browser->hists->stats.total_period,
628 }; 628 };
629 629
630 ui_browser__gotorc(&browser->b, row, 0); 630 ui_browser__gotorc(&browser->b, row, 0);
@@ -982,7 +982,7 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser,
982 folded_sign = hist_entry__folded(he); 982 folded_sign = hist_entry__folded(he);
983 983
984 hist_entry__sort_snprintf(he, s, sizeof(s), browser->hists); 984 hist_entry__sort_snprintf(he, s, sizeof(s), browser->hists);
985 percent = (he->period * 100.0) / browser->hists->stats.total_period; 985 percent = (he->stat.period * 100.0) / browser->hists->stats.total_period;
986 986
987 if (symbol_conf.use_callchain) 987 if (symbol_conf.use_callchain)
988 printed += fprintf(fp, "%c ", folded_sign); 988 printed += fprintf(fp, "%c ", folded_sign);
@@ -990,10 +990,10 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser,
990 printed += fprintf(fp, " %5.2f%%", percent); 990 printed += fprintf(fp, " %5.2f%%", percent);
991 991
992 if (symbol_conf.show_nr_samples) 992 if (symbol_conf.show_nr_samples)
993 printed += fprintf(fp, " %11u", he->nr_events); 993 printed += fprintf(fp, " %11u", he->stat.nr_events);
994 994
995 if (symbol_conf.show_total_period) 995 if (symbol_conf.show_total_period)
996 printed += fprintf(fp, " %12" PRIu64, he->period); 996 printed += fprintf(fp, " %12" PRIu64, he->stat.period);
997 997
998 printed += fprintf(fp, "%s\n", rtrim(s)); 998 printed += fprintf(fp, "%s\n", rtrim(s));
999 999
diff --git a/tools/perf/ui/gtk/browser.c b/tools/perf/ui/gtk/browser.c
index 7ff99ec1d95e..4125c6284114 100644
--- a/tools/perf/ui/gtk/browser.c
+++ b/tools/perf/ui/gtk/browser.c
@@ -49,7 +49,8 @@ static const char *perf_gtk__get_percent_color(double percent)
49static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \ 49static int perf_gtk__hpp_color_ ## _name(struct perf_hpp *hpp, \
50 struct hist_entry *he) \ 50 struct hist_entry *he) \
51{ \ 51{ \
52 double percent = 100.0 * he->_field / hpp->total_period; \ 52 struct hists *hists = he->hists; \
53 double percent = 100.0 * he->stat._field / hists->stats.total_period; \
53 const char *markup; \ 54 const char *markup; \
54 int ret = 0; \ 55 int ret = 0; \
55 \ 56 \
@@ -73,7 +74,7 @@ HPP__COLOR_FN(overhead_guest_us, period_guest_us)
73 74
74void perf_gtk__init_hpp(void) 75void perf_gtk__init_hpp(void)
75{ 76{
76 perf_hpp__init(false, false); 77 perf_hpp__init();
77 78
78 perf_hpp__format[PERF_HPP__OVERHEAD].color = 79 perf_hpp__format[PERF_HPP__OVERHEAD].color =
79 perf_gtk__hpp_color_overhead; 80 perf_gtk__hpp_color_overhead;
@@ -102,7 +103,6 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists)
102 struct perf_hpp hpp = { 103 struct perf_hpp hpp = {
103 .buf = s, 104 .buf = s,
104 .size = sizeof(s), 105 .size = sizeof(s),
105 .total_period = hists->stats.total_period,
106 }; 106 };
107 107
108 nr_cols = 0; 108 nr_cols = 0;
diff --git a/tools/perf/ui/gtk/util.c b/tools/perf/ui/gtk/util.c
index 8aada5b3c04c..ccb046aac98b 100644
--- a/tools/perf/ui/gtk/util.c
+++ b/tools/perf/ui/gtk/util.c
@@ -116,7 +116,7 @@ struct perf_error_ops perf_gtk_eops = {
116 * FIXME: Functions below should be implemented properly. 116 * FIXME: Functions below should be implemented properly.
117 * For now, just add stubs for NO_NEWT=1 build. 117 * For now, just add stubs for NO_NEWT=1 build.
118 */ 118 */
119#ifdef NO_NEWT_SUPPORT 119#ifndef NEWT_SUPPORT
120void ui_progress__update(u64 curr __maybe_unused, u64 total __maybe_unused, 120void ui_progress__update(u64 curr __maybe_unused, u64 total __maybe_unused,
121 const char *title __maybe_unused) 121 const char *title __maybe_unused)
122{ 122{
diff --git a/tools/perf/ui/helpline.h b/tools/perf/ui/helpline.h
index 2b667ee454c3..baa28a4d16b9 100644
--- a/tools/perf/ui/helpline.h
+++ b/tools/perf/ui/helpline.h
@@ -23,25 +23,25 @@ void ui_helpline__puts(const char *msg);
23 23
24extern char ui_helpline__current[512]; 24extern char ui_helpline__current[512];
25 25
26#ifdef NO_NEWT_SUPPORT 26#ifdef NEWT_SUPPORT
27extern char ui_helpline__last_msg[];
28int ui_helpline__show_help(const char *format, va_list ap);
29#else
27static inline int ui_helpline__show_help(const char *format __maybe_unused, 30static inline int ui_helpline__show_help(const char *format __maybe_unused,
28 va_list ap __maybe_unused) 31 va_list ap __maybe_unused)
29{ 32{
30 return 0; 33 return 0;
31} 34}
32#else 35#endif /* NEWT_SUPPORT */
33extern char ui_helpline__last_msg[];
34int ui_helpline__show_help(const char *format, va_list ap);
35#endif /* NO_NEWT_SUPPORT */
36 36
37#ifdef NO_GTK2_SUPPORT 37#ifdef GTK2_SUPPORT
38int perf_gtk__show_helpline(const char *format, va_list ap);
39#else
38static inline int perf_gtk__show_helpline(const char *format __maybe_unused, 40static inline int perf_gtk__show_helpline(const char *format __maybe_unused,
39 va_list ap __maybe_unused) 41 va_list ap __maybe_unused)
40{ 42{
41 return 0; 43 return 0;
42} 44}
43#else 45#endif /* GTK2_SUPPORT */
44int perf_gtk__show_helpline(const char *format, va_list ap);
45#endif /* NO_GTK2_SUPPORT */
46 46
47#endif /* _PERF_UI_HELPLINE_H_ */ 47#endif /* _PERF_UI_HELPLINE_H_ */
diff --git a/tools/perf/ui/hist.c b/tools/perf/ui/hist.c
index e3f8cd46e7d7..f5a1e4f65263 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)
@@ -20,38 +18,18 @@ static int hpp__width_overhead(struct perf_hpp *hpp __maybe_unused)
20 18
21static int hpp__color_overhead(struct perf_hpp *hpp, struct hist_entry *he) 19static 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 struct hists *hists = he->hists;
24 22 double percent = 100.0 * he->stat.period / hists->stats.total_period;
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 23
36 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent); 24 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);
37} 25}
38 26
39static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he) 27static int hpp__entry_overhead(struct perf_hpp *hpp, struct hist_entry *he)
40{ 28{
41 double percent = 100.0 * he->period / hpp->total_period; 29 struct hists *hists = he->hists;
30 double percent = 100.0 * he->stat.period / hists->stats.total_period;
42 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%"; 31 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%";
43 32
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); 33 return scnprintf(hpp->buf, hpp->size, fmt, percent);
56} 34}
57 35
@@ -69,13 +47,16 @@ static int hpp__width_overhead_sys(struct perf_hpp *hpp __maybe_unused)
69 47
70static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) 48static int hpp__color_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
71{ 49{
72 double percent = 100.0 * he->period_sys / hpp->total_period; 50 struct hists *hists = he->hists;
51 double percent = 100.0 * he->stat.period_sys / hists->stats.total_period;
52
73 return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); 53 return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
74} 54}
75 55
76static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he) 56static int hpp__entry_overhead_sys(struct perf_hpp *hpp, struct hist_entry *he)
77{ 57{
78 double percent = 100.0 * he->period_sys / hpp->total_period; 58 struct hists *hists = he->hists;
59 double percent = 100.0 * he->stat.period_sys / hists->stats.total_period;
79 const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; 60 const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%";
80 61
81 return scnprintf(hpp->buf, hpp->size, fmt, percent); 62 return scnprintf(hpp->buf, hpp->size, fmt, percent);
@@ -95,13 +76,16 @@ static int hpp__width_overhead_us(struct perf_hpp *hpp __maybe_unused)
95 76
96static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) 77static int hpp__color_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
97{ 78{
98 double percent = 100.0 * he->period_us / hpp->total_period; 79 struct hists *hists = he->hists;
80 double percent = 100.0 * he->stat.period_us / hists->stats.total_period;
81
99 return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent); 82 return percent_color_snprintf(hpp->buf, hpp->size, "%6.2f%%", percent);
100} 83}
101 84
102static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he) 85static int hpp__entry_overhead_us(struct perf_hpp *hpp, struct hist_entry *he)
103{ 86{
104 double percent = 100.0 * he->period_us / hpp->total_period; 87 struct hists *hists = he->hists;
88 double percent = 100.0 * he->stat.period_us / hists->stats.total_period;
105 const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%"; 89 const char *fmt = symbol_conf.field_sep ? "%.2f" : "%6.2f%%";
106 90
107 return scnprintf(hpp->buf, hpp->size, fmt, percent); 91 return scnprintf(hpp->buf, hpp->size, fmt, percent);
@@ -120,14 +104,17 @@ static int hpp__width_overhead_guest_sys(struct perf_hpp *hpp __maybe_unused)
120static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp, 104static int hpp__color_overhead_guest_sys(struct perf_hpp *hpp,
121 struct hist_entry *he) 105 struct hist_entry *he)
122{ 106{
123 double percent = 100.0 * he->period_guest_sys / hpp->total_period; 107 struct hists *hists = he->hists;
108 double percent = 100.0 * he->stat.period_guest_sys / hists->stats.total_period;
109
124 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); 110 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent);
125} 111}
126 112
127static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp, 113static int hpp__entry_overhead_guest_sys(struct perf_hpp *hpp,
128 struct hist_entry *he) 114 struct hist_entry *he)
129{ 115{
130 double percent = 100.0 * he->period_guest_sys / hpp->total_period; 116 struct hists *hists = he->hists;
117 double percent = 100.0 * he->stat.period_guest_sys / hists->stats.total_period;
131 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; 118 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% ";
132 119
133 return scnprintf(hpp->buf, hpp->size, fmt, percent); 120 return scnprintf(hpp->buf, hpp->size, fmt, percent);
@@ -146,19 +133,63 @@ static int hpp__width_overhead_guest_us(struct perf_hpp *hpp __maybe_unused)
146static int hpp__color_overhead_guest_us(struct perf_hpp *hpp, 133static int hpp__color_overhead_guest_us(struct perf_hpp *hpp,
147 struct hist_entry *he) 134 struct hist_entry *he)
148{ 135{
149 double percent = 100.0 * he->period_guest_us / hpp->total_period; 136 struct hists *hists = he->hists;
137 double percent = 100.0 * he->stat.period_guest_us / hists->stats.total_period;
138
150 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent); 139 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%% ", percent);
151} 140}
152 141
153static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp, 142static int hpp__entry_overhead_guest_us(struct perf_hpp *hpp,
154 struct hist_entry *he) 143 struct hist_entry *he)
155{ 144{
156 double percent = 100.0 * he->period_guest_us / hpp->total_period; 145 struct hists *hists = he->hists;
146 double percent = 100.0 * he->stat.period_guest_us / hists->stats.total_period;
157 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% "; 147 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%% ";
158 148
159 return scnprintf(hpp->buf, hpp->size, fmt, percent); 149 return scnprintf(hpp->buf, hpp->size, fmt, percent);
160} 150}
161 151
152static int hpp__header_baseline(struct perf_hpp *hpp)
153{
154 return scnprintf(hpp->buf, hpp->size, "Baseline");
155}
156
157static int hpp__width_baseline(struct perf_hpp *hpp __maybe_unused)
158{
159 return 8;
160}
161
162static double baseline_percent(struct hist_entry *he)
163{
164 struct hist_entry *pair = he->pair;
165 struct hists *pair_hists = pair ? pair->hists : NULL;
166 double percent = 0.0;
167
168 if (pair) {
169 u64 total_period = pair_hists->stats.total_period;
170 u64 base_period = pair->stat.period;
171
172 percent = 100.0 * base_period / total_period;
173 }
174
175 return percent;
176}
177
178static int hpp__color_baseline(struct perf_hpp *hpp, struct hist_entry *he)
179{
180 double percent = baseline_percent(he);
181
182 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);
183}
184
185static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he)
186{
187 double percent = baseline_percent(he);
188 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%";
189
190 return scnprintf(hpp->buf, hpp->size, fmt, percent);
191}
192
162static int hpp__header_samples(struct perf_hpp *hpp) 193static int hpp__header_samples(struct perf_hpp *hpp)
163{ 194{
164 const char *fmt = symbol_conf.field_sep ? "%s" : "%11s"; 195 const char *fmt = symbol_conf.field_sep ? "%s" : "%11s";
@@ -175,7 +206,7 @@ static int hpp__entry_samples(struct perf_hpp *hpp, struct hist_entry *he)
175{ 206{
176 const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%11" PRIu64; 207 const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%11" PRIu64;
177 208
178 return scnprintf(hpp->buf, hpp->size, fmt, he->nr_events); 209 return scnprintf(hpp->buf, hpp->size, fmt, he->stat.nr_events);
179} 210}
180 211
181static int hpp__header_period(struct perf_hpp *hpp) 212static int hpp__header_period(struct perf_hpp *hpp)
@@ -194,7 +225,7 @@ static int hpp__entry_period(struct perf_hpp *hpp, struct hist_entry *he)
194{ 225{
195 const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64; 226 const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64;
196 227
197 return scnprintf(hpp->buf, hpp->size, fmt, he->period); 228 return scnprintf(hpp->buf, hpp->size, fmt, he->stat.period);
198} 229}
199 230
200static int hpp__header_delta(struct perf_hpp *hpp) 231static int hpp__header_delta(struct perf_hpp *hpp)
@@ -211,20 +242,22 @@ static int hpp__width_delta(struct perf_hpp *hpp __maybe_unused)
211 242
212static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he) 243static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he)
213{ 244{
214 struct hists *pair_hists = hpp->ptr; 245 struct hist_entry *pair = he->pair;
246 struct hists *pair_hists = pair ? pair->hists : NULL;
247 struct hists *hists = he->hists;
215 u64 old_total, new_total; 248 u64 old_total, new_total;
216 double old_percent = 0, new_percent = 0; 249 double old_percent = 0, new_percent = 0;
217 double diff; 250 double diff;
218 const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s"; 251 const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s";
219 char buf[32] = " "; 252 char buf[32] = " ";
220 253
221 old_total = pair_hists->stats.total_period; 254 old_total = pair_hists ? pair_hists->stats.total_period : 0;
222 if (old_total > 0 && he->pair) 255 if (old_total > 0 && pair)
223 old_percent = 100.0 * he->pair->period / old_total; 256 old_percent = 100.0 * pair->stat.period / old_total;
224 257
225 new_total = hpp->total_period; 258 new_total = hists->stats.total_period;
226 if (new_total > 0) 259 if (new_total > 0)
227 new_percent = 100.0 * he->period / new_total; 260 new_percent = 100.0 * he->stat.period / new_total;
228 261
229 diff = new_percent - old_percent; 262 diff = new_percent - old_percent;
230 if (fabs(diff) >= 0.01) 263 if (fabs(diff) >= 0.01)
@@ -244,13 +277,15 @@ static int hpp__width_displ(struct perf_hpp *hpp __maybe_unused)
244} 277}
245 278
246static int hpp__entry_displ(struct perf_hpp *hpp, 279static int hpp__entry_displ(struct perf_hpp *hpp,
247 struct hist_entry *he __maybe_unused) 280 struct hist_entry *he)
248{ 281{
282 struct hist_entry *pair = he->pair;
283 long displacement = pair ? pair->position - he->position : 0;
249 const char *fmt = symbol_conf.field_sep ? "%s" : "%6.6s"; 284 const char *fmt = symbol_conf.field_sep ? "%s" : "%6.6s";
250 char buf[32] = " "; 285 char buf[32] = " ";
251 286
252 if (hpp->displacement) 287 if (displacement)
253 scnprintf(buf, sizeof(buf), "%+4ld", hpp->displacement); 288 scnprintf(buf, sizeof(buf), "%+4ld", displacement);
254 289
255 return scnprintf(hpp->buf, hpp->size, fmt, buf); 290 return scnprintf(hpp->buf, hpp->size, fmt, buf);
256} 291}
@@ -267,6 +302,7 @@ static int hpp__entry_displ(struct perf_hpp *hpp,
267 .entry = hpp__entry_ ## _name 302 .entry = hpp__entry_ ## _name
268 303
269struct perf_hpp_fmt perf_hpp__format[] = { 304struct perf_hpp_fmt perf_hpp__format[] = {
305 { .cond = false, HPP__COLOR_PRINT_FNS(baseline) },
270 { .cond = true, HPP__COLOR_PRINT_FNS(overhead) }, 306 { .cond = true, HPP__COLOR_PRINT_FNS(overhead) },
271 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_sys) }, 307 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_sys) },
272 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_us) }, 308 { .cond = false, HPP__COLOR_PRINT_FNS(overhead_us) },
@@ -281,7 +317,7 @@ struct perf_hpp_fmt perf_hpp__format[] = {
281#undef HPP__COLOR_PRINT_FNS 317#undef HPP__COLOR_PRINT_FNS
282#undef HPP__PRINT_FNS 318#undef HPP__PRINT_FNS
283 319
284void perf_hpp__init(bool need_pair, bool show_displacement) 320void perf_hpp__init(void)
285{ 321{
286 if (symbol_conf.show_cpu_utilization) { 322 if (symbol_conf.show_cpu_utilization) {
287 perf_hpp__format[PERF_HPP__OVERHEAD_SYS].cond = true; 323 perf_hpp__format[PERF_HPP__OVERHEAD_SYS].cond = true;
@@ -298,13 +334,12 @@ void perf_hpp__init(bool need_pair, bool show_displacement)
298 334
299 if (symbol_conf.show_total_period) 335 if (symbol_conf.show_total_period)
300 perf_hpp__format[PERF_HPP__PERIOD].cond = true; 336 perf_hpp__format[PERF_HPP__PERIOD].cond = true;
337}
301 338
302 if (need_pair) { 339void perf_hpp__column_enable(unsigned col, bool enable)
303 perf_hpp__format[PERF_HPP__DELTA].cond = true; 340{
304 341 BUG_ON(col >= PERF_HPP__MAX_INDEX);
305 if (show_displacement) 342 perf_hpp__format[col].cond = enable;
306 perf_hpp__format[PERF_HPP__DISPL].cond = true;
307 }
308} 343}
309 344
310static inline void advance_hpp(struct perf_hpp *hpp, int inc) 345static inline void advance_hpp(struct perf_hpp *hpp, int inc)
@@ -319,6 +354,7 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
319 const char *sep = symbol_conf.field_sep; 354 const char *sep = symbol_conf.field_sep;
320 char *start = hpp->buf; 355 char *start = hpp->buf;
321 int i, ret; 356 int i, ret;
357 bool first = true;
322 358
323 if (symbol_conf.exclude_other && !he->parent) 359 if (symbol_conf.exclude_other && !he->parent)
324 return 0; 360 return 0;
@@ -327,9 +363,10 @@ int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
327 if (!perf_hpp__format[i].cond) 363 if (!perf_hpp__format[i].cond)
328 continue; 364 continue;
329 365
330 if (!sep || i > 0) { 366 if (!sep || !first) {
331 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " "); 367 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
332 advance_hpp(hpp, ret); 368 advance_hpp(hpp, ret);
369 first = false;
333 } 370 }
334 371
335 if (color && perf_hpp__format[i].color) 372 if (color && perf_hpp__format[i].color)
diff --git a/tools/perf/ui/setup.c b/tools/perf/ui/setup.c
index bd7d460f844c..ebb4cc107876 100644
--- a/tools/perf/ui/setup.c
+++ b/tools/perf/ui/setup.c
@@ -30,7 +30,7 @@ void setup_browser(bool fallback_to_pager)
30 if (fallback_to_pager) 30 if (fallback_to_pager)
31 setup_pager(); 31 setup_pager();
32 32
33 perf_hpp__init(false, false); 33 perf_hpp__init();
34 break; 34 break;
35 } 35 }
36} 36}
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 882461a42830..fbd4e32d0743 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -271,7 +271,7 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
271{ 271{
272 switch (callchain_param.mode) { 272 switch (callchain_param.mode) {
273 case CHAIN_GRAPH_REL: 273 case CHAIN_GRAPH_REL:
274 return callchain__fprintf_graph(fp, &he->sorted_chain, he->period, 274 return callchain__fprintf_graph(fp, &he->sorted_chain, he->stat.period,
275 left_margin); 275 left_margin);
276 break; 276 break;
277 case CHAIN_GRAPH_ABS: 277 case CHAIN_GRAPH_ABS:
@@ -292,9 +292,10 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
292 292
293static size_t hist_entry__callchain_fprintf(struct hist_entry *he, 293static size_t hist_entry__callchain_fprintf(struct hist_entry *he,
294 struct hists *hists, 294 struct hists *hists,
295 u64 total_period, FILE *fp) 295 FILE *fp)
296{ 296{
297 int left_margin = 0; 297 int left_margin = 0;
298 u64 total_period = hists->stats.total_period;
298 299
299 if (sort__first_dimension == SORT_COMM) { 300 if (sort__first_dimension == SORT_COMM) {
300 struct sort_entry *se = list_first_entry(&hist_entry__sort_list, 301 struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
@@ -307,17 +308,13 @@ static size_t hist_entry__callchain_fprintf(struct hist_entry *he,
307} 308}
308 309
309static int hist_entry__fprintf(struct hist_entry *he, size_t size, 310static int hist_entry__fprintf(struct hist_entry *he, size_t size,
310 struct hists *hists, struct hists *pair_hists, 311 struct hists *hists, FILE *fp)
311 long displacement, u64 total_period, FILE *fp)
312{ 312{
313 char bf[512]; 313 char bf[512];
314 int ret; 314 int ret;
315 struct perf_hpp hpp = { 315 struct perf_hpp hpp = {
316 .buf = bf, 316 .buf = bf,
317 .size = size, 317 .size = size,
318 .total_period = total_period,
319 .displacement = displacement,
320 .ptr = pair_hists,
321 }; 318 };
322 bool color = !symbol_conf.field_sep; 319 bool color = !symbol_conf.field_sep;
323 320
@@ -330,22 +327,17 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
330 ret = fprintf(fp, "%s\n", bf); 327 ret = fprintf(fp, "%s\n", bf);
331 328
332 if (symbol_conf.use_callchain) 329 if (symbol_conf.use_callchain)
333 ret += hist_entry__callchain_fprintf(he, hists, 330 ret += hist_entry__callchain_fprintf(he, hists, fp);
334 total_period, fp);
335 331
336 return ret; 332 return ret;
337} 333}
338 334
339size_t hists__fprintf(struct hists *hists, struct hists *pair, 335size_t hists__fprintf(struct hists *hists, bool show_header, int max_rows,
340 bool show_displacement, bool show_header, int max_rows,
341 int max_cols, FILE *fp) 336 int max_cols, FILE *fp)
342{ 337{
343 struct sort_entry *se; 338 struct sort_entry *se;
344 struct rb_node *nd; 339 struct rb_node *nd;
345 size_t ret = 0; 340 size_t ret = 0;
346 u64 total_period;
347 unsigned long position = 1;
348 long displacement = 0;
349 unsigned int width; 341 unsigned int width;
350 const char *sep = symbol_conf.field_sep; 342 const char *sep = symbol_conf.field_sep;
351 const char *col_width = symbol_conf.col_width_list_str; 343 const char *col_width = symbol_conf.col_width_list_str;
@@ -354,8 +346,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
354 struct perf_hpp dummy_hpp = { 346 struct perf_hpp dummy_hpp = {
355 .buf = bf, 347 .buf = bf,
356 .size = sizeof(bf), 348 .size = sizeof(bf),
357 .ptr = pair,
358 }; 349 };
350 bool first = true;
359 351
360 init_rem_hits(); 352 init_rem_hits();
361 353
@@ -367,8 +359,10 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
367 if (!perf_hpp__format[idx].cond) 359 if (!perf_hpp__format[idx].cond)
368 continue; 360 continue;
369 361
370 if (idx) 362 if (!first)
371 fprintf(fp, "%s", sep ?: " "); 363 fprintf(fp, "%s", sep ?: " ");
364 else
365 first = false;
372 366
373 perf_hpp__format[idx].header(&dummy_hpp); 367 perf_hpp__format[idx].header(&dummy_hpp);
374 fprintf(fp, "%s", bf); 368 fprintf(fp, "%s", bf);
@@ -403,6 +397,8 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
403 if (sep) 397 if (sep)
404 goto print_entries; 398 goto print_entries;
405 399
400 first = true;
401
406 fprintf(fp, "# "); 402 fprintf(fp, "# ");
407 for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) { 403 for (idx = 0; idx < PERF_HPP__MAX_INDEX; idx++) {
408 unsigned int i; 404 unsigned int i;
@@ -410,8 +406,10 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
410 if (!perf_hpp__format[idx].cond) 406 if (!perf_hpp__format[idx].cond)
411 continue; 407 continue;
412 408
413 if (idx) 409 if (!first)
414 fprintf(fp, "%s", sep ?: " "); 410 fprintf(fp, "%s", sep ?: " ");
411 else
412 first = false;
415 413
416 width = perf_hpp__format[idx].width(&dummy_hpp); 414 width = perf_hpp__format[idx].width(&dummy_hpp);
417 for (i = 0; i < width; i++) 415 for (i = 0; i < width; i++)
@@ -441,24 +439,13 @@ size_t hists__fprintf(struct hists *hists, struct hists *pair,
441 goto out; 439 goto out;
442 440
443print_entries: 441print_entries:
444 total_period = hists->stats.total_period;
445
446 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { 442 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
447 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); 443 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
448 444
449 if (h->filtered) 445 if (h->filtered)
450 continue; 446 continue;
451 447
452 if (show_displacement) { 448 ret += hist_entry__fprintf(h, max_cols, hists, fp);
453 if (h->pair != NULL)
454 displacement = ((long)h->pair->position -
455 (long)position);
456 else
457 displacement = 0;
458 ++position;
459 }
460 ret += hist_entry__fprintf(h, max_cols, hists, pair, displacement,
461 total_period, fp);
462 449
463 if (max_rows && ++nr_rows >= max_rows) 450 if (max_rows && ++nr_rows >= max_rows)
464 goto out; 451 goto out;