blob: 5440d56d884ae1f92104b69c455a34e415fd5d33 [file] [log] [blame]
Namhyung Kimea251d52012-09-03 11:53:06 +09001#include <math.h>
Jiri Olsa2c5d4b42013-01-31 23:31:11 +01002#include <linux/compiler.h>
Namhyung Kimea251d52012-09-03 11:53:06 +09003
4#include "../util/hist.h"
5#include "../util/util.h"
6#include "../util/sort.h"
Namhyung Kim4fb71072013-01-22 18:09:34 +09007#include "../util/evsel.h"
Namhyung Kimea251d52012-09-03 11:53:06 +09008
9/* hist period print (hpp) functions */
Namhyung Kimea251d52012-09-03 11:53:06 +090010
Namhyung Kim4fb71072013-01-22 18:09:34 +090011typedef int (*hpp_snprint_fn)(char *buf, size_t size, const char *fmt, ...);
Namhyung Kimea251d52012-09-03 11:53:06 +090012
Jiri Olsa0c5268b2013-02-04 13:32:55 +010013static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
14 u64 (*get_field)(struct hist_entry *),
15 const char *fmt, hpp_snprint_fn print_fn,
16 bool fmt_percent)
Namhyung Kimea251d52012-09-03 11:53:06 +090017{
Namhyung Kim4fb71072013-01-22 18:09:34 +090018 int ret;
Jiri Olsab5ff71c2012-10-04 21:49:40 +090019 struct hists *hists = he->hists;
Namhyung Kim759ff492013-03-05 14:53:26 +090020 struct perf_evsel *evsel = hists_to_evsel(hists);
Namhyung Kimea251d52012-09-03 11:53:06 +090021
Jiri Olsa0c5268b2013-02-04 13:32:55 +010022 if (fmt_percent) {
23 double percent = 0.0;
Namhyung Kim4fb71072013-01-22 18:09:34 +090024
Jiri Olsa0c5268b2013-02-04 13:32:55 +010025 if (hists->stats.total_period)
26 percent = 100.0 * get_field(he) /
27 hists->stats.total_period;
28
29 ret = print_fn(hpp->buf, hpp->size, fmt, percent);
30 } else
31 ret = print_fn(hpp->buf, hpp->size, fmt, get_field(he));
Namhyung Kim5b9e2142013-01-22 18:09:37 +090032
Namhyung Kim759ff492013-03-05 14:53:26 +090033 if (perf_evsel__is_group_event(evsel)) {
Namhyung Kim5b9e2142013-01-22 18:09:37 +090034 int prev_idx, idx_delta;
Namhyung Kim5b9e2142013-01-22 18:09:37 +090035 struct hist_entry *pair;
36 int nr_members = evsel->nr_members;
37
Namhyung Kim5b9e2142013-01-22 18:09:37 +090038 prev_idx = perf_evsel__group_idx(evsel);
39
40 list_for_each_entry(pair, &he->pairs.head, pairs.node) {
41 u64 period = get_field(pair);
42 u64 total = pair->hists->stats.total_period;
43
44 if (!total)
45 continue;
46
47 evsel = hists_to_evsel(pair->hists);
48 idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1;
49
50 while (idx_delta--) {
51 /*
52 * zero-fill group members in the middle which
53 * have no sample
54 */
55 ret += print_fn(hpp->buf + ret, hpp->size - ret,
Jiri Olsa0c5268b2013-02-04 13:32:55 +010056 fmt, 0);
Namhyung Kim5b9e2142013-01-22 18:09:37 +090057 }
58
Jiri Olsa0c5268b2013-02-04 13:32:55 +010059 if (fmt_percent)
60 ret += print_fn(hpp->buf + ret, hpp->size - ret,
61 fmt, 100.0 * period / total);
62 else
63 ret += print_fn(hpp->buf + ret, hpp->size - ret,
64 fmt, period);
Namhyung Kim5b9e2142013-01-22 18:09:37 +090065
66 prev_idx = perf_evsel__group_idx(evsel);
67 }
68
69 idx_delta = nr_members - prev_idx - 1;
70
71 while (idx_delta--) {
72 /*
73 * zero-fill group members at last which have no sample
74 */
75 ret += print_fn(hpp->buf + ret, hpp->size - ret,
Jiri Olsa0c5268b2013-02-04 13:32:55 +010076 fmt, 0);
Namhyung Kim5b9e2142013-01-22 18:09:37 +090077 }
78 }
Namhyung Kim4fb71072013-01-22 18:09:34 +090079 return ret;
Namhyung Kimea251d52012-09-03 11:53:06 +090080}
81
Namhyung Kim4fb71072013-01-22 18:09:34 +090082#define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
Jiri Olsa2c5d4b42013-01-31 23:31:11 +010083static int hpp__header_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
84 struct perf_hpp *hpp) \
Namhyung Kim4fb71072013-01-22 18:09:34 +090085{ \
86 int len = _min_width; \
87 \
Namhyung Kim5b9e2142013-01-22 18:09:37 +090088 if (symbol_conf.event_group) { \
89 struct perf_evsel *evsel = hpp->ptr; \
90 \
91 len = max(len, evsel->nr_members * _unit_width); \
92 } \
Namhyung Kim4fb71072013-01-22 18:09:34 +090093 return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
Namhyung Kimea251d52012-09-03 11:53:06 +090094}
95
Namhyung Kim4fb71072013-01-22 18:09:34 +090096#define __HPP_WIDTH_FN(_type, _min_width, _unit_width) \
Jiri Olsa2c5d4b42013-01-31 23:31:11 +010097static int hpp__width_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
98 struct perf_hpp *hpp __maybe_unused) \
Namhyung Kim4fb71072013-01-22 18:09:34 +090099{ \
100 int len = _min_width; \
101 \
Namhyung Kim5b9e2142013-01-22 18:09:37 +0900102 if (symbol_conf.event_group) { \
103 struct perf_evsel *evsel = hpp->ptr; \
104 \
105 len = max(len, evsel->nr_members * _unit_width); \
106 } \
Namhyung Kim4fb71072013-01-22 18:09:34 +0900107 return len; \
Namhyung Kimea251d52012-09-03 11:53:06 +0900108}
109
Namhyung Kim4fb71072013-01-22 18:09:34 +0900110#define __HPP_COLOR_PERCENT_FN(_type, _field) \
111static u64 he_get_##_field(struct hist_entry *he) \
112{ \
113 return he->stat._field; \
114} \
115 \
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100116static int hpp__color_##_type(struct perf_hpp_fmt *fmt __maybe_unused, \
117 struct perf_hpp *hpp, struct hist_entry *he) \
Namhyung Kim4fb71072013-01-22 18:09:34 +0900118{ \
Jiri Olsa0c5268b2013-02-04 13:32:55 +0100119 return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \
120 (hpp_snprint_fn)percent_color_snprintf, true); \
Namhyung Kimea251d52012-09-03 11:53:06 +0900121}
122
Namhyung Kim4fb71072013-01-22 18:09:34 +0900123#define __HPP_ENTRY_PERCENT_FN(_type, _field) \
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100124static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
125 struct perf_hpp *hpp, struct hist_entry *he) \
Namhyung Kim4fb71072013-01-22 18:09:34 +0900126{ \
127 const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \
Jiri Olsa0c5268b2013-02-04 13:32:55 +0100128 return __hpp__fmt(hpp, he, he_get_##_field, fmt, \
129 scnprintf, true); \
Namhyung Kimea251d52012-09-03 11:53:06 +0900130}
131
Namhyung Kim4fb71072013-01-22 18:09:34 +0900132#define __HPP_ENTRY_RAW_FN(_type, _field) \
133static u64 he_get_raw_##_field(struct hist_entry *he) \
134{ \
135 return he->stat._field; \
136} \
137 \
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100138static int hpp__entry_##_type(struct perf_hpp_fmt *_fmt __maybe_unused, \
139 struct perf_hpp *hpp, struct hist_entry *he) \
Namhyung Kim4fb71072013-01-22 18:09:34 +0900140{ \
141 const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \
Jiri Olsa0c5268b2013-02-04 13:32:55 +0100142 return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, scnprintf, false); \
Namhyung Kimea251d52012-09-03 11:53:06 +0900143}
144
Namhyung Kim4fb71072013-01-22 18:09:34 +0900145#define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \
146__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
147__HPP_WIDTH_FN(_type, _min_width, _unit_width) \
148__HPP_COLOR_PERCENT_FN(_type, _field) \
149__HPP_ENTRY_PERCENT_FN(_type, _field)
Namhyung Kimea251d52012-09-03 11:53:06 +0900150
Namhyung Kim4fb71072013-01-22 18:09:34 +0900151#define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \
152__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
153__HPP_WIDTH_FN(_type, _min_width, _unit_width) \
154__HPP_ENTRY_RAW_FN(_type, _field)
Jiri Olsab5ff71c2012-10-04 21:49:40 +0900155
Namhyung Kimea251d52012-09-03 11:53:06 +0900156
Namhyung Kim4fb71072013-01-22 18:09:34 +0900157HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8)
158HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8)
159HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8)
160HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8)
161HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us, 9, 8)
Namhyung Kim9ffad982012-09-03 11:53:07 +0900162
Namhyung Kim4fb71072013-01-22 18:09:34 +0900163HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12)
164HPP_RAW_FNS(period, "Period", period, 12, 12)
Namhyung Kimea251d52012-09-03 11:53:06 +0900165
Namhyung Kimea251d52012-09-03 11:53:06 +0900166
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100167static int hpp__header_baseline(struct perf_hpp_fmt *fmt __maybe_unused,
168 struct perf_hpp *hpp)
Jiri Olsa5395a042012-10-04 21:49:37 +0900169{
170 return scnprintf(hpp->buf, hpp->size, "Baseline");
171}
172
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100173static int hpp__width_baseline(struct perf_hpp_fmt *fmt __maybe_unused,
174 struct perf_hpp *hpp __maybe_unused)
Jiri Olsa5395a042012-10-04 21:49:37 +0900175{
176 return 8;
177}
178
179static double baseline_percent(struct hist_entry *he)
180{
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200181 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa5395a042012-10-04 21:49:37 +0900182 struct hists *pair_hists = pair ? pair->hists : NULL;
183 double percent = 0.0;
184
185 if (pair) {
186 u64 total_period = pair_hists->stats.total_period;
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900187 u64 base_period = pair->stat.period;
Jiri Olsa5395a042012-10-04 21:49:37 +0900188
189 percent = 100.0 * base_period / total_period;
190 }
191
192 return percent;
193}
194
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100195static int hpp__color_baseline(struct perf_hpp_fmt *fmt __maybe_unused,
196 struct perf_hpp *hpp, struct hist_entry *he)
Jiri Olsa5395a042012-10-04 21:49:37 +0900197{
198 double percent = baseline_percent(he);
199
Namhyung Kim4fb71072013-01-22 18:09:34 +0900200 if (hist_entry__has_pairs(he) || symbol_conf.field_sep)
Jiri Olsa6e923492012-10-05 16:44:47 +0200201 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);
202 else
203 return scnprintf(hpp->buf, hpp->size, " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900204}
205
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100206static int hpp__entry_baseline(struct perf_hpp_fmt *_fmt __maybe_unused,
207 struct perf_hpp *hpp, struct hist_entry *he)
Jiri Olsa5395a042012-10-04 21:49:37 +0900208{
209 double percent = baseline_percent(he);
210 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%";
211
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200212 if (hist_entry__has_pairs(he) || symbol_conf.field_sep)
Jiri Olsa6e923492012-10-05 16:44:47 +0200213 return scnprintf(hpp->buf, hpp->size, fmt, percent);
214 else
215 return scnprintf(hpp->buf, hpp->size, " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900216}
217
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100218static int hpp__header_period_baseline(struct perf_hpp_fmt *_fmt __maybe_unused,
219 struct perf_hpp *hpp)
Jiri Olsa61949b22012-10-05 16:44:44 +0200220{
221 const char *fmt = symbol_conf.field_sep ? "%s" : "%12s";
222
223 return scnprintf(hpp->buf, hpp->size, fmt, "Period Base");
224}
225
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100226static int hpp__width_period_baseline(struct perf_hpp_fmt *fmt __maybe_unused,
227 struct perf_hpp *hpp __maybe_unused)
Jiri Olsa61949b22012-10-05 16:44:44 +0200228{
229 return 12;
230}
231
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100232static int hpp__entry_period_baseline(struct perf_hpp_fmt *_fmt __maybe_unused,
233 struct perf_hpp *hpp, struct hist_entry *he)
Jiri Olsa61949b22012-10-05 16:44:44 +0200234{
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200235 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa61949b22012-10-05 16:44:44 +0200236 u64 period = pair ? pair->stat.period : 0;
237 const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64;
238
239 return scnprintf(hpp->buf, hpp->size, fmt, period);
240}
Namhyung Kim4fb71072013-01-22 18:09:34 +0900241
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100242static int hpp__header_delta(struct perf_hpp_fmt *_fmt __maybe_unused,
243 struct perf_hpp *hpp)
Namhyung Kimea251d52012-09-03 11:53:06 +0900244{
Namhyung Kim9ffad982012-09-03 11:53:07 +0900245 const char *fmt = symbol_conf.field_sep ? "%s" : "%7s";
246
247 return scnprintf(hpp->buf, hpp->size, fmt, "Delta");
Namhyung Kimea251d52012-09-03 11:53:06 +0900248}
249
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100250static int hpp__width_delta(struct perf_hpp_fmt *fmt __maybe_unused,
251 struct perf_hpp *hpp __maybe_unused)
Namhyung Kimea251d52012-09-03 11:53:06 +0900252{
253 return 7;
254}
255
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100256static int hpp__entry_delta(struct perf_hpp_fmt *_fmt __maybe_unused,
257 struct perf_hpp *hpp, struct hist_entry *he)
Namhyung Kimea251d52012-09-03 11:53:06 +0900258{
Jiri Olsa05472da2012-11-28 14:52:40 +0100259 struct hist_entry *pair = hist_entry__next_pair(he);
Namhyung Kim9ffad982012-09-03 11:53:07 +0900260 const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s";
261 char buf[32] = " ";
Jiri Olsa05472da2012-11-28 14:52:40 +0100262 double diff = 0.0;
Namhyung Kimea251d52012-09-03 11:53:06 +0900263
Jiri Olsa05472da2012-11-28 14:52:40 +0100264 if (pair) {
265 if (he->diff.computed)
266 diff = he->diff.period_ratio_delta;
267 else
268 diff = perf_diff__compute_delta(he, pair);
269 } else
270 diff = perf_diff__period_percent(he, he->stat.period);
Namhyung Kimea251d52012-09-03 11:53:06 +0900271
Namhyung Kim9ffad982012-09-03 11:53:07 +0900272 if (fabs(diff) >= 0.01)
273 scnprintf(buf, sizeof(buf), "%+4.2F%%", diff);
Namhyung Kimea251d52012-09-03 11:53:06 +0900274
Namhyung Kim9ffad982012-09-03 11:53:07 +0900275 return scnprintf(hpp->buf, hpp->size, fmt, buf);
Namhyung Kimea251d52012-09-03 11:53:06 +0900276}
277
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100278static int hpp__header_ratio(struct perf_hpp_fmt *_fmt __maybe_unused,
279 struct perf_hpp *hpp)
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200280{
281 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
282
283 return scnprintf(hpp->buf, hpp->size, fmt, "Ratio");
284}
285
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100286static int hpp__width_ratio(struct perf_hpp_fmt *fmt __maybe_unused,
287 struct perf_hpp *hpp __maybe_unused)
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200288{
289 return 14;
290}
291
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100292static int hpp__entry_ratio(struct perf_hpp_fmt *_fmt __maybe_unused,
293 struct perf_hpp *hpp, struct hist_entry *he)
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200294{
Jiri Olsa05472da2012-11-28 14:52:40 +0100295 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200296 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
297 char buf[32] = " ";
Jiri Olsa05472da2012-11-28 14:52:40 +0100298 double ratio = 0.0;
Jiri Olsa96c47f12012-10-05 16:44:42 +0200299
Jiri Olsa05472da2012-11-28 14:52:40 +0100300 if (pair) {
301 if (he->diff.computed)
302 ratio = he->diff.period_ratio;
303 else
304 ratio = perf_diff__compute_ratio(he, pair);
305 }
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200306
307 if (ratio > 0.0)
308 scnprintf(buf, sizeof(buf), "%+14.6F", ratio);
309
310 return scnprintf(hpp->buf, hpp->size, fmt, buf);
311}
312
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100313static int hpp__header_wdiff(struct perf_hpp_fmt *_fmt __maybe_unused,
314 struct perf_hpp *hpp)
Jiri Olsa81d5f952012-10-05 16:44:43 +0200315{
316 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
317
318 return scnprintf(hpp->buf, hpp->size, fmt, "Weighted diff");
319}
320
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100321static int hpp__width_wdiff(struct perf_hpp_fmt *fmt __maybe_unused,
322 struct perf_hpp *hpp __maybe_unused)
Jiri Olsa81d5f952012-10-05 16:44:43 +0200323{
324 return 14;
325}
326
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100327static int hpp__entry_wdiff(struct perf_hpp_fmt *_fmt __maybe_unused,
328 struct perf_hpp *hpp, struct hist_entry *he)
Jiri Olsa81d5f952012-10-05 16:44:43 +0200329{
Jiri Olsa05472da2012-11-28 14:52:40 +0100330 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa81d5f952012-10-05 16:44:43 +0200331 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
332 char buf[32] = " ";
Jiri Olsa05472da2012-11-28 14:52:40 +0100333 s64 wdiff = 0;
Jiri Olsa81d5f952012-10-05 16:44:43 +0200334
Jiri Olsa05472da2012-11-28 14:52:40 +0100335 if (pair) {
336 if (he->diff.computed)
337 wdiff = he->diff.wdiff;
338 else
339 wdiff = perf_diff__compute_wdiff(he, pair);
340 }
Jiri Olsa81d5f952012-10-05 16:44:43 +0200341
342 if (wdiff != 0)
343 scnprintf(buf, sizeof(buf), "%14ld", wdiff);
344
345 return scnprintf(hpp->buf, hpp->size, fmt, buf);
346}
347
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100348static int hpp__header_formula(struct perf_hpp_fmt *_fmt __maybe_unused,
349 struct perf_hpp *hpp)
Jiri Olsaed279da2012-10-05 16:44:45 +0200350{
351 const char *fmt = symbol_conf.field_sep ? "%s" : "%70s";
352
353 return scnprintf(hpp->buf, hpp->size, fmt, "Formula");
354}
355
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100356static int hpp__width_formula(struct perf_hpp_fmt *fmt __maybe_unused,
357 struct perf_hpp *hpp __maybe_unused)
Jiri Olsaed279da2012-10-05 16:44:45 +0200358{
359 return 70;
360}
361
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100362static int hpp__entry_formula(struct perf_hpp_fmt *_fmt __maybe_unused,
363 struct perf_hpp *hpp, struct hist_entry *he)
Jiri Olsaed279da2012-10-05 16:44:45 +0200364{
Jiri Olsaf4c8bae2012-11-28 14:52:41 +0100365 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsaed279da2012-10-05 16:44:45 +0200366 const char *fmt = symbol_conf.field_sep ? "%s" : "%-70s";
367 char buf[96] = " ";
368
Jiri Olsaf4c8bae2012-11-28 14:52:41 +0100369 if (pair)
370 perf_diff__formula(he, pair, buf, sizeof(buf));
371
Jiri Olsaed279da2012-10-05 16:44:45 +0200372 return scnprintf(hpp->buf, hpp->size, fmt, buf);
373}
374
Jiri Olsa12400052012-10-13 00:06:16 +0200375#define HPP__COLOR_PRINT_FNS(_name) \
376 { \
377 .header = hpp__header_ ## _name, \
378 .width = hpp__width_ ## _name, \
379 .color = hpp__color_ ## _name, \
380 .entry = hpp__entry_ ## _name \
381 }
Namhyung Kimea251d52012-09-03 11:53:06 +0900382
Jiri Olsa12400052012-10-13 00:06:16 +0200383#define HPP__PRINT_FNS(_name) \
384 { \
385 .header = hpp__header_ ## _name, \
386 .width = hpp__width_ ## _name, \
387 .entry = hpp__entry_ ## _name \
388 }
Namhyung Kimea251d52012-09-03 11:53:06 +0900389
390struct perf_hpp_fmt perf_hpp__format[] = {
Jiri Olsa12400052012-10-13 00:06:16 +0200391 HPP__COLOR_PRINT_FNS(baseline),
392 HPP__COLOR_PRINT_FNS(overhead),
393 HPP__COLOR_PRINT_FNS(overhead_sys),
394 HPP__COLOR_PRINT_FNS(overhead_us),
395 HPP__COLOR_PRINT_FNS(overhead_guest_sys),
396 HPP__COLOR_PRINT_FNS(overhead_guest_us),
397 HPP__PRINT_FNS(samples),
398 HPP__PRINT_FNS(period),
399 HPP__PRINT_FNS(period_baseline),
400 HPP__PRINT_FNS(delta),
401 HPP__PRINT_FNS(ratio),
402 HPP__PRINT_FNS(wdiff),
Jiri Olsa12400052012-10-13 00:06:16 +0200403 HPP__PRINT_FNS(formula)
Namhyung Kimea251d52012-09-03 11:53:06 +0900404};
405
Jiri Olsa12400052012-10-13 00:06:16 +0200406LIST_HEAD(perf_hpp__list);
407
Namhyung Kim4fb71072013-01-22 18:09:34 +0900408
Namhyung Kimea251d52012-09-03 11:53:06 +0900409#undef HPP__COLOR_PRINT_FNS
410#undef HPP__PRINT_FNS
411
Namhyung Kim4fb71072013-01-22 18:09:34 +0900412#undef HPP_PERCENT_FNS
413#undef HPP_RAW_FNS
414
415#undef __HPP_HEADER_FN
416#undef __HPP_WIDTH_FN
417#undef __HPP_COLOR_PERCENT_FN
418#undef __HPP_ENTRY_PERCENT_FN
419#undef __HPP_ENTRY_RAW_FN
420
421
Jiri Olsa1d778222012-10-04 21:49:39 +0900422void perf_hpp__init(void)
Namhyung Kimea251d52012-09-03 11:53:06 +0900423{
424 if (symbol_conf.show_cpu_utilization) {
Jiri Olsa12400052012-10-13 00:06:16 +0200425 perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS);
426 perf_hpp__column_enable(PERF_HPP__OVERHEAD_US);
Namhyung Kimea251d52012-09-03 11:53:06 +0900427
428 if (perf_guest) {
Jiri Olsa12400052012-10-13 00:06:16 +0200429 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS);
430 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US);
Namhyung Kimea251d52012-09-03 11:53:06 +0900431 }
432 }
433
434 if (symbol_conf.show_nr_samples)
Jiri Olsa12400052012-10-13 00:06:16 +0200435 perf_hpp__column_enable(PERF_HPP__SAMPLES);
Namhyung Kimea251d52012-09-03 11:53:06 +0900436
437 if (symbol_conf.show_total_period)
Jiri Olsa12400052012-10-13 00:06:16 +0200438 perf_hpp__column_enable(PERF_HPP__PERIOD);
Jiri Olsa1d778222012-10-04 21:49:39 +0900439}
Namhyung Kimea251d52012-09-03 11:53:06 +0900440
Jiri Olsa12400052012-10-13 00:06:16 +0200441void perf_hpp__column_register(struct perf_hpp_fmt *format)
442{
443 list_add_tail(&format->list, &perf_hpp__list);
444}
445
446void perf_hpp__column_enable(unsigned col)
Jiri Olsa1d778222012-10-04 21:49:39 +0900447{
448 BUG_ON(col >= PERF_HPP__MAX_INDEX);
Jiri Olsa12400052012-10-13 00:06:16 +0200449 perf_hpp__column_register(&perf_hpp__format[col]);
Namhyung Kimea251d52012-09-03 11:53:06 +0900450}
451
452static inline void advance_hpp(struct perf_hpp *hpp, int inc)
453{
454 hpp->buf += inc;
455 hpp->size -= inc;
456}
457
458int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
459 bool color)
460{
461 const char *sep = symbol_conf.field_sep;
Jiri Olsa12400052012-10-13 00:06:16 +0200462 struct perf_hpp_fmt *fmt;
Namhyung Kimea251d52012-09-03 11:53:06 +0900463 char *start = hpp->buf;
Jiri Olsa12400052012-10-13 00:06:16 +0200464 int ret;
Jiri Olsa5395a042012-10-04 21:49:37 +0900465 bool first = true;
Namhyung Kimea251d52012-09-03 11:53:06 +0900466
467 if (symbol_conf.exclude_other && !he->parent)
468 return 0;
469
Jiri Olsa12400052012-10-13 00:06:16 +0200470 perf_hpp__for_each_format(fmt) {
Jiri Olsac0d246b2012-10-20 22:14:10 +0200471 /*
472 * If there's no field_sep, we still need
473 * to display initial ' '.
474 */
Jiri Olsa5395a042012-10-04 21:49:37 +0900475 if (!sep || !first) {
Namhyung Kimea251d52012-09-03 11:53:06 +0900476 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
477 advance_hpp(hpp, ret);
Jiri Olsac0d246b2012-10-20 22:14:10 +0200478 } else
Jiri Olsa5395a042012-10-04 21:49:37 +0900479 first = false;
Namhyung Kimea251d52012-09-03 11:53:06 +0900480
Jiri Olsa12400052012-10-13 00:06:16 +0200481 if (color && fmt->color)
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100482 ret = fmt->color(fmt, hpp, he);
Namhyung Kimea251d52012-09-03 11:53:06 +0900483 else
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100484 ret = fmt->entry(fmt, hpp, he);
Namhyung Kimea251d52012-09-03 11:53:06 +0900485
486 advance_hpp(hpp, ret);
487 }
488
489 return hpp->buf - start;
490}
491
492int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size,
493 struct hists *hists)
494{
495 const char *sep = symbol_conf.field_sep;
496 struct sort_entry *se;
497 int ret = 0;
498
499 list_for_each_entry(se, &hist_entry__sort_list, list) {
500 if (se->elide)
501 continue;
502
503 ret += scnprintf(s + ret, size - ret, "%s", sep ?: " ");
504 ret += se->se_snprintf(he, s + ret, size - ret,
505 hists__col_len(hists, se->se_width_idx));
506 }
507
508 return ret;
509}
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900510
511/*
512 * See hists__fprintf to match the column widths
513 */
514unsigned int hists__sort_list_width(struct hists *hists)
515{
Jiri Olsa12400052012-10-13 00:06:16 +0200516 struct perf_hpp_fmt *fmt;
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900517 struct sort_entry *se;
Jiri Olsa12400052012-10-13 00:06:16 +0200518 int i = 0, ret = 0;
Namhyung Kim5b9e2142013-01-22 18:09:37 +0900519 struct perf_hpp dummy_hpp = {
520 .ptr = hists_to_evsel(hists),
521 };
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900522
Jiri Olsa12400052012-10-13 00:06:16 +0200523 perf_hpp__for_each_format(fmt) {
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900524 if (i)
525 ret += 2;
526
Jiri Olsa2c5d4b42013-01-31 23:31:11 +0100527 ret += fmt->width(fmt, &dummy_hpp);
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900528 }
529
530 list_for_each_entry(se, &hist_entry__sort_list, list)
531 if (!se->elide)
532 ret += 2 + hists__col_len(hists, se->se_width_idx);
533
534 if (verbose) /* Addr + origin */
535 ret += 3 + BITS_PER_LONG / 4;
536
537 return ret;
538}