blob: d671e63aa351ce4f5ccbf864fe72db80b5d2ffd6 [file] [log] [blame]
Namhyung Kimea251d52012-09-03 11:53:06 +09001#include <math.h>
2
3#include "../util/hist.h"
4#include "../util/util.h"
5#include "../util/sort.h"
Namhyung Kim4fb71072013-01-22 18:09:34 +09006#include "../util/evsel.h"
Namhyung Kimea251d52012-09-03 11:53:06 +09007
8/* hist period print (hpp) functions */
Namhyung Kimea251d52012-09-03 11:53:06 +09009
Namhyung Kim4fb71072013-01-22 18:09:34 +090010typedef int (*hpp_snprint_fn)(char *buf, size_t size, const char *fmt, ...);
Namhyung Kimea251d52012-09-03 11:53:06 +090011
Jiri Olsa0c5268b2013-02-04 13:32:55 +010012static int __hpp__fmt(struct perf_hpp *hpp, struct hist_entry *he,
13 u64 (*get_field)(struct hist_entry *),
14 const char *fmt, hpp_snprint_fn print_fn,
15 bool fmt_percent)
Namhyung Kimea251d52012-09-03 11:53:06 +090016{
Namhyung Kim4fb71072013-01-22 18:09:34 +090017 int ret;
Jiri Olsab5ff71c2012-10-04 21:49:40 +090018 struct hists *hists = he->hists;
Namhyung Kimea251d52012-09-03 11:53:06 +090019
Jiri Olsa0c5268b2013-02-04 13:32:55 +010020 if (fmt_percent) {
21 double percent = 0.0;
Namhyung Kim4fb71072013-01-22 18:09:34 +090022
Jiri Olsa0c5268b2013-02-04 13:32:55 +010023 if (hists->stats.total_period)
24 percent = 100.0 * get_field(he) /
25 hists->stats.total_period;
26
27 ret = print_fn(hpp->buf, hpp->size, fmt, percent);
28 } else
29 ret = print_fn(hpp->buf, hpp->size, fmt, get_field(he));
Namhyung Kim5b9e2142013-01-22 18:09:37 +090030
31 if (symbol_conf.event_group) {
32 int prev_idx, idx_delta;
33 struct perf_evsel *evsel = hists_to_evsel(hists);
34 struct hist_entry *pair;
35 int nr_members = evsel->nr_members;
36
37 if (nr_members <= 1)
38 return ret;
39
40 prev_idx = perf_evsel__group_idx(evsel);
41
42 list_for_each_entry(pair, &he->pairs.head, pairs.node) {
43 u64 period = get_field(pair);
44 u64 total = pair->hists->stats.total_period;
45
46 if (!total)
47 continue;
48
49 evsel = hists_to_evsel(pair->hists);
50 idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1;
51
52 while (idx_delta--) {
53 /*
54 * zero-fill group members in the middle which
55 * have no sample
56 */
57 ret += print_fn(hpp->buf + ret, hpp->size - ret,
Jiri Olsa0c5268b2013-02-04 13:32:55 +010058 fmt, 0);
Namhyung Kim5b9e2142013-01-22 18:09:37 +090059 }
60
Jiri Olsa0c5268b2013-02-04 13:32:55 +010061 if (fmt_percent)
62 ret += print_fn(hpp->buf + ret, hpp->size - ret,
63 fmt, 100.0 * period / total);
64 else
65 ret += print_fn(hpp->buf + ret, hpp->size - ret,
66 fmt, period);
Namhyung Kim5b9e2142013-01-22 18:09:37 +090067
68 prev_idx = perf_evsel__group_idx(evsel);
69 }
70
71 idx_delta = nr_members - prev_idx - 1;
72
73 while (idx_delta--) {
74 /*
75 * zero-fill group members at last which have no sample
76 */
77 ret += print_fn(hpp->buf + ret, hpp->size - ret,
Jiri Olsa0c5268b2013-02-04 13:32:55 +010078 fmt, 0);
Namhyung Kim5b9e2142013-01-22 18:09:37 +090079 }
80 }
Namhyung Kim4fb71072013-01-22 18:09:34 +090081 return ret;
Namhyung Kimea251d52012-09-03 11:53:06 +090082}
83
Namhyung Kim4fb71072013-01-22 18:09:34 +090084#define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
85static int hpp__header_##_type(struct perf_hpp *hpp) \
86{ \
87 int len = _min_width; \
88 \
Namhyung Kim5b9e2142013-01-22 18:09:37 +090089 if (symbol_conf.event_group) { \
90 struct perf_evsel *evsel = hpp->ptr; \
91 \
92 len = max(len, evsel->nr_members * _unit_width); \
93 } \
Namhyung Kim4fb71072013-01-22 18:09:34 +090094 return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
Namhyung Kimea251d52012-09-03 11:53:06 +090095}
96
Namhyung Kim4fb71072013-01-22 18:09:34 +090097#define __HPP_WIDTH_FN(_type, _min_width, _unit_width) \
98static int hpp__width_##_type(struct perf_hpp *hpp __maybe_unused) \
99{ \
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 \
116static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he) \
117{ \
Jiri Olsa0c5268b2013-02-04 13:32:55 +0100118 return __hpp__fmt(hpp, he, he_get_##_field, " %6.2f%%", \
119 (hpp_snprint_fn)percent_color_snprintf, true); \
Namhyung Kimea251d52012-09-03 11:53:06 +0900120}
121
Namhyung Kim4fb71072013-01-22 18:09:34 +0900122#define __HPP_ENTRY_PERCENT_FN(_type, _field) \
123static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) \
124{ \
125 const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \
Jiri Olsa0c5268b2013-02-04 13:32:55 +0100126 return __hpp__fmt(hpp, he, he_get_##_field, fmt, \
127 scnprintf, true); \
Namhyung Kimea251d52012-09-03 11:53:06 +0900128}
129
Namhyung Kim4fb71072013-01-22 18:09:34 +0900130#define __HPP_ENTRY_RAW_FN(_type, _field) \
131static u64 he_get_raw_##_field(struct hist_entry *he) \
132{ \
133 return he->stat._field; \
134} \
135 \
136static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) \
137{ \
138 const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \
Jiri Olsa0c5268b2013-02-04 13:32:55 +0100139 return __hpp__fmt(hpp, he, he_get_raw_##_field, fmt, scnprintf, false); \
Namhyung Kimea251d52012-09-03 11:53:06 +0900140}
141
Namhyung Kim4fb71072013-01-22 18:09:34 +0900142#define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \
143__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
144__HPP_WIDTH_FN(_type, _min_width, _unit_width) \
145__HPP_COLOR_PERCENT_FN(_type, _field) \
146__HPP_ENTRY_PERCENT_FN(_type, _field)
Namhyung Kimea251d52012-09-03 11:53:06 +0900147
Namhyung Kim4fb71072013-01-22 18:09:34 +0900148#define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \
149__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
150__HPP_WIDTH_FN(_type, _min_width, _unit_width) \
151__HPP_ENTRY_RAW_FN(_type, _field)
Jiri Olsab5ff71c2012-10-04 21:49:40 +0900152
Namhyung Kimea251d52012-09-03 11:53:06 +0900153
Namhyung Kim4fb71072013-01-22 18:09:34 +0900154HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8)
155HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8)
156HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8)
157HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8)
158HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us, 9, 8)
Namhyung Kim9ffad982012-09-03 11:53:07 +0900159
Namhyung Kim4fb71072013-01-22 18:09:34 +0900160HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12)
161HPP_RAW_FNS(period, "Period", period, 12, 12)
Namhyung Kimea251d52012-09-03 11:53:06 +0900162
Namhyung Kimea251d52012-09-03 11:53:06 +0900163
Jiri Olsa5395a042012-10-04 21:49:37 +0900164static int hpp__header_baseline(struct perf_hpp *hpp)
165{
166 return scnprintf(hpp->buf, hpp->size, "Baseline");
167}
168
169static int hpp__width_baseline(struct perf_hpp *hpp __maybe_unused)
170{
171 return 8;
172}
173
174static double baseline_percent(struct hist_entry *he)
175{
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200176 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa5395a042012-10-04 21:49:37 +0900177 struct hists *pair_hists = pair ? pair->hists : NULL;
178 double percent = 0.0;
179
180 if (pair) {
181 u64 total_period = pair_hists->stats.total_period;
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900182 u64 base_period = pair->stat.period;
Jiri Olsa5395a042012-10-04 21:49:37 +0900183
184 percent = 100.0 * base_period / total_period;
185 }
186
187 return percent;
188}
189
190static int hpp__color_baseline(struct perf_hpp *hpp, struct hist_entry *he)
191{
192 double percent = baseline_percent(he);
193
Namhyung Kim4fb71072013-01-22 18:09:34 +0900194 if (hist_entry__has_pairs(he) || symbol_conf.field_sep)
Jiri Olsa6e923492012-10-05 16:44:47 +0200195 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);
196 else
197 return scnprintf(hpp->buf, hpp->size, " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900198}
199
200static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he)
201{
202 double percent = baseline_percent(he);
203 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%";
204
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200205 if (hist_entry__has_pairs(he) || symbol_conf.field_sep)
Jiri Olsa6e923492012-10-05 16:44:47 +0200206 return scnprintf(hpp->buf, hpp->size, fmt, percent);
207 else
208 return scnprintf(hpp->buf, hpp->size, " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900209}
210
Jiri Olsa61949b22012-10-05 16:44:44 +0200211static int hpp__header_period_baseline(struct perf_hpp *hpp)
212{
213 const char *fmt = symbol_conf.field_sep ? "%s" : "%12s";
214
215 return scnprintf(hpp->buf, hpp->size, fmt, "Period Base");
216}
217
218static int hpp__width_period_baseline(struct perf_hpp *hpp __maybe_unused)
219{
220 return 12;
221}
222
223static int hpp__entry_period_baseline(struct perf_hpp *hpp, struct hist_entry *he)
224{
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200225 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa61949b22012-10-05 16:44:44 +0200226 u64 period = pair ? pair->stat.period : 0;
227 const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64;
228
229 return scnprintf(hpp->buf, hpp->size, fmt, period);
230}
Namhyung Kim4fb71072013-01-22 18:09:34 +0900231
Namhyung Kimea251d52012-09-03 11:53:06 +0900232static int hpp__header_delta(struct perf_hpp *hpp)
233{
Namhyung Kim9ffad982012-09-03 11:53:07 +0900234 const char *fmt = symbol_conf.field_sep ? "%s" : "%7s";
235
236 return scnprintf(hpp->buf, hpp->size, fmt, "Delta");
Namhyung Kimea251d52012-09-03 11:53:06 +0900237}
238
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300239static int hpp__width_delta(struct perf_hpp *hpp __maybe_unused)
Namhyung Kimea251d52012-09-03 11:53:06 +0900240{
241 return 7;
242}
243
244static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he)
245{
Jiri Olsa05472da2012-11-28 14:52:40 +0100246 struct hist_entry *pair = hist_entry__next_pair(he);
Namhyung Kim9ffad982012-09-03 11:53:07 +0900247 const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s";
248 char buf[32] = " ";
Jiri Olsa05472da2012-11-28 14:52:40 +0100249 double diff = 0.0;
Namhyung Kimea251d52012-09-03 11:53:06 +0900250
Jiri Olsa05472da2012-11-28 14:52:40 +0100251 if (pair) {
252 if (he->diff.computed)
253 diff = he->diff.period_ratio_delta;
254 else
255 diff = perf_diff__compute_delta(he, pair);
256 } else
257 diff = perf_diff__period_percent(he, he->stat.period);
Namhyung Kimea251d52012-09-03 11:53:06 +0900258
Namhyung Kim9ffad982012-09-03 11:53:07 +0900259 if (fabs(diff) >= 0.01)
260 scnprintf(buf, sizeof(buf), "%+4.2F%%", diff);
Namhyung Kimea251d52012-09-03 11:53:06 +0900261
Namhyung Kim9ffad982012-09-03 11:53:07 +0900262 return scnprintf(hpp->buf, hpp->size, fmt, buf);
Namhyung Kimea251d52012-09-03 11:53:06 +0900263}
264
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200265static int hpp__header_ratio(struct perf_hpp *hpp)
266{
267 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
268
269 return scnprintf(hpp->buf, hpp->size, fmt, "Ratio");
270}
271
272static int hpp__width_ratio(struct perf_hpp *hpp __maybe_unused)
273{
274 return 14;
275}
276
277static int hpp__entry_ratio(struct perf_hpp *hpp, struct hist_entry *he)
278{
Jiri Olsa05472da2012-11-28 14:52:40 +0100279 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200280 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
281 char buf[32] = " ";
Jiri Olsa05472da2012-11-28 14:52:40 +0100282 double ratio = 0.0;
Jiri Olsa96c47f12012-10-05 16:44:42 +0200283
Jiri Olsa05472da2012-11-28 14:52:40 +0100284 if (pair) {
285 if (he->diff.computed)
286 ratio = he->diff.period_ratio;
287 else
288 ratio = perf_diff__compute_ratio(he, pair);
289 }
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200290
291 if (ratio > 0.0)
292 scnprintf(buf, sizeof(buf), "%+14.6F", ratio);
293
294 return scnprintf(hpp->buf, hpp->size, fmt, buf);
295}
296
Jiri Olsa81d5f952012-10-05 16:44:43 +0200297static int hpp__header_wdiff(struct perf_hpp *hpp)
298{
299 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
300
301 return scnprintf(hpp->buf, hpp->size, fmt, "Weighted diff");
302}
303
304static int hpp__width_wdiff(struct perf_hpp *hpp __maybe_unused)
305{
306 return 14;
307}
308
309static int hpp__entry_wdiff(struct perf_hpp *hpp, struct hist_entry *he)
310{
Jiri Olsa05472da2012-11-28 14:52:40 +0100311 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa81d5f952012-10-05 16:44:43 +0200312 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
313 char buf[32] = " ";
Jiri Olsa05472da2012-11-28 14:52:40 +0100314 s64 wdiff = 0;
Jiri Olsa81d5f952012-10-05 16:44:43 +0200315
Jiri Olsa05472da2012-11-28 14:52:40 +0100316 if (pair) {
317 if (he->diff.computed)
318 wdiff = he->diff.wdiff;
319 else
320 wdiff = perf_diff__compute_wdiff(he, pair);
321 }
Jiri Olsa81d5f952012-10-05 16:44:43 +0200322
323 if (wdiff != 0)
324 scnprintf(buf, sizeof(buf), "%14ld", wdiff);
325
326 return scnprintf(hpp->buf, hpp->size, fmt, buf);
327}
328
Jiri Olsaed279da2012-10-05 16:44:45 +0200329static int hpp__header_formula(struct perf_hpp *hpp)
330{
331 const char *fmt = symbol_conf.field_sep ? "%s" : "%70s";
332
333 return scnprintf(hpp->buf, hpp->size, fmt, "Formula");
334}
335
336static int hpp__width_formula(struct perf_hpp *hpp __maybe_unused)
337{
338 return 70;
339}
340
341static int hpp__entry_formula(struct perf_hpp *hpp, struct hist_entry *he)
342{
Jiri Olsaf4c8bae2012-11-28 14:52:41 +0100343 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsaed279da2012-10-05 16:44:45 +0200344 const char *fmt = symbol_conf.field_sep ? "%s" : "%-70s";
345 char buf[96] = " ";
346
Jiri Olsaf4c8bae2012-11-28 14:52:41 +0100347 if (pair)
348 perf_diff__formula(he, pair, buf, sizeof(buf));
349
Jiri Olsaed279da2012-10-05 16:44:45 +0200350 return scnprintf(hpp->buf, hpp->size, fmt, buf);
351}
352
Jiri Olsa12400052012-10-13 00:06:16 +0200353#define HPP__COLOR_PRINT_FNS(_name) \
354 { \
355 .header = hpp__header_ ## _name, \
356 .width = hpp__width_ ## _name, \
357 .color = hpp__color_ ## _name, \
358 .entry = hpp__entry_ ## _name \
359 }
Namhyung Kimea251d52012-09-03 11:53:06 +0900360
Jiri Olsa12400052012-10-13 00:06:16 +0200361#define HPP__PRINT_FNS(_name) \
362 { \
363 .header = hpp__header_ ## _name, \
364 .width = hpp__width_ ## _name, \
365 .entry = hpp__entry_ ## _name \
366 }
Namhyung Kimea251d52012-09-03 11:53:06 +0900367
368struct perf_hpp_fmt perf_hpp__format[] = {
Jiri Olsa12400052012-10-13 00:06:16 +0200369 HPP__COLOR_PRINT_FNS(baseline),
370 HPP__COLOR_PRINT_FNS(overhead),
371 HPP__COLOR_PRINT_FNS(overhead_sys),
372 HPP__COLOR_PRINT_FNS(overhead_us),
373 HPP__COLOR_PRINT_FNS(overhead_guest_sys),
374 HPP__COLOR_PRINT_FNS(overhead_guest_us),
375 HPP__PRINT_FNS(samples),
376 HPP__PRINT_FNS(period),
377 HPP__PRINT_FNS(period_baseline),
378 HPP__PRINT_FNS(delta),
379 HPP__PRINT_FNS(ratio),
380 HPP__PRINT_FNS(wdiff),
Jiri Olsa12400052012-10-13 00:06:16 +0200381 HPP__PRINT_FNS(formula)
Namhyung Kimea251d52012-09-03 11:53:06 +0900382};
383
Jiri Olsa12400052012-10-13 00:06:16 +0200384LIST_HEAD(perf_hpp__list);
385
Namhyung Kim4fb71072013-01-22 18:09:34 +0900386
Namhyung Kimea251d52012-09-03 11:53:06 +0900387#undef HPP__COLOR_PRINT_FNS
388#undef HPP__PRINT_FNS
389
Namhyung Kim4fb71072013-01-22 18:09:34 +0900390#undef HPP_PERCENT_FNS
391#undef HPP_RAW_FNS
392
393#undef __HPP_HEADER_FN
394#undef __HPP_WIDTH_FN
395#undef __HPP_COLOR_PERCENT_FN
396#undef __HPP_ENTRY_PERCENT_FN
397#undef __HPP_ENTRY_RAW_FN
398
399
Jiri Olsa1d778222012-10-04 21:49:39 +0900400void perf_hpp__init(void)
Namhyung Kimea251d52012-09-03 11:53:06 +0900401{
402 if (symbol_conf.show_cpu_utilization) {
Jiri Olsa12400052012-10-13 00:06:16 +0200403 perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS);
404 perf_hpp__column_enable(PERF_HPP__OVERHEAD_US);
Namhyung Kimea251d52012-09-03 11:53:06 +0900405
406 if (perf_guest) {
Jiri Olsa12400052012-10-13 00:06:16 +0200407 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS);
408 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US);
Namhyung Kimea251d52012-09-03 11:53:06 +0900409 }
410 }
411
412 if (symbol_conf.show_nr_samples)
Jiri Olsa12400052012-10-13 00:06:16 +0200413 perf_hpp__column_enable(PERF_HPP__SAMPLES);
Namhyung Kimea251d52012-09-03 11:53:06 +0900414
415 if (symbol_conf.show_total_period)
Jiri Olsa12400052012-10-13 00:06:16 +0200416 perf_hpp__column_enable(PERF_HPP__PERIOD);
Jiri Olsa1d778222012-10-04 21:49:39 +0900417}
Namhyung Kimea251d52012-09-03 11:53:06 +0900418
Jiri Olsa12400052012-10-13 00:06:16 +0200419void perf_hpp__column_register(struct perf_hpp_fmt *format)
420{
421 list_add_tail(&format->list, &perf_hpp__list);
422}
423
424void perf_hpp__column_enable(unsigned col)
Jiri Olsa1d778222012-10-04 21:49:39 +0900425{
426 BUG_ON(col >= PERF_HPP__MAX_INDEX);
Jiri Olsa12400052012-10-13 00:06:16 +0200427 perf_hpp__column_register(&perf_hpp__format[col]);
Namhyung Kimea251d52012-09-03 11:53:06 +0900428}
429
430static inline void advance_hpp(struct perf_hpp *hpp, int inc)
431{
432 hpp->buf += inc;
433 hpp->size -= inc;
434}
435
436int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
437 bool color)
438{
439 const char *sep = symbol_conf.field_sep;
Jiri Olsa12400052012-10-13 00:06:16 +0200440 struct perf_hpp_fmt *fmt;
Namhyung Kimea251d52012-09-03 11:53:06 +0900441 char *start = hpp->buf;
Jiri Olsa12400052012-10-13 00:06:16 +0200442 int ret;
Jiri Olsa5395a042012-10-04 21:49:37 +0900443 bool first = true;
Namhyung Kimea251d52012-09-03 11:53:06 +0900444
445 if (symbol_conf.exclude_other && !he->parent)
446 return 0;
447
Jiri Olsa12400052012-10-13 00:06:16 +0200448 perf_hpp__for_each_format(fmt) {
Jiri Olsac0d246b2012-10-20 22:14:10 +0200449 /*
450 * If there's no field_sep, we still need
451 * to display initial ' '.
452 */
Jiri Olsa5395a042012-10-04 21:49:37 +0900453 if (!sep || !first) {
Namhyung Kimea251d52012-09-03 11:53:06 +0900454 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
455 advance_hpp(hpp, ret);
Jiri Olsac0d246b2012-10-20 22:14:10 +0200456 } else
Jiri Olsa5395a042012-10-04 21:49:37 +0900457 first = false;
Namhyung Kimea251d52012-09-03 11:53:06 +0900458
Jiri Olsa12400052012-10-13 00:06:16 +0200459 if (color && fmt->color)
460 ret = fmt->color(hpp, he);
Namhyung Kimea251d52012-09-03 11:53:06 +0900461 else
Jiri Olsa12400052012-10-13 00:06:16 +0200462 ret = fmt->entry(hpp, he);
Namhyung Kimea251d52012-09-03 11:53:06 +0900463
464 advance_hpp(hpp, ret);
465 }
466
467 return hpp->buf - start;
468}
469
470int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size,
471 struct hists *hists)
472{
473 const char *sep = symbol_conf.field_sep;
474 struct sort_entry *se;
475 int ret = 0;
476
477 list_for_each_entry(se, &hist_entry__sort_list, list) {
478 if (se->elide)
479 continue;
480
481 ret += scnprintf(s + ret, size - ret, "%s", sep ?: " ");
482 ret += se->se_snprintf(he, s + ret, size - ret,
483 hists__col_len(hists, se->se_width_idx));
484 }
485
486 return ret;
487}
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900488
489/*
490 * See hists__fprintf to match the column widths
491 */
492unsigned int hists__sort_list_width(struct hists *hists)
493{
Jiri Olsa12400052012-10-13 00:06:16 +0200494 struct perf_hpp_fmt *fmt;
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900495 struct sort_entry *se;
Jiri Olsa12400052012-10-13 00:06:16 +0200496 int i = 0, ret = 0;
Namhyung Kim5b9e2142013-01-22 18:09:37 +0900497 struct perf_hpp dummy_hpp = {
498 .ptr = hists_to_evsel(hists),
499 };
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900500
Jiri Olsa12400052012-10-13 00:06:16 +0200501 perf_hpp__for_each_format(fmt) {
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900502 if (i)
503 ret += 2;
504
Namhyung Kim5b9e2142013-01-22 18:09:37 +0900505 ret += fmt->width(&dummy_hpp);
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900506 }
507
508 list_for_each_entry(se, &hist_entry__sort_list, list)
509 if (!se->elide)
510 ret += 2 + hists__col_len(hists, se->se_width_idx);
511
512 if (verbose) /* Addr + origin */
513 ret += 3 + BITS_PER_LONG / 4;
514
515 return ret;
516}