perf hist: Introduce hists class and move lots of methods to it
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / tools / perf / util / hist.c
CommitLineData
3d1d07ec 1#include "hist.h"
4e4f06e4
ACM
2#include "session.h"
3#include "sort.h"
9b33827d 4#include <math.h>
3d1d07ec
JK
5
6struct callchain_param callchain_param = {
7 .mode = CHAIN_GRAPH_REL,
8 .min_percent = 0.5
9};
10
1c02c4d2
ACM
11static void hist_entry__add_cpumode_count(struct hist_entry *self,
12 unsigned int cpumode, u64 count)
a1645ce1 13{
28e2a106 14 switch (cpumode) {
a1645ce1 15 case PERF_RECORD_MISC_KERNEL:
1c02c4d2 16 self->count_sys += count;
a1645ce1
ZY
17 break;
18 case PERF_RECORD_MISC_USER:
1c02c4d2 19 self->count_us += count;
a1645ce1
ZY
20 break;
21 case PERF_RECORD_MISC_GUEST_KERNEL:
1c02c4d2 22 self->count_guest_sys += count;
a1645ce1
ZY
23 break;
24 case PERF_RECORD_MISC_GUEST_USER:
1c02c4d2 25 self->count_guest_us += count;
a1645ce1
ZY
26 break;
27 default:
28 break;
29 }
30}
31
3d1d07ec
JK
32/*
33 * histogram, sorted on item, collects counts
34 */
35
28e2a106
ACM
36static struct hist_entry *hist_entry__new(struct hist_entry *template)
37{
38 size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_node) : 0;
39 struct hist_entry *self = malloc(sizeof(*self) + callchain_size);
40
41 if (self != NULL) {
42 *self = *template;
43 if (symbol_conf.use_callchain)
44 callchain_init(self->callchain);
45 }
46
47 return self;
48}
49
1c02c4d2
ACM
50struct hist_entry *__hists__add_entry(struct hists *self,
51 struct addr_location *al,
52 struct symbol *sym_parent, u64 count)
9735abf1 53{
1c02c4d2 54 struct rb_node **p = &self->entries.rb_node;
9735abf1
ACM
55 struct rb_node *parent = NULL;
56 struct hist_entry *he;
57 struct hist_entry entry = {
1ed091c4 58 .thread = al->thread,
59fd5306
ACM
59 .ms = {
60 .map = al->map,
61 .sym = al->sym,
62 },
1ed091c4
ACM
63 .ip = al->addr,
64 .level = al->level,
9735abf1
ACM
65 .count = count,
66 .parent = sym_parent,
67 };
68 int cmp;
69
70 while (*p != NULL) {
71 parent = *p;
72 he = rb_entry(parent, struct hist_entry, rb_node);
73
74 cmp = hist_entry__cmp(&entry, he);
75
76 if (!cmp) {
28e2a106
ACM
77 he->count += count;
78 goto out;
9735abf1
ACM
79 }
80
81 if (cmp < 0)
82 p = &(*p)->rb_left;
83 else
84 p = &(*p)->rb_right;
85 }
86
28e2a106 87 he = hist_entry__new(&entry);
9735abf1
ACM
88 if (!he)
89 return NULL;
9735abf1 90 rb_link_node(&he->rb_node, parent, p);
1c02c4d2 91 rb_insert_color(&he->rb_node, &self->entries);
28e2a106 92out:
1c02c4d2 93 hist_entry__add_cpumode_count(he, al->cpumode, count);
9735abf1
ACM
94 return he;
95}
96
3d1d07ec
JK
97int64_t
98hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
99{
100 struct sort_entry *se;
101 int64_t cmp = 0;
102
103 list_for_each_entry(se, &hist_entry__sort_list, list) {
fcd14984 104 cmp = se->se_cmp(left, right);
3d1d07ec
JK
105 if (cmp)
106 break;
107 }
108
109 return cmp;
110}
111
112int64_t
113hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
114{
115 struct sort_entry *se;
116 int64_t cmp = 0;
117
118 list_for_each_entry(se, &hist_entry__sort_list, list) {
119 int64_t (*f)(struct hist_entry *, struct hist_entry *);
120
fcd14984 121 f = se->se_collapse ?: se->se_cmp;
3d1d07ec
JK
122
123 cmp = f(left, right);
124 if (cmp)
125 break;
126 }
127
128 return cmp;
129}
130
131void hist_entry__free(struct hist_entry *he)
132{
133 free(he);
134}
135
136/*
137 * collapse the histogram
138 */
139
b9bf0892 140static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
3d1d07ec 141{
b9bf0892 142 struct rb_node **p = &root->rb_node;
3d1d07ec
JK
143 struct rb_node *parent = NULL;
144 struct hist_entry *iter;
145 int64_t cmp;
146
147 while (*p != NULL) {
148 parent = *p;
149 iter = rb_entry(parent, struct hist_entry, rb_node);
150
151 cmp = hist_entry__collapse(iter, he);
152
153 if (!cmp) {
154 iter->count += he->count;
155 hist_entry__free(he);
156 return;
157 }
158
159 if (cmp < 0)
160 p = &(*p)->rb_left;
161 else
162 p = &(*p)->rb_right;
163 }
164
165 rb_link_node(&he->rb_node, parent, p);
b9bf0892 166 rb_insert_color(&he->rb_node, root);
3d1d07ec
JK
167}
168
1c02c4d2 169void hists__collapse_resort(struct hists *self)
3d1d07ec 170{
b9bf0892 171 struct rb_root tmp;
3d1d07ec
JK
172 struct rb_node *next;
173 struct hist_entry *n;
174
175 if (!sort__need_collapse)
176 return;
177
b9bf0892 178 tmp = RB_ROOT;
1c02c4d2 179 next = rb_first(&self->entries);
b9bf0892 180
3d1d07ec
JK
181 while (next) {
182 n = rb_entry(next, struct hist_entry, rb_node);
183 next = rb_next(&n->rb_node);
184
1c02c4d2 185 rb_erase(&n->rb_node, &self->entries);
b9bf0892 186 collapse__insert_entry(&tmp, n);
3d1d07ec 187 }
b9bf0892 188
1c02c4d2 189 self->entries = tmp;
3d1d07ec
JK
190}
191
192/*
193 * reverse the map, sort on count.
194 */
195
1c02c4d2
ACM
196static void __hists__insert_output_entry(struct rb_root *entries,
197 struct hist_entry *he,
198 u64 min_callchain_hits)
3d1d07ec 199{
1c02c4d2 200 struct rb_node **p = &entries->rb_node;
3d1d07ec
JK
201 struct rb_node *parent = NULL;
202 struct hist_entry *iter;
203
d599db3f 204 if (symbol_conf.use_callchain)
b9fb9304 205 callchain_param.sort(&he->sorted_chain, he->callchain,
3d1d07ec
JK
206 min_callchain_hits, &callchain_param);
207
208 while (*p != NULL) {
209 parent = *p;
210 iter = rb_entry(parent, struct hist_entry, rb_node);
211
212 if (he->count > iter->count)
213 p = &(*p)->rb_left;
214 else
215 p = &(*p)->rb_right;
216 }
217
218 rb_link_node(&he->rb_node, parent, p);
1c02c4d2 219 rb_insert_color(&he->rb_node, entries);
3d1d07ec
JK
220}
221
1c02c4d2 222u64 hists__output_resort(struct hists *self)
3d1d07ec 223{
b9bf0892 224 struct rb_root tmp;
3d1d07ec
JK
225 struct rb_node *next;
226 struct hist_entry *n;
3d1d07ec 227 u64 min_callchain_hits;
5f4d3f88 228 u64 nr_hists = 0;
3d1d07ec 229
1c02c4d2 230 min_callchain_hits = self->stats.total * (callchain_param.min_percent / 100);
3d1d07ec 231
b9bf0892 232 tmp = RB_ROOT;
1c02c4d2 233 next = rb_first(&self->entries);
3d1d07ec
JK
234
235 while (next) {
236 n = rb_entry(next, struct hist_entry, rb_node);
237 next = rb_next(&n->rb_node);
238
1c02c4d2
ACM
239 rb_erase(&n->rb_node, &self->entries);
240 __hists__insert_output_entry(&tmp, n, min_callchain_hits);
5f4d3f88 241 ++nr_hists;
3d1d07ec 242 }
b9bf0892 243
1c02c4d2 244 self->entries = tmp;
5f4d3f88 245 return nr_hists;
3d1d07ec 246}
4ecf84d0
ACM
247
248static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
249{
250 int i;
251 int ret = fprintf(fp, " ");
252
253 for (i = 0; i < left_margin; i++)
254 ret += fprintf(fp, " ");
255
256 return ret;
257}
258
259static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
260 int left_margin)
261{
262 int i;
263 size_t ret = callchain__fprintf_left_margin(fp, left_margin);
264
265 for (i = 0; i < depth; i++)
266 if (depth_mask & (1 << i))
267 ret += fprintf(fp, "| ");
268 else
269 ret += fprintf(fp, " ");
270
271 ret += fprintf(fp, "\n");
272
273 return ret;
274}
275
276static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
277 int depth, int depth_mask, int count,
278 u64 total_samples, int hits,
279 int left_margin)
280{
281 int i;
282 size_t ret = 0;
283
284 ret += callchain__fprintf_left_margin(fp, left_margin);
285 for (i = 0; i < depth; i++) {
286 if (depth_mask & (1 << i))
287 ret += fprintf(fp, "|");
288 else
289 ret += fprintf(fp, " ");
290 if (!count && i == depth - 1) {
291 double percent;
292
293 percent = hits * 100.0 / total_samples;
294 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
295 } else
296 ret += fprintf(fp, "%s", " ");
297 }
b3c9ac08
ACM
298 if (chain->ms.sym)
299 ret += fprintf(fp, "%s\n", chain->ms.sym->name);
4ecf84d0
ACM
300 else
301 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
302
303 return ret;
304}
305
306static struct symbol *rem_sq_bracket;
307static struct callchain_list rem_hits;
308
309static void init_rem_hits(void)
310{
311 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
312 if (!rem_sq_bracket) {
313 fprintf(stderr, "Not enough memory to display remaining hits\n");
314 return;
315 }
316
317 strcpy(rem_sq_bracket->name, "[...]");
b3c9ac08 318 rem_hits.ms.sym = rem_sq_bracket;
4ecf84d0
ACM
319}
320
321static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
322 u64 total_samples, int depth,
323 int depth_mask, int left_margin)
324{
325 struct rb_node *node, *next;
326 struct callchain_node *child;
327 struct callchain_list *chain;
328 int new_depth_mask = depth_mask;
329 u64 new_total;
330 u64 remaining;
331 size_t ret = 0;
332 int i;
232a5c94 333 uint entries_printed = 0;
4ecf84d0
ACM
334
335 if (callchain_param.mode == CHAIN_GRAPH_REL)
336 new_total = self->children_hit;
337 else
338 new_total = total_samples;
339
340 remaining = new_total;
341
342 node = rb_first(&self->rb_root);
343 while (node) {
344 u64 cumul;
345
346 child = rb_entry(node, struct callchain_node, rb_node);
347 cumul = cumul_hits(child);
348 remaining -= cumul;
349
350 /*
351 * The depth mask manages the output of pipes that show
352 * the depth. We don't want to keep the pipes of the current
353 * level for the last child of this depth.
354 * Except if we have remaining filtered hits. They will
355 * supersede the last child
356 */
357 next = rb_next(node);
358 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
359 new_depth_mask &= ~(1 << (depth - 1));
360
361 /*
3ad2f3fb 362 * But we keep the older depth mask for the line separator
4ecf84d0
ACM
363 * to keep the level link until we reach the last child
364 */
365 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
366 left_margin);
367 i = 0;
368 list_for_each_entry(chain, &child->val, list) {
4ecf84d0
ACM
369 ret += ipchain__fprintf_graph(fp, chain, depth,
370 new_depth_mask, i++,
371 new_total,
372 cumul,
373 left_margin);
374 }
375 ret += __callchain__fprintf_graph(fp, child, new_total,
376 depth + 1,
377 new_depth_mask | (1 << depth),
378 left_margin);
379 node = next;
232a5c94
ACM
380 if (++entries_printed == callchain_param.print_limit)
381 break;
4ecf84d0
ACM
382 }
383
384 if (callchain_param.mode == CHAIN_GRAPH_REL &&
385 remaining && remaining != new_total) {
386
387 if (!rem_sq_bracket)
388 return ret;
389
390 new_depth_mask &= ~(1 << (depth - 1));
391
392 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
393 new_depth_mask, 0, new_total,
394 remaining, left_margin);
395 }
396
397 return ret;
398}
399
400static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
401 u64 total_samples, int left_margin)
402{
403 struct callchain_list *chain;
404 bool printed = false;
405 int i = 0;
406 int ret = 0;
232a5c94 407 u32 entries_printed = 0;
4ecf84d0
ACM
408
409 list_for_each_entry(chain, &self->val, list) {
4ecf84d0
ACM
410 if (!i++ && sort__first_dimension == SORT_SYM)
411 continue;
412
413 if (!printed) {
414 ret += callchain__fprintf_left_margin(fp, left_margin);
415 ret += fprintf(fp, "|\n");
416 ret += callchain__fprintf_left_margin(fp, left_margin);
417 ret += fprintf(fp, "---");
418
419 left_margin += 3;
420 printed = true;
421 } else
422 ret += callchain__fprintf_left_margin(fp, left_margin);
423
b3c9ac08
ACM
424 if (chain->ms.sym)
425 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
4ecf84d0
ACM
426 else
427 ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
232a5c94
ACM
428
429 if (++entries_printed == callchain_param.print_limit)
430 break;
4ecf84d0
ACM
431 }
432
433 ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
434
435 return ret;
436}
437
438static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
439 u64 total_samples)
440{
441 struct callchain_list *chain;
442 size_t ret = 0;
443
444 if (!self)
445 return 0;
446
447 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
448
449
450 list_for_each_entry(chain, &self->val, list) {
451 if (chain->ip >= PERF_CONTEXT_MAX)
452 continue;
b3c9ac08
ACM
453 if (chain->ms.sym)
454 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
4ecf84d0
ACM
455 else
456 ret += fprintf(fp, " %p\n",
457 (void *)(long)chain->ip);
458 }
459
460 return ret;
461}
462
463static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
464 u64 total_samples, int left_margin)
465{
466 struct rb_node *rb_node;
467 struct callchain_node *chain;
468 size_t ret = 0;
232a5c94 469 u32 entries_printed = 0;
4ecf84d0
ACM
470
471 rb_node = rb_first(&self->sorted_chain);
472 while (rb_node) {
473 double percent;
474
475 chain = rb_entry(rb_node, struct callchain_node, rb_node);
476 percent = chain->hit * 100.0 / total_samples;
477 switch (callchain_param.mode) {
478 case CHAIN_FLAT:
479 ret += percent_color_fprintf(fp, " %6.2f%%\n",
480 percent);
481 ret += callchain__fprintf_flat(fp, chain, total_samples);
482 break;
483 case CHAIN_GRAPH_ABS: /* Falldown */
484 case CHAIN_GRAPH_REL:
485 ret += callchain__fprintf_graph(fp, chain, total_samples,
486 left_margin);
487 case CHAIN_NONE:
488 default:
489 break;
490 }
491 ret += fprintf(fp, "\n");
232a5c94
ACM
492 if (++entries_printed == callchain_param.print_limit)
493 break;
4ecf84d0
ACM
494 rb_node = rb_next(rb_node);
495 }
496
497 return ret;
498}
499
1c02c4d2
ACM
500int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size,
501 struct hists *pair_hists, bool show_displacement,
502 long displacement, bool color, u64 session_total)
4ecf84d0
ACM
503{
504 struct sort_entry *se;
a1645ce1 505 u64 count, total, count_sys, count_us, count_guest_sys, count_guest_us;
c351c281 506 const char *sep = symbol_conf.field_sep;
a4e3b956 507 int ret;
4ecf84d0
ACM
508
509 if (symbol_conf.exclude_other && !self->parent)
510 return 0;
511
1c02c4d2 512 if (pair_hists) {
c351c281 513 count = self->pair ? self->pair->count : 0;
1c02c4d2 514 total = pair_hists->stats.total;
a1645ce1
ZY
515 count_sys = self->pair ? self->pair->count_sys : 0;
516 count_us = self->pair ? self->pair->count_us : 0;
517 count_guest_sys = self->pair ? self->pair->count_guest_sys : 0;
518 count_guest_us = self->pair ? self->pair->count_guest_us : 0;
c351c281
ACM
519 } else {
520 count = self->count;
eefc465c 521 total = session_total;
a1645ce1
ZY
522 count_sys = self->count_sys;
523 count_us = self->count_us;
524 count_guest_sys = self->count_guest_sys;
525 count_guest_us = self->count_guest_us;
c351c281
ACM
526 }
527
a4e3b956
ACM
528 if (total) {
529 if (color)
530 ret = percent_color_snprintf(s, size,
531 sep ? "%.2f" : " %6.2f%%",
532 (count * 100.0) / total);
533 else
534 ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%",
535 (count * 100.0) / total);
a1645ce1
ZY
536 if (symbol_conf.show_cpu_utilization) {
537 ret += percent_color_snprintf(s + ret, size - ret,
538 sep ? "%.2f" : " %6.2f%%",
539 (count_sys * 100.0) / total);
540 ret += percent_color_snprintf(s + ret, size - ret,
541 sep ? "%.2f" : " %6.2f%%",
542 (count_us * 100.0) / total);
543 if (perf_guest) {
544 ret += percent_color_snprintf(s + ret,
545 size - ret,
546 sep ? "%.2f" : " %6.2f%%",
547 (count_guest_sys * 100.0) /
548 total);
549 ret += percent_color_snprintf(s + ret,
550 size - ret,
551 sep ? "%.2f" : " %6.2f%%",
552 (count_guest_us * 100.0) /
553 total);
554 }
555 }
a4e3b956
ACM
556 } else
557 ret = snprintf(s, size, sep ? "%lld" : "%12lld ", count);
4ecf84d0
ACM
558
559 if (symbol_conf.show_nr_samples) {
c351c281 560 if (sep)
a4e3b956 561 ret += snprintf(s + ret, size - ret, "%c%lld", *sep, count);
4ecf84d0 562 else
a4e3b956 563 ret += snprintf(s + ret, size - ret, "%11lld", count);
c351c281
ACM
564 }
565
1c02c4d2 566 if (pair_hists) {
c351c281
ACM
567 char bf[32];
568 double old_percent = 0, new_percent = 0, diff;
569
570 if (total > 0)
9b33827d 571 old_percent = (count * 100.0) / total;
eefc465c
EM
572 if (session_total > 0)
573 new_percent = (self->count * 100.0) / session_total;
c351c281 574
9b33827d 575 diff = new_percent - old_percent;
c351c281 576
9b33827d 577 if (fabs(diff) >= 0.01)
c351c281
ACM
578 snprintf(bf, sizeof(bf), "%+4.2F%%", diff);
579 else
580 snprintf(bf, sizeof(bf), " ");
581
582 if (sep)
a4e3b956 583 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
c351c281 584 else
a4e3b956 585 ret += snprintf(s + ret, size - ret, "%11.11s", bf);
c351c281
ACM
586
587 if (show_displacement) {
588 if (displacement)
589 snprintf(bf, sizeof(bf), "%+4ld", displacement);
590 else
591 snprintf(bf, sizeof(bf), " ");
592
593 if (sep)
a4e3b956 594 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
c351c281 595 else
a4e3b956 596 ret += snprintf(s + ret, size - ret, "%6.6s", bf);
c351c281 597 }
4ecf84d0
ACM
598 }
599
600 list_for_each_entry(se, &hist_entry__sort_list, list) {
601 if (se->elide)
602 continue;
603
a4e3b956 604 ret += snprintf(s + ret, size - ret, "%s", sep ?: " ");
fcd14984
FW
605 ret += se->se_snprintf(self, s + ret, size - ret,
606 se->se_width ? *se->se_width : 0);
4ecf84d0
ACM
607 }
608
a4e3b956
ACM
609 return ret;
610}
611
1c02c4d2
ACM
612int hist_entry__fprintf(struct hist_entry *self, struct hists *pair_hists,
613 bool show_displacement, long displacement, FILE *fp,
a4e3b956
ACM
614 u64 session_total)
615{
616 char bf[512];
1c02c4d2 617 hist_entry__snprintf(self, bf, sizeof(bf), pair_hists,
a4e3b956
ACM
618 show_displacement, displacement,
619 true, session_total);
620 return fprintf(fp, "%s\n", bf);
3997d377 621}
4ecf84d0 622
3997d377
ACM
623static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp,
624 u64 session_total)
625{
626 int left_margin = 0;
4ecf84d0 627
3997d377
ACM
628 if (sort__first_dimension == SORT_COMM) {
629 struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
630 typeof(*se), list);
fcd14984 631 left_margin = se->se_width ? *se->se_width : 0;
3997d377 632 left_margin -= thread__comm_len(self->thread);
4ecf84d0
ACM
633 }
634
3997d377
ACM
635 return hist_entry_callchain__fprintf(fp, self, session_total,
636 left_margin);
4ecf84d0
ACM
637}
638
1c02c4d2
ACM
639size_t hists__fprintf(struct hists *self, struct hists *pair,
640 bool show_displacement, FILE *fp)
4ecf84d0 641{
4ecf84d0
ACM
642 struct sort_entry *se;
643 struct rb_node *nd;
644 size_t ret = 0;
c351c281
ACM
645 unsigned long position = 1;
646 long displacement = 0;
4ecf84d0 647 unsigned int width;
c351c281 648 const char *sep = symbol_conf.field_sep;
4ecf84d0
ACM
649 char *col_width = symbol_conf.col_width_list_str;
650
651 init_rem_hits();
652
c351c281
ACM
653 fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
654
4ecf84d0 655 if (symbol_conf.show_nr_samples) {
c351c281
ACM
656 if (sep)
657 fprintf(fp, "%cSamples", *sep);
4ecf84d0
ACM
658 else
659 fputs(" Samples ", fp);
660 }
c351c281 661
a1645ce1
ZY
662 if (symbol_conf.show_cpu_utilization) {
663 if (sep) {
664 ret += fprintf(fp, "%csys", *sep);
665 ret += fprintf(fp, "%cus", *sep);
666 if (perf_guest) {
667 ret += fprintf(fp, "%cguest sys", *sep);
668 ret += fprintf(fp, "%cguest us", *sep);
669 }
670 } else {
671 ret += fprintf(fp, " sys ");
672 ret += fprintf(fp, " us ");
673 if (perf_guest) {
674 ret += fprintf(fp, " guest sys ");
675 ret += fprintf(fp, " guest us ");
676 }
677 }
678 }
679
c351c281
ACM
680 if (pair) {
681 if (sep)
682 ret += fprintf(fp, "%cDelta", *sep);
683 else
684 ret += fprintf(fp, " Delta ");
685
686 if (show_displacement) {
687 if (sep)
688 ret += fprintf(fp, "%cDisplacement", *sep);
689 else
690 ret += fprintf(fp, " Displ");
691 }
692 }
693
4ecf84d0
ACM
694 list_for_each_entry(se, &hist_entry__sort_list, list) {
695 if (se->elide)
696 continue;
c351c281 697 if (sep) {
fcd14984 698 fprintf(fp, "%c%s", *sep, se->se_header);
4ecf84d0
ACM
699 continue;
700 }
fcd14984
FW
701 width = strlen(se->se_header);
702 if (se->se_width) {
4ecf84d0
ACM
703 if (symbol_conf.col_width_list_str) {
704 if (col_width) {
fcd14984 705 *se->se_width = atoi(col_width);
4ecf84d0
ACM
706 col_width = strchr(col_width, ',');
707 if (col_width)
708 ++col_width;
709 }
710 }
fcd14984 711 width = *se->se_width = max(*se->se_width, width);
4ecf84d0 712 }
fcd14984 713 fprintf(fp, " %*s", width, se->se_header);
4ecf84d0
ACM
714 }
715 fprintf(fp, "\n");
716
c351c281 717 if (sep)
4ecf84d0
ACM
718 goto print_entries;
719
720 fprintf(fp, "# ........");
721 if (symbol_conf.show_nr_samples)
722 fprintf(fp, " ..........");
c351c281
ACM
723 if (pair) {
724 fprintf(fp, " ..........");
725 if (show_displacement)
726 fprintf(fp, " .....");
727 }
4ecf84d0
ACM
728 list_for_each_entry(se, &hist_entry__sort_list, list) {
729 unsigned int i;
730
731 if (se->elide)
732 continue;
733
734 fprintf(fp, " ");
fcd14984
FW
735 if (se->se_width)
736 width = *se->se_width;
4ecf84d0 737 else
fcd14984 738 width = strlen(se->se_header);
4ecf84d0
ACM
739 for (i = 0; i < width; i++)
740 fprintf(fp, ".");
741 }
4ecf84d0 742
c351c281 743 fprintf(fp, "\n#\n");
4ecf84d0
ACM
744
745print_entries:
1c02c4d2 746 for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
c351c281
ACM
747 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
748
749 if (show_displacement) {
750 if (h->pair != NULL)
751 displacement = ((long)h->pair->position -
752 (long)position);
753 else
754 displacement = 0;
755 ++position;
756 }
eefc465c 757 ret += hist_entry__fprintf(h, pair, show_displacement,
1c02c4d2 758 displacement, fp, self->stats.total);
3997d377
ACM
759
760 if (symbol_conf.use_callchain)
1c02c4d2 761 ret += hist_entry__fprintf_callchain(h, fp, self->stats.total);
3997d377 762
59fd5306 763 if (h->ms.map == NULL && verbose > 1) {
65f2ed2b 764 __map_groups__fprintf_maps(&h->thread->mg,
c6e718ff 765 MAP__FUNCTION, verbose, fp);
65f2ed2b
ACM
766 fprintf(fp, "%.10s end\n", graph_dotted_line);
767 }
4ecf84d0
ACM
768 }
769
4ecf84d0
ACM
770 free(rem_sq_bracket);
771
772 return ret;
773}