blob: a47ce98c2cb12924df7b6289b1348e4341b7108e [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
Namhyung Kim4fb71072013-01-22 18:09:34 +090012static int __hpp__percent_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)
Namhyung Kimea251d52012-09-03 11:53:06 +090015{
Namhyung Kim4fb71072013-01-22 18:09:34 +090016 int ret;
17 double percent = 0.0;
Jiri Olsab5ff71c2012-10-04 21:49:40 +090018 struct hists *hists = he->hists;
Namhyung Kimea251d52012-09-03 11:53:06 +090019
Namhyung Kim4fb71072013-01-22 18:09:34 +090020 if (hists->stats.total_period)
21 percent = 100.0 * get_field(he) / hists->stats.total_period;
22
23 ret = print_fn(hpp->buf, hpp->size, fmt, percent);
Namhyung Kim5b9e2142013-01-22 18:09:37 +090024
25 if (symbol_conf.event_group) {
26 int prev_idx, idx_delta;
27 struct perf_evsel *evsel = hists_to_evsel(hists);
28 struct hist_entry *pair;
29 int nr_members = evsel->nr_members;
30
31 if (nr_members <= 1)
32 return ret;
33
34 prev_idx = perf_evsel__group_idx(evsel);
35
36 list_for_each_entry(pair, &he->pairs.head, pairs.node) {
37 u64 period = get_field(pair);
38 u64 total = pair->hists->stats.total_period;
39
40 if (!total)
41 continue;
42
43 evsel = hists_to_evsel(pair->hists);
44 idx_delta = perf_evsel__group_idx(evsel) - prev_idx - 1;
45
46 while (idx_delta--) {
47 /*
48 * zero-fill group members in the middle which
49 * have no sample
50 */
51 ret += print_fn(hpp->buf + ret, hpp->size - ret,
52 fmt, 0.0);
53 }
54
55 ret += print_fn(hpp->buf + ret, hpp->size - ret,
56 fmt, 100.0 * period / total);
57
58 prev_idx = perf_evsel__group_idx(evsel);
59 }
60
61 idx_delta = nr_members - prev_idx - 1;
62
63 while (idx_delta--) {
64 /*
65 * zero-fill group members at last which have no sample
66 */
67 ret += print_fn(hpp->buf + ret, hpp->size - ret,
68 fmt, 0.0);
69 }
70 }
Namhyung Kim4fb71072013-01-22 18:09:34 +090071 return ret;
Namhyung Kimea251d52012-09-03 11:53:06 +090072}
73
Namhyung Kim4fb71072013-01-22 18:09:34 +090074static int __hpp__raw_fmt(struct perf_hpp *hpp, struct hist_entry *he,
75 u64 (*get_field)(struct hist_entry *),
76 const char *fmt, hpp_snprint_fn print_fn)
Namhyung Kimea251d52012-09-03 11:53:06 +090077{
Namhyung Kim4fb71072013-01-22 18:09:34 +090078 int ret;
Namhyung Kimea251d52012-09-03 11:53:06 +090079
Namhyung Kim4fb71072013-01-22 18:09:34 +090080 ret = print_fn(hpp->buf, hpp->size, fmt, get_field(he));
81 return ret;
Namhyung Kimea251d52012-09-03 11:53:06 +090082}
83
Namhyung Kim9ffad982012-09-03 11:53:07 +090084
Namhyung Kim4fb71072013-01-22 18:09:34 +090085#define __HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
86static int hpp__header_##_type(struct perf_hpp *hpp) \
87{ \
88 int len = _min_width; \
89 \
Namhyung Kim5b9e2142013-01-22 18:09:37 +090090 if (symbol_conf.event_group) { \
91 struct perf_evsel *evsel = hpp->ptr; \
92 \
93 len = max(len, evsel->nr_members * _unit_width); \
94 } \
Namhyung Kim4fb71072013-01-22 18:09:34 +090095 return scnprintf(hpp->buf, hpp->size, "%*s", len, _str); \
Namhyung Kimea251d52012-09-03 11:53:06 +090096}
97
Namhyung Kim4fb71072013-01-22 18:09:34 +090098#define __HPP_WIDTH_FN(_type, _min_width, _unit_width) \
99static int hpp__width_##_type(struct perf_hpp *hpp __maybe_unused) \
100{ \
101 int len = _min_width; \
102 \
Namhyung Kim5b9e2142013-01-22 18:09:37 +0900103 if (symbol_conf.event_group) { \
104 struct perf_evsel *evsel = hpp->ptr; \
105 \
106 len = max(len, evsel->nr_members * _unit_width); \
107 } \
Namhyung Kim4fb71072013-01-22 18:09:34 +0900108 return len; \
Namhyung Kimea251d52012-09-03 11:53:06 +0900109}
110
Namhyung Kim4fb71072013-01-22 18:09:34 +0900111#define __HPP_COLOR_PERCENT_FN(_type, _field) \
112static u64 he_get_##_field(struct hist_entry *he) \
113{ \
114 return he->stat._field; \
115} \
116 \
117static int hpp__color_##_type(struct perf_hpp *hpp, struct hist_entry *he) \
118{ \
119 return __hpp__percent_fmt(hpp, he, he_get_##_field, " %6.2f%%", \
120 (hpp_snprint_fn)percent_color_snprintf); \
Namhyung Kimea251d52012-09-03 11:53:06 +0900121}
122
Namhyung Kim4fb71072013-01-22 18:09:34 +0900123#define __HPP_ENTRY_PERCENT_FN(_type, _field) \
124static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) \
125{ \
126 const char *fmt = symbol_conf.field_sep ? " %.2f" : " %6.2f%%"; \
127 return __hpp__percent_fmt(hpp, he, he_get_##_field, fmt, \
128 scnprintf); \
Namhyung Kimea251d52012-09-03 11:53:06 +0900129}
130
Namhyung Kim4fb71072013-01-22 18:09:34 +0900131#define __HPP_ENTRY_RAW_FN(_type, _field) \
132static u64 he_get_raw_##_field(struct hist_entry *he) \
133{ \
134 return he->stat._field; \
135} \
136 \
137static int hpp__entry_##_type(struct perf_hpp *hpp, struct hist_entry *he) \
138{ \
139 const char *fmt = symbol_conf.field_sep ? " %"PRIu64 : " %11"PRIu64; \
140 return __hpp__raw_fmt(hpp, he, he_get_raw_##_field, fmt, scnprintf); \
Namhyung Kimea251d52012-09-03 11:53:06 +0900141}
142
Namhyung Kim4fb71072013-01-22 18:09:34 +0900143#define HPP_PERCENT_FNS(_type, _str, _field, _min_width, _unit_width) \
144__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
145__HPP_WIDTH_FN(_type, _min_width, _unit_width) \
146__HPP_COLOR_PERCENT_FN(_type, _field) \
147__HPP_ENTRY_PERCENT_FN(_type, _field)
Namhyung Kimea251d52012-09-03 11:53:06 +0900148
Namhyung Kim4fb71072013-01-22 18:09:34 +0900149#define HPP_RAW_FNS(_type, _str, _field, _min_width, _unit_width) \
150__HPP_HEADER_FN(_type, _str, _min_width, _unit_width) \
151__HPP_WIDTH_FN(_type, _min_width, _unit_width) \
152__HPP_ENTRY_RAW_FN(_type, _field)
Jiri Olsab5ff71c2012-10-04 21:49:40 +0900153
Namhyung Kimea251d52012-09-03 11:53:06 +0900154
Namhyung Kim4fb71072013-01-22 18:09:34 +0900155HPP_PERCENT_FNS(overhead, "Overhead", period, 8, 8)
156HPP_PERCENT_FNS(overhead_sys, "sys", period_sys, 8, 8)
157HPP_PERCENT_FNS(overhead_us, "usr", period_us, 8, 8)
158HPP_PERCENT_FNS(overhead_guest_sys, "guest sys", period_guest_sys, 9, 8)
159HPP_PERCENT_FNS(overhead_guest_us, "guest usr", period_guest_us, 9, 8)
Namhyung Kim9ffad982012-09-03 11:53:07 +0900160
Namhyung Kim4fb71072013-01-22 18:09:34 +0900161HPP_RAW_FNS(samples, "Samples", nr_events, 12, 12)
162HPP_RAW_FNS(period, "Period", period, 12, 12)
Namhyung Kimea251d52012-09-03 11:53:06 +0900163
Namhyung Kimea251d52012-09-03 11:53:06 +0900164
Jiri Olsa5395a042012-10-04 21:49:37 +0900165static int hpp__header_baseline(struct perf_hpp *hpp)
166{
167 return scnprintf(hpp->buf, hpp->size, "Baseline");
168}
169
170static int hpp__width_baseline(struct perf_hpp *hpp __maybe_unused)
171{
172 return 8;
173}
174
175static double baseline_percent(struct hist_entry *he)
176{
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200177 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa5395a042012-10-04 21:49:37 +0900178 struct hists *pair_hists = pair ? pair->hists : NULL;
179 double percent = 0.0;
180
181 if (pair) {
182 u64 total_period = pair_hists->stats.total_period;
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900183 u64 base_period = pair->stat.period;
Jiri Olsa5395a042012-10-04 21:49:37 +0900184
185 percent = 100.0 * base_period / total_period;
186 }
187
188 return percent;
189}
190
191static int hpp__color_baseline(struct perf_hpp *hpp, struct hist_entry *he)
192{
193 double percent = baseline_percent(he);
194
Namhyung Kim4fb71072013-01-22 18:09:34 +0900195 if (hist_entry__has_pairs(he) || symbol_conf.field_sep)
Jiri Olsa6e923492012-10-05 16:44:47 +0200196 return percent_color_snprintf(hpp->buf, hpp->size, " %6.2f%%", percent);
197 else
198 return scnprintf(hpp->buf, hpp->size, " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900199}
200
201static int hpp__entry_baseline(struct perf_hpp *hpp, struct hist_entry *he)
202{
203 double percent = baseline_percent(he);
204 const char *fmt = symbol_conf.field_sep ? "%.2f" : " %6.2f%%";
205
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200206 if (hist_entry__has_pairs(he) || symbol_conf.field_sep)
Jiri Olsa6e923492012-10-05 16:44:47 +0200207 return scnprintf(hpp->buf, hpp->size, fmt, percent);
208 else
209 return scnprintf(hpp->buf, hpp->size, " ");
Jiri Olsa5395a042012-10-04 21:49:37 +0900210}
211
Jiri Olsa61949b22012-10-05 16:44:44 +0200212static int hpp__header_period_baseline(struct perf_hpp *hpp)
213{
214 const char *fmt = symbol_conf.field_sep ? "%s" : "%12s";
215
216 return scnprintf(hpp->buf, hpp->size, fmt, "Period Base");
217}
218
219static int hpp__width_period_baseline(struct perf_hpp *hpp __maybe_unused)
220{
221 return 12;
222}
223
224static int hpp__entry_period_baseline(struct perf_hpp *hpp, struct hist_entry *he)
225{
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200226 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa61949b22012-10-05 16:44:44 +0200227 u64 period = pair ? pair->stat.period : 0;
228 const char *fmt = symbol_conf.field_sep ? "%" PRIu64 : "%12" PRIu64;
229
230 return scnprintf(hpp->buf, hpp->size, fmt, period);
231}
Namhyung Kim4fb71072013-01-22 18:09:34 +0900232
Namhyung Kimea251d52012-09-03 11:53:06 +0900233static int hpp__header_delta(struct perf_hpp *hpp)
234{
Namhyung Kim9ffad982012-09-03 11:53:07 +0900235 const char *fmt = symbol_conf.field_sep ? "%s" : "%7s";
236
237 return scnprintf(hpp->buf, hpp->size, fmt, "Delta");
Namhyung Kimea251d52012-09-03 11:53:06 +0900238}
239
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300240static int hpp__width_delta(struct perf_hpp *hpp __maybe_unused)
Namhyung Kimea251d52012-09-03 11:53:06 +0900241{
242 return 7;
243}
244
245static int hpp__entry_delta(struct perf_hpp *hpp, struct hist_entry *he)
246{
Jiri Olsa05472da2012-11-28 14:52:40 +0100247 struct hist_entry *pair = hist_entry__next_pair(he);
Namhyung Kim9ffad982012-09-03 11:53:07 +0900248 const char *fmt = symbol_conf.field_sep ? "%s" : "%7.7s";
249 char buf[32] = " ";
Jiri Olsa05472da2012-11-28 14:52:40 +0100250 double diff = 0.0;
Namhyung Kimea251d52012-09-03 11:53:06 +0900251
Jiri Olsa05472da2012-11-28 14:52:40 +0100252 if (pair) {
253 if (he->diff.computed)
254 diff = he->diff.period_ratio_delta;
255 else
256 diff = perf_diff__compute_delta(he, pair);
257 } else
258 diff = perf_diff__period_percent(he, he->stat.period);
Namhyung Kimea251d52012-09-03 11:53:06 +0900259
Namhyung Kim9ffad982012-09-03 11:53:07 +0900260 if (fabs(diff) >= 0.01)
261 scnprintf(buf, sizeof(buf), "%+4.2F%%", diff);
Namhyung Kimea251d52012-09-03 11:53:06 +0900262
Namhyung Kim9ffad982012-09-03 11:53:07 +0900263 return scnprintf(hpp->buf, hpp->size, fmt, buf);
Namhyung Kimea251d52012-09-03 11:53:06 +0900264}
265
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200266static int hpp__header_ratio(struct perf_hpp *hpp)
267{
268 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
269
270 return scnprintf(hpp->buf, hpp->size, fmt, "Ratio");
271}
272
273static int hpp__width_ratio(struct perf_hpp *hpp __maybe_unused)
274{
275 return 14;
276}
277
278static int hpp__entry_ratio(struct perf_hpp *hpp, struct hist_entry *he)
279{
Jiri Olsa05472da2012-11-28 14:52:40 +0100280 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200281 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
282 char buf[32] = " ";
Jiri Olsa05472da2012-11-28 14:52:40 +0100283 double ratio = 0.0;
Jiri Olsa96c47f12012-10-05 16:44:42 +0200284
Jiri Olsa05472da2012-11-28 14:52:40 +0100285 if (pair) {
286 if (he->diff.computed)
287 ratio = he->diff.period_ratio;
288 else
289 ratio = perf_diff__compute_ratio(he, pair);
290 }
Jiri Olsa7aaf6b32012-10-05 16:44:41 +0200291
292 if (ratio > 0.0)
293 scnprintf(buf, sizeof(buf), "%+14.6F", ratio);
294
295 return scnprintf(hpp->buf, hpp->size, fmt, buf);
296}
297
Jiri Olsa81d5f952012-10-05 16:44:43 +0200298static int hpp__header_wdiff(struct perf_hpp *hpp)
299{
300 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
301
302 return scnprintf(hpp->buf, hpp->size, fmt, "Weighted diff");
303}
304
305static int hpp__width_wdiff(struct perf_hpp *hpp __maybe_unused)
306{
307 return 14;
308}
309
310static int hpp__entry_wdiff(struct perf_hpp *hpp, struct hist_entry *he)
311{
Jiri Olsa05472da2012-11-28 14:52:40 +0100312 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsa81d5f952012-10-05 16:44:43 +0200313 const char *fmt = symbol_conf.field_sep ? "%s" : "%14s";
314 char buf[32] = " ";
Jiri Olsa05472da2012-11-28 14:52:40 +0100315 s64 wdiff = 0;
Jiri Olsa81d5f952012-10-05 16:44:43 +0200316
Jiri Olsa05472da2012-11-28 14:52:40 +0100317 if (pair) {
318 if (he->diff.computed)
319 wdiff = he->diff.wdiff;
320 else
321 wdiff = perf_diff__compute_wdiff(he, pair);
322 }
Jiri Olsa81d5f952012-10-05 16:44:43 +0200323
324 if (wdiff != 0)
325 scnprintf(buf, sizeof(buf), "%14ld", wdiff);
326
327 return scnprintf(hpp->buf, hpp->size, fmt, buf);
328}
329
Jiri Olsaed279da2012-10-05 16:44:45 +0200330static int hpp__header_formula(struct perf_hpp *hpp)
331{
332 const char *fmt = symbol_conf.field_sep ? "%s" : "%70s";
333
334 return scnprintf(hpp->buf, hpp->size, fmt, "Formula");
335}
336
337static int hpp__width_formula(struct perf_hpp *hpp __maybe_unused)
338{
339 return 70;
340}
341
342static int hpp__entry_formula(struct perf_hpp *hpp, struct hist_entry *he)
343{
Jiri Olsaf4c8bae2012-11-28 14:52:41 +0100344 struct hist_entry *pair = hist_entry__next_pair(he);
Jiri Olsaed279da2012-10-05 16:44:45 +0200345 const char *fmt = symbol_conf.field_sep ? "%s" : "%-70s";
346 char buf[96] = " ";
347
Jiri Olsaf4c8bae2012-11-28 14:52:41 +0100348 if (pair)
349 perf_diff__formula(he, pair, buf, sizeof(buf));
350
Jiri Olsaed279da2012-10-05 16:44:45 +0200351 return scnprintf(hpp->buf, hpp->size, fmt, buf);
352}
353
Jiri Olsa12400052012-10-13 00:06:16 +0200354#define HPP__COLOR_PRINT_FNS(_name) \
355 { \
356 .header = hpp__header_ ## _name, \
357 .width = hpp__width_ ## _name, \
358 .color = hpp__color_ ## _name, \
359 .entry = hpp__entry_ ## _name \
360 }
Namhyung Kimea251d52012-09-03 11:53:06 +0900361
Jiri Olsa12400052012-10-13 00:06:16 +0200362#define HPP__PRINT_FNS(_name) \
363 { \
364 .header = hpp__header_ ## _name, \
365 .width = hpp__width_ ## _name, \
366 .entry = hpp__entry_ ## _name \
367 }
Namhyung Kimea251d52012-09-03 11:53:06 +0900368
369struct perf_hpp_fmt perf_hpp__format[] = {
Jiri Olsa12400052012-10-13 00:06:16 +0200370 HPP__COLOR_PRINT_FNS(baseline),
371 HPP__COLOR_PRINT_FNS(overhead),
372 HPP__COLOR_PRINT_FNS(overhead_sys),
373 HPP__COLOR_PRINT_FNS(overhead_us),
374 HPP__COLOR_PRINT_FNS(overhead_guest_sys),
375 HPP__COLOR_PRINT_FNS(overhead_guest_us),
376 HPP__PRINT_FNS(samples),
377 HPP__PRINT_FNS(period),
378 HPP__PRINT_FNS(period_baseline),
379 HPP__PRINT_FNS(delta),
380 HPP__PRINT_FNS(ratio),
381 HPP__PRINT_FNS(wdiff),
Jiri Olsa12400052012-10-13 00:06:16 +0200382 HPP__PRINT_FNS(formula)
Namhyung Kimea251d52012-09-03 11:53:06 +0900383};
384
Jiri Olsa12400052012-10-13 00:06:16 +0200385LIST_HEAD(perf_hpp__list);
386
Namhyung Kim4fb71072013-01-22 18:09:34 +0900387
Namhyung Kimea251d52012-09-03 11:53:06 +0900388#undef HPP__COLOR_PRINT_FNS
389#undef HPP__PRINT_FNS
390
Namhyung Kim4fb71072013-01-22 18:09:34 +0900391#undef HPP_PERCENT_FNS
392#undef HPP_RAW_FNS
393
394#undef __HPP_HEADER_FN
395#undef __HPP_WIDTH_FN
396#undef __HPP_COLOR_PERCENT_FN
397#undef __HPP_ENTRY_PERCENT_FN
398#undef __HPP_ENTRY_RAW_FN
399
400
Jiri Olsa1d778222012-10-04 21:49:39 +0900401void perf_hpp__init(void)
Namhyung Kimea251d52012-09-03 11:53:06 +0900402{
403 if (symbol_conf.show_cpu_utilization) {
Jiri Olsa12400052012-10-13 00:06:16 +0200404 perf_hpp__column_enable(PERF_HPP__OVERHEAD_SYS);
405 perf_hpp__column_enable(PERF_HPP__OVERHEAD_US);
Namhyung Kimea251d52012-09-03 11:53:06 +0900406
407 if (perf_guest) {
Jiri Olsa12400052012-10-13 00:06:16 +0200408 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_SYS);
409 perf_hpp__column_enable(PERF_HPP__OVERHEAD_GUEST_US);
Namhyung Kimea251d52012-09-03 11:53:06 +0900410 }
411 }
412
413 if (symbol_conf.show_nr_samples)
Jiri Olsa12400052012-10-13 00:06:16 +0200414 perf_hpp__column_enable(PERF_HPP__SAMPLES);
Namhyung Kimea251d52012-09-03 11:53:06 +0900415
416 if (symbol_conf.show_total_period)
Jiri Olsa12400052012-10-13 00:06:16 +0200417 perf_hpp__column_enable(PERF_HPP__PERIOD);
Jiri Olsa1d778222012-10-04 21:49:39 +0900418}
Namhyung Kimea251d52012-09-03 11:53:06 +0900419
Jiri Olsa12400052012-10-13 00:06:16 +0200420void perf_hpp__column_register(struct perf_hpp_fmt *format)
421{
422 list_add_tail(&format->list, &perf_hpp__list);
423}
424
425void perf_hpp__column_enable(unsigned col)
Jiri Olsa1d778222012-10-04 21:49:39 +0900426{
427 BUG_ON(col >= PERF_HPP__MAX_INDEX);
Jiri Olsa12400052012-10-13 00:06:16 +0200428 perf_hpp__column_register(&perf_hpp__format[col]);
Namhyung Kimea251d52012-09-03 11:53:06 +0900429}
430
431static inline void advance_hpp(struct perf_hpp *hpp, int inc)
432{
433 hpp->buf += inc;
434 hpp->size -= inc;
435}
436
437int hist_entry__period_snprintf(struct perf_hpp *hpp, struct hist_entry *he,
438 bool color)
439{
440 const char *sep = symbol_conf.field_sep;
Jiri Olsa12400052012-10-13 00:06:16 +0200441 struct perf_hpp_fmt *fmt;
Namhyung Kimea251d52012-09-03 11:53:06 +0900442 char *start = hpp->buf;
Jiri Olsa12400052012-10-13 00:06:16 +0200443 int ret;
Jiri Olsa5395a042012-10-04 21:49:37 +0900444 bool first = true;
Namhyung Kimea251d52012-09-03 11:53:06 +0900445
446 if (symbol_conf.exclude_other && !he->parent)
447 return 0;
448
Jiri Olsa12400052012-10-13 00:06:16 +0200449 perf_hpp__for_each_format(fmt) {
Jiri Olsac0d246b2012-10-20 22:14:10 +0200450 /*
451 * If there's no field_sep, we still need
452 * to display initial ' '.
453 */
Jiri Olsa5395a042012-10-04 21:49:37 +0900454 if (!sep || !first) {
Namhyung Kimea251d52012-09-03 11:53:06 +0900455 ret = scnprintf(hpp->buf, hpp->size, "%s", sep ?: " ");
456 advance_hpp(hpp, ret);
Jiri Olsac0d246b2012-10-20 22:14:10 +0200457 } else
Jiri Olsa5395a042012-10-04 21:49:37 +0900458 first = false;
Namhyung Kimea251d52012-09-03 11:53:06 +0900459
Jiri Olsa12400052012-10-13 00:06:16 +0200460 if (color && fmt->color)
461 ret = fmt->color(hpp, he);
Namhyung Kimea251d52012-09-03 11:53:06 +0900462 else
Jiri Olsa12400052012-10-13 00:06:16 +0200463 ret = fmt->entry(hpp, he);
Namhyung Kimea251d52012-09-03 11:53:06 +0900464
465 advance_hpp(hpp, ret);
466 }
467
468 return hpp->buf - start;
469}
470
471int hist_entry__sort_snprintf(struct hist_entry *he, char *s, size_t size,
472 struct hists *hists)
473{
474 const char *sep = symbol_conf.field_sep;
475 struct sort_entry *se;
476 int ret = 0;
477
478 list_for_each_entry(se, &hist_entry__sort_list, list) {
479 if (se->elide)
480 continue;
481
482 ret += scnprintf(s + ret, size - ret, "%s", sep ?: " ");
483 ret += se->se_snprintf(he, s + ret, size - ret,
484 hists__col_len(hists, se->se_width_idx));
485 }
486
487 return ret;
488}
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900489
490/*
491 * See hists__fprintf to match the column widths
492 */
493unsigned int hists__sort_list_width(struct hists *hists)
494{
Jiri Olsa12400052012-10-13 00:06:16 +0200495 struct perf_hpp_fmt *fmt;
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900496 struct sort_entry *se;
Jiri Olsa12400052012-10-13 00:06:16 +0200497 int i = 0, ret = 0;
Namhyung Kim5b9e2142013-01-22 18:09:37 +0900498 struct perf_hpp dummy_hpp = {
499 .ptr = hists_to_evsel(hists),
500 };
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900501
Jiri Olsa12400052012-10-13 00:06:16 +0200502 perf_hpp__for_each_format(fmt) {
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900503 if (i)
504 ret += 2;
505
Namhyung Kim5b9e2142013-01-22 18:09:37 +0900506 ret += fmt->width(&dummy_hpp);
Namhyung Kim7e62ef42012-09-03 11:53:08 +0900507 }
508
509 list_for_each_entry(se, &hist_entry__sort_list, list)
510 if (!se->elide)
511 ret += 2 + hists__col_len(hists, se->se_width_idx);
512
513 if (verbose) /* Addr + origin */
514 ret += 3 + BITS_PER_LONG / 4;
515
516 return ret;
517}