15 struct callchain_param callchain_param
= {
16 .mode
= CHAIN_GRAPH_REL
,
21 u16
hists__col_len(struct hists
*hists
, enum hist_column col
)
23 return hists
->col_len
[col
];
26 void hists__set_col_len(struct hists
*hists
, enum hist_column col
, u16 len
)
28 hists
->col_len
[col
] = len
;
31 bool hists__new_col_len(struct hists
*hists
, enum hist_column col
, u16 len
)
33 if (len
> hists__col_len(hists
, col
)) {
34 hists__set_col_len(hists
, col
, len
);
40 static void hists__reset_col_len(struct hists
*hists
)
44 for (col
= 0; col
< HISTC_NR_COLS
; ++col
)
45 hists__set_col_len(hists
, col
, 0);
48 static void hists__calc_col_len(struct hists
*hists
, struct hist_entry
*h
)
53 hists__new_col_len(hists
, HISTC_SYMBOL
, h
->ms
.sym
->namelen
);
55 const unsigned int unresolved_col_width
= BITS_PER_LONG
/ 4;
57 if (hists__col_len(hists
, HISTC_DSO
) < unresolved_col_width
&&
58 !symbol_conf
.col_width_list_str
&& !symbol_conf
.field_sep
&&
59 !symbol_conf
.dso_list
)
60 hists__set_col_len(hists
, HISTC_DSO
,
61 unresolved_col_width
);
64 len
= thread__comm_len(h
->thread
);
65 if (hists__new_col_len(hists
, HISTC_COMM
, len
))
66 hists__set_col_len(hists
, HISTC_THREAD
, len
+ 6);
69 len
= dso__name_len(h
->ms
.map
->dso
);
70 hists__new_col_len(hists
, HISTC_DSO
, len
);
74 static void hist_entry__add_cpumode_period(struct hist_entry
*self
,
75 unsigned int cpumode
, u64 period
)
78 case PERF_RECORD_MISC_KERNEL
:
79 self
->period_sys
+= period
;
81 case PERF_RECORD_MISC_USER
:
82 self
->period_us
+= period
;
84 case PERF_RECORD_MISC_GUEST_KERNEL
:
85 self
->period_guest_sys
+= period
;
87 case PERF_RECORD_MISC_GUEST_USER
:
88 self
->period_guest_us
+= period
;
95 static void hist_entry__decay(struct hist_entry
*he
)
97 he
->period
= (he
->period
* 7) / 8;
98 he
->nr_events
= (he
->nr_events
* 7) / 8;
101 static bool hists__decay_entry(struct hists
*hists
, struct hist_entry
*he
)
105 hists
->stats
.total_period
-= he
->period
;
106 hist_entry__decay(he
);
107 hists
->stats
.total_period
+= he
->period
;
108 return he
->period
== 0;
111 void hists__decay_entries(struct hists
*hists
)
113 struct rb_node
*next
= rb_first(&hists
->entries
);
114 struct hist_entry
*n
;
117 n
= rb_entry(next
, struct hist_entry
, rb_node
);
118 next
= rb_next(&n
->rb_node
);
120 * We may be annotating this, for instance, so keep it here in
121 * case some it gets new samples, we'll eventually free it when
122 * the user stops browsing and it agains gets fully decayed.
124 if (hists__decay_entry(hists
, n
) && !n
->used
) {
125 rb_erase(&n
->rb_node
, &hists
->entries
);
127 if (sort__need_collapse
)
128 rb_erase(&n
->rb_node_in
, &hists
->entries_collapsed
);
137 * histogram, sorted on item, collects periods
140 static struct hist_entry
*hist_entry__new(struct hist_entry
*template)
142 size_t callchain_size
= symbol_conf
.use_callchain
? sizeof(struct callchain_root
) : 0;
143 struct hist_entry
*self
= malloc(sizeof(*self
) + callchain_size
);
149 self
->ms
.map
->referenced
= true;
150 if (symbol_conf
.use_callchain
)
151 callchain_init(self
->callchain
);
157 static void hists__inc_nr_entries(struct hists
*hists
, struct hist_entry
*h
)
160 hists__calc_col_len(hists
, h
);
162 hists
->stats
.total_period
+= h
->period
;
166 static u8
symbol__parent_filter(const struct symbol
*parent
)
168 if (symbol_conf
.exclude_other
&& parent
== NULL
)
169 return 1 << HIST_FILTER__PARENT
;
173 struct hist_entry
*__hists__add_entry(struct hists
*hists
,
174 struct addr_location
*al
,
175 struct symbol
*sym_parent
, u64 period
)
178 struct rb_node
*parent
= NULL
;
179 struct hist_entry
*he
;
180 struct hist_entry entry
= {
181 .thread
= al
->thread
,
190 .parent
= sym_parent
,
191 .filtered
= symbol__parent_filter(sym_parent
),
195 pthread_mutex_lock(&hists
->lock
);
197 p
= &hists
->entries_in
->rb_node
;
201 he
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
203 cmp
= hist_entry__cmp(&entry
, he
);
206 he
->period
+= period
;
217 he
= hist_entry__new(&entry
);
221 rb_link_node(&he
->rb_node_in
, parent
, p
);
222 rb_insert_color(&he
->rb_node_in
, hists
->entries_in
);
224 hist_entry__add_cpumode_period(he
, al
->cpumode
, period
);
226 pthread_mutex_unlock(&hists
->lock
);
231 hist_entry__cmp(struct hist_entry
*left
, struct hist_entry
*right
)
233 struct sort_entry
*se
;
236 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
237 cmp
= se
->se_cmp(left
, right
);
246 hist_entry__collapse(struct hist_entry
*left
, struct hist_entry
*right
)
248 struct sort_entry
*se
;
251 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
252 int64_t (*f
)(struct hist_entry
*, struct hist_entry
*);
254 f
= se
->se_collapse
?: se
->se_cmp
;
256 cmp
= f(left
, right
);
264 void hist_entry__free(struct hist_entry
*he
)
270 * collapse the histogram
273 static bool hists__collapse_insert_entry(struct hists
*hists
,
274 struct rb_root
*root
,
275 struct hist_entry
*he
)
277 struct rb_node
**p
= &root
->rb_node
;
278 struct rb_node
*parent
= NULL
;
279 struct hist_entry
*iter
;
284 iter
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
286 cmp
= hist_entry__collapse(iter
, he
);
289 iter
->period
+= he
->period
;
290 iter
->nr_events
+= he
->nr_events
;
291 if (symbol_conf
.use_callchain
) {
292 callchain_cursor_reset(&hists
->callchain_cursor
);
293 callchain_merge(&hists
->callchain_cursor
, iter
->callchain
,
296 hist_entry__free(he
);
306 rb_link_node(&he
->rb_node_in
, parent
, p
);
307 rb_insert_color(&he
->rb_node_in
, root
);
311 static struct rb_root
*hists__get_rotate_entries_in(struct hists
*hists
)
313 struct rb_root
*root
;
315 pthread_mutex_lock(&hists
->lock
);
317 root
= hists
->entries_in
;
318 if (++hists
->entries_in
> &hists
->entries_in_array
[1])
319 hists
->entries_in
= &hists
->entries_in_array
[0];
321 pthread_mutex_unlock(&hists
->lock
);
326 static void __hists__collapse_resort(struct hists
*hists
, bool threaded
)
328 struct rb_root
*root
;
329 struct rb_node
*next
;
330 struct hist_entry
*n
;
332 if (!sort__need_collapse
&& !threaded
)
335 root
= hists__get_rotate_entries_in(hists
);
336 next
= rb_first(root
);
337 hists
->stats
.total_period
= 0;
340 n
= rb_entry(next
, struct hist_entry
, rb_node_in
);
341 next
= rb_next(&n
->rb_node_in
);
343 rb_erase(&n
->rb_node_in
, root
);
344 if (hists__collapse_insert_entry(hists
, &hists
->entries_collapsed
, n
))
345 hists__inc_nr_entries(hists
, n
);
349 void hists__collapse_resort(struct hists
*hists
)
351 return __hists__collapse_resort(hists
, false);
354 void hists__collapse_resort_threaded(struct hists
*hists
)
356 return __hists__collapse_resort(hists
, true);
360 * reverse the map, sort on period.
363 static void __hists__insert_output_entry(struct rb_root
*entries
,
364 struct hist_entry
*he
,
365 u64 min_callchain_hits
)
367 struct rb_node
**p
= &entries
->rb_node
;
368 struct rb_node
*parent
= NULL
;
369 struct hist_entry
*iter
;
371 if (symbol_conf
.use_callchain
)
372 callchain_param
.sort(&he
->sorted_chain
, he
->callchain
,
373 min_callchain_hits
, &callchain_param
);
377 iter
= rb_entry(parent
, struct hist_entry
, rb_node
);
379 if (he
->period
> iter
->period
)
385 rb_link_node(&he
->rb_node
, parent
, p
);
386 rb_insert_color(&he
->rb_node
, entries
);
389 static void __hists__output_resort(struct hists
*hists
, bool threaded
)
391 struct rb_root
*root
;
392 struct rb_node
*next
;
393 struct hist_entry
*n
;
394 u64 min_callchain_hits
;
396 min_callchain_hits
= hists
->stats
.total_period
* (callchain_param
.min_percent
/ 100);
398 if (sort__need_collapse
|| threaded
)
399 root
= &hists
->entries_collapsed
;
401 root
= hists
->entries_in
;
403 next
= rb_first(root
);
404 hists
->entries
= RB_ROOT
;
406 hists
->nr_entries
= 0;
407 hists__reset_col_len(hists
);
410 n
= rb_entry(next
, struct hist_entry
, rb_node_in
);
411 next
= rb_next(&n
->rb_node_in
);
413 __hists__insert_output_entry(&hists
->entries
, n
, min_callchain_hits
);
414 hists__inc_nr_entries(hists
, n
);
418 void hists__output_resort(struct hists
*hists
)
420 return __hists__output_resort(hists
, false);
423 void hists__output_resort_threaded(struct hists
*hists
)
425 return __hists__output_resort(hists
, true);
428 static size_t callchain__fprintf_left_margin(FILE *fp
, int left_margin
)
431 int ret
= fprintf(fp
, " ");
433 for (i
= 0; i
< left_margin
; i
++)
434 ret
+= fprintf(fp
, " ");
439 static size_t ipchain__fprintf_graph_line(FILE *fp
, int depth
, int depth_mask
,
443 size_t ret
= callchain__fprintf_left_margin(fp
, left_margin
);
445 for (i
= 0; i
< depth
; i
++)
446 if (depth_mask
& (1 << i
))
447 ret
+= fprintf(fp
, "| ");
449 ret
+= fprintf(fp
, " ");
451 ret
+= fprintf(fp
, "\n");
456 static size_t ipchain__fprintf_graph(FILE *fp
, struct callchain_list
*chain
,
457 int depth
, int depth_mask
, int period
,
458 u64 total_samples
, u64 hits
,
464 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
465 for (i
= 0; i
< depth
; i
++) {
466 if (depth_mask
& (1 << i
))
467 ret
+= fprintf(fp
, "|");
469 ret
+= fprintf(fp
, " ");
470 if (!period
&& i
== depth
- 1) {
473 percent
= hits
* 100.0 / total_samples
;
474 ret
+= percent_color_fprintf(fp
, "--%2.2f%%-- ", percent
);
476 ret
+= fprintf(fp
, "%s", " ");
479 ret
+= fprintf(fp
, "%s\n", chain
->ms
.sym
->name
);
481 ret
+= fprintf(fp
, "%p\n", (void *)(long)chain
->ip
);
486 static struct symbol
*rem_sq_bracket
;
487 static struct callchain_list rem_hits
;
489 static void init_rem_hits(void)
491 rem_sq_bracket
= malloc(sizeof(*rem_sq_bracket
) + 6);
492 if (!rem_sq_bracket
) {
493 fprintf(stderr
, "Not enough memory to display remaining hits\n");
497 strcpy(rem_sq_bracket
->name
, "[...]");
498 rem_hits
.ms
.sym
= rem_sq_bracket
;
501 static size_t __callchain__fprintf_graph(FILE *fp
, struct callchain_node
*self
,
502 u64 total_samples
, int depth
,
503 int depth_mask
, int left_margin
)
505 struct rb_node
*node
, *next
;
506 struct callchain_node
*child
;
507 struct callchain_list
*chain
;
508 int new_depth_mask
= depth_mask
;
513 uint entries_printed
= 0;
515 if (callchain_param
.mode
== CHAIN_GRAPH_REL
)
516 new_total
= self
->children_hit
;
518 new_total
= total_samples
;
520 remaining
= new_total
;
522 node
= rb_first(&self
->rb_root
);
526 child
= rb_entry(node
, struct callchain_node
, rb_node
);
527 cumul
= callchain_cumul_hits(child
);
531 * The depth mask manages the output of pipes that show
532 * the depth. We don't want to keep the pipes of the current
533 * level for the last child of this depth.
534 * Except if we have remaining filtered hits. They will
535 * supersede the last child
537 next
= rb_next(node
);
538 if (!next
&& (callchain_param
.mode
!= CHAIN_GRAPH_REL
|| !remaining
))
539 new_depth_mask
&= ~(1 << (depth
- 1));
542 * But we keep the older depth mask for the line separator
543 * to keep the level link until we reach the last child
545 ret
+= ipchain__fprintf_graph_line(fp
, depth
, depth_mask
,
548 list_for_each_entry(chain
, &child
->val
, list
) {
549 ret
+= ipchain__fprintf_graph(fp
, chain
, depth
,
555 ret
+= __callchain__fprintf_graph(fp
, child
, new_total
,
557 new_depth_mask
| (1 << depth
),
560 if (++entries_printed
== callchain_param
.print_limit
)
564 if (callchain_param
.mode
== CHAIN_GRAPH_REL
&&
565 remaining
&& remaining
!= new_total
) {
570 new_depth_mask
&= ~(1 << (depth
- 1));
572 ret
+= ipchain__fprintf_graph(fp
, &rem_hits
, depth
,
573 new_depth_mask
, 0, new_total
,
574 remaining
, left_margin
);
580 static size_t callchain__fprintf_graph(FILE *fp
, struct callchain_node
*self
,
581 u64 total_samples
, int left_margin
)
583 struct callchain_list
*chain
;
584 bool printed
= false;
587 u32 entries_printed
= 0;
589 list_for_each_entry(chain
, &self
->val
, list
) {
590 if (!i
++ && sort__first_dimension
== SORT_SYM
)
594 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
595 ret
+= fprintf(fp
, "|\n");
596 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
597 ret
+= fprintf(fp
, "---");
602 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
605 ret
+= fprintf(fp
, " %s\n", chain
->ms
.sym
->name
);
607 ret
+= fprintf(fp
, " %p\n", (void *)(long)chain
->ip
);
609 if (++entries_printed
== callchain_param
.print_limit
)
613 ret
+= __callchain__fprintf_graph(fp
, self
, total_samples
, 1, 1, left_margin
);
618 static size_t callchain__fprintf_flat(FILE *fp
, struct callchain_node
*self
,
621 struct callchain_list
*chain
;
627 ret
+= callchain__fprintf_flat(fp
, self
->parent
, total_samples
);
630 list_for_each_entry(chain
, &self
->val
, list
) {
631 if (chain
->ip
>= PERF_CONTEXT_MAX
)
634 ret
+= fprintf(fp
, " %s\n", chain
->ms
.sym
->name
);
636 ret
+= fprintf(fp
, " %p\n",
637 (void *)(long)chain
->ip
);
643 static size_t hist_entry_callchain__fprintf(FILE *fp
, struct hist_entry
*self
,
644 u64 total_samples
, int left_margin
)
646 struct rb_node
*rb_node
;
647 struct callchain_node
*chain
;
649 u32 entries_printed
= 0;
651 rb_node
= rb_first(&self
->sorted_chain
);
655 chain
= rb_entry(rb_node
, struct callchain_node
, rb_node
);
656 percent
= chain
->hit
* 100.0 / total_samples
;
657 switch (callchain_param
.mode
) {
659 ret
+= percent_color_fprintf(fp
, " %6.2f%%\n",
661 ret
+= callchain__fprintf_flat(fp
, chain
, total_samples
);
663 case CHAIN_GRAPH_ABS
: /* Falldown */
664 case CHAIN_GRAPH_REL
:
665 ret
+= callchain__fprintf_graph(fp
, chain
, total_samples
,
671 ret
+= fprintf(fp
, "\n");
672 if (++entries_printed
== callchain_param
.print_limit
)
674 rb_node
= rb_next(rb_node
);
680 void hists__output_recalc_col_len(struct hists
*hists
, int max_rows
)
682 struct rb_node
*next
= rb_first(&hists
->entries
);
683 struct hist_entry
*n
;
686 hists__reset_col_len(hists
);
688 while (next
&& row
++ < max_rows
) {
689 n
= rb_entry(next
, struct hist_entry
, rb_node
);
690 hists__calc_col_len(hists
, n
);
691 next
= rb_next(&n
->rb_node
);
695 int hist_entry__snprintf(struct hist_entry
*self
, char *s
, size_t size
,
696 struct hists
*hists
, struct hists
*pair_hists
,
697 bool show_displacement
, long displacement
,
698 bool color
, u64 session_total
)
700 struct sort_entry
*se
;
701 u64 period
, total
, period_sys
, period_us
, period_guest_sys
, period_guest_us
;
703 const char *sep
= symbol_conf
.field_sep
;
706 if (symbol_conf
.exclude_other
&& !self
->parent
)
710 period
= self
->pair
? self
->pair
->period
: 0;
711 nr_events
= self
->pair
? self
->pair
->nr_events
: 0;
712 total
= pair_hists
->stats
.total_period
;
713 period_sys
= self
->pair
? self
->pair
->period_sys
: 0;
714 period_us
= self
->pair
? self
->pair
->period_us
: 0;
715 period_guest_sys
= self
->pair
? self
->pair
->period_guest_sys
: 0;
716 period_guest_us
= self
->pair
? self
->pair
->period_guest_us
: 0;
718 period
= self
->period
;
719 nr_events
= self
->nr_events
;
720 total
= session_total
;
721 period_sys
= self
->period_sys
;
722 period_us
= self
->period_us
;
723 period_guest_sys
= self
->period_guest_sys
;
724 period_guest_us
= self
->period_guest_us
;
729 ret
= percent_color_snprintf(s
, size
,
730 sep
? "%.2f" : " %6.2f%%",
731 (period
* 100.0) / total
);
733 ret
= snprintf(s
, size
, sep
? "%.2f" : " %6.2f%%",
734 (period
* 100.0) / total
);
735 if (symbol_conf
.show_cpu_utilization
) {
736 ret
+= percent_color_snprintf(s
+ ret
, size
- ret
,
737 sep
? "%.2f" : " %6.2f%%",
738 (period_sys
* 100.0) / total
);
739 ret
+= percent_color_snprintf(s
+ ret
, size
- ret
,
740 sep
? "%.2f" : " %6.2f%%",
741 (period_us
* 100.0) / total
);
743 ret
+= percent_color_snprintf(s
+ ret
,
745 sep
? "%.2f" : " %6.2f%%",
746 (period_guest_sys
* 100.0) /
748 ret
+= percent_color_snprintf(s
+ ret
,
750 sep
? "%.2f" : " %6.2f%%",
751 (period_guest_us
* 100.0) /
756 ret
= snprintf(s
, size
, sep
? "%" PRIu64
: "%12" PRIu64
" ", period
);
758 if (symbol_conf
.show_nr_samples
) {
760 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%" PRIu64
, *sep
, nr_events
);
762 ret
+= snprintf(s
+ ret
, size
- ret
, "%11" PRIu64
, nr_events
);
765 if (symbol_conf
.show_total_period
) {
767 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%" PRIu64
, *sep
, period
);
769 ret
+= snprintf(s
+ ret
, size
- ret
, " %12" PRIu64
, period
);
774 double old_percent
= 0, new_percent
= 0, diff
;
777 old_percent
= (period
* 100.0) / total
;
778 if (session_total
> 0)
779 new_percent
= (self
->period
* 100.0) / session_total
;
781 diff
= new_percent
- old_percent
;
783 if (fabs(diff
) >= 0.01)
784 snprintf(bf
, sizeof(bf
), "%+4.2F%%", diff
);
786 snprintf(bf
, sizeof(bf
), " ");
789 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%s", *sep
, bf
);
791 ret
+= snprintf(s
+ ret
, size
- ret
, "%11.11s", bf
);
793 if (show_displacement
) {
795 snprintf(bf
, sizeof(bf
), "%+4ld", displacement
);
797 snprintf(bf
, sizeof(bf
), " ");
800 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%s", *sep
, bf
);
802 ret
+= snprintf(s
+ ret
, size
- ret
, "%6.6s", bf
);
806 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
810 ret
+= snprintf(s
+ ret
, size
- ret
, "%s", sep
?: " ");
811 ret
+= se
->se_snprintf(self
, s
+ ret
, size
- ret
,
812 hists__col_len(hists
, se
->se_width_idx
));
818 int hist_entry__fprintf(struct hist_entry
*he
, size_t size
, struct hists
*hists
,
819 struct hists
*pair_hists
, bool show_displacement
,
820 long displacement
, FILE *fp
, u64 session_total
)
824 if (size
== 0 || size
> sizeof(bf
))
827 hist_entry__snprintf(he
, bf
, size
, hists
, pair_hists
,
828 show_displacement
, displacement
,
829 true, session_total
);
830 return fprintf(fp
, "%s\n", bf
);
833 static size_t hist_entry__fprintf_callchain(struct hist_entry
*self
,
834 struct hists
*hists
, FILE *fp
,
839 if (sort__first_dimension
== SORT_COMM
) {
840 struct sort_entry
*se
= list_first_entry(&hist_entry__sort_list
,
842 left_margin
= hists__col_len(hists
, se
->se_width_idx
);
843 left_margin
-= thread__comm_len(self
->thread
);
846 return hist_entry_callchain__fprintf(fp
, self
, session_total
,
850 size_t hists__fprintf(struct hists
*hists
, struct hists
*pair
,
851 bool show_displacement
, bool show_header
, int max_rows
,
852 int max_cols
, FILE *fp
)
854 struct sort_entry
*se
;
857 unsigned long position
= 1;
858 long displacement
= 0;
860 const char *sep
= symbol_conf
.field_sep
;
861 const char *col_width
= symbol_conf
.col_width_list_str
;
869 fprintf(fp
, "# %s", pair
? "Baseline" : "Overhead");
871 if (symbol_conf
.show_nr_samples
) {
873 fprintf(fp
, "%cSamples", *sep
);
875 fputs(" Samples ", fp
);
878 if (symbol_conf
.show_total_period
) {
880 ret
+= fprintf(fp
, "%cPeriod", *sep
);
882 ret
+= fprintf(fp
, " Period ");
885 if (symbol_conf
.show_cpu_utilization
) {
887 ret
+= fprintf(fp
, "%csys", *sep
);
888 ret
+= fprintf(fp
, "%cus", *sep
);
890 ret
+= fprintf(fp
, "%cguest sys", *sep
);
891 ret
+= fprintf(fp
, "%cguest us", *sep
);
894 ret
+= fprintf(fp
, " sys ");
895 ret
+= fprintf(fp
, " us ");
897 ret
+= fprintf(fp
, " guest sys ");
898 ret
+= fprintf(fp
, " guest us ");
905 ret
+= fprintf(fp
, "%cDelta", *sep
);
907 ret
+= fprintf(fp
, " Delta ");
909 if (show_displacement
) {
911 ret
+= fprintf(fp
, "%cDisplacement", *sep
);
913 ret
+= fprintf(fp
, " Displ");
917 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
921 fprintf(fp
, "%c%s", *sep
, se
->se_header
);
924 width
= strlen(se
->se_header
);
925 if (symbol_conf
.col_width_list_str
) {
927 hists__set_col_len(hists
, se
->se_width_idx
,
929 col_width
= strchr(col_width
, ',');
934 if (!hists__new_col_len(hists
, se
->se_width_idx
, width
))
935 width
= hists__col_len(hists
, se
->se_width_idx
);
936 fprintf(fp
, " %*s", width
, se
->se_header
);
940 if (max_rows
&& ++nr_rows
>= max_rows
)
946 fprintf(fp
, "# ........");
947 if (symbol_conf
.show_nr_samples
)
948 fprintf(fp
, " ..........");
949 if (symbol_conf
.show_total_period
)
950 fprintf(fp
, " ............");
952 fprintf(fp
, " ..........");
953 if (show_displacement
)
954 fprintf(fp
, " .....");
956 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
963 width
= hists__col_len(hists
, se
->se_width_idx
);
965 width
= strlen(se
->se_header
);
966 for (i
= 0; i
< width
; i
++)
971 if (max_rows
&& ++nr_rows
>= max_rows
)
975 if (max_rows
&& ++nr_rows
>= max_rows
)
979 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
980 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
985 if (show_displacement
) {
987 displacement
= ((long)h
->pair
->position
-
993 ret
+= hist_entry__fprintf(h
, max_cols
, hists
, pair
, show_displacement
,
994 displacement
, fp
, hists
->stats
.total_period
);
996 if (symbol_conf
.use_callchain
)
997 ret
+= hist_entry__fprintf_callchain(h
, hists
, fp
,
998 hists
->stats
.total_period
);
999 if (max_rows
&& ++nr_rows
>= max_rows
)
1002 if (h
->ms
.map
== NULL
&& verbose
> 1) {
1003 __map_groups__fprintf_maps(&h
->thread
->mg
,
1004 MAP__FUNCTION
, verbose
, fp
);
1005 fprintf(fp
, "%.10s end\n", graph_dotted_line
);
1009 free(rem_sq_bracket
);
1015 * See hists__fprintf to match the column widths
1017 unsigned int hists__sort_list_width(struct hists
*hists
)
1019 struct sort_entry
*se
;
1020 int ret
= 9; /* total % */
1022 if (symbol_conf
.show_cpu_utilization
) {
1023 ret
+= 7; /* count_sys % */
1024 ret
+= 6; /* count_us % */
1026 ret
+= 13; /* count_guest_sys % */
1027 ret
+= 12; /* count_guest_us % */
1031 if (symbol_conf
.show_nr_samples
)
1034 if (symbol_conf
.show_total_period
)
1037 list_for_each_entry(se
, &hist_entry__sort_list
, list
)
1039 ret
+= 2 + hists__col_len(hists
, se
->se_width_idx
);
1041 if (verbose
) /* Addr + origin */
1042 ret
+= 3 + BITS_PER_LONG
/ 4;
1047 static void hists__remove_entry_filter(struct hists
*hists
, struct hist_entry
*h
,
1048 enum hist_filter filter
)
1050 h
->filtered
&= ~(1 << filter
);
1054 ++hists
->nr_entries
;
1056 hists
->nr_entries
+= h
->nr_rows
;
1058 hists
->stats
.total_period
+= h
->period
;
1059 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] += h
->nr_events
;
1061 hists__calc_col_len(hists
, h
);
1064 void hists__filter_by_dso(struct hists
*hists
, const struct dso
*dso
)
1068 hists
->nr_entries
= hists
->stats
.total_period
= 0;
1069 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
1070 hists__reset_col_len(hists
);
1072 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
1073 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
1075 if (symbol_conf
.exclude_other
&& !h
->parent
)
1078 if (dso
!= NULL
&& (h
->ms
.map
== NULL
|| h
->ms
.map
->dso
!= dso
)) {
1079 h
->filtered
|= (1 << HIST_FILTER__DSO
);
1083 hists__remove_entry_filter(hists
, h
, HIST_FILTER__DSO
);
1087 void hists__filter_by_thread(struct hists
*hists
, const struct thread
*thread
)
1091 hists
->nr_entries
= hists
->stats
.total_period
= 0;
1092 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
1093 hists__reset_col_len(hists
);
1095 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
1096 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
1098 if (thread
!= NULL
&& h
->thread
!= thread
) {
1099 h
->filtered
|= (1 << HIST_FILTER__THREAD
);
1103 hists__remove_entry_filter(hists
, h
, HIST_FILTER__THREAD
);
1107 int hist_entry__inc_addr_samples(struct hist_entry
*he
, int evidx
, u64 ip
)
1109 return symbol__inc_addr_samples(he
->ms
.sym
, he
->ms
.map
, evidx
, ip
);
1112 int hist_entry__annotate(struct hist_entry
*he
, size_t privsize
)
1114 return symbol__annotate(he
->ms
.sym
, he
->ms
.map
, privsize
);
1117 void hists__inc_nr_events(struct hists
*hists
, u32 type
)
1119 ++hists
->stats
.nr_events
[0];
1120 ++hists
->stats
.nr_events
[type
];
1123 size_t hists__fprintf_nr_events(struct hists
*hists
, FILE *fp
)
1128 for (i
= 0; i
< PERF_RECORD_HEADER_MAX
; ++i
) {
1131 if (hists
->stats
.nr_events
[i
] == 0)
1134 name
= perf_event__name(i
);
1135 if (!strcmp(name
, "UNKNOWN"))
1138 ret
+= fprintf(fp
, "%16s events: %10d\n", name
,
1139 hists
->stats
.nr_events
[i
]);
1145 void hists__init(struct hists
*hists
)
1147 memset(hists
, 0, sizeof(*hists
));
1148 hists
->entries_in_array
[0] = hists
->entries_in_array
[1] = RB_ROOT
;
1149 hists
->entries_in
= &hists
->entries_in_array
[0];
1150 hists
->entries_collapsed
= RB_ROOT
;
1151 hists
->entries
= RB_ROOT
;
1152 pthread_mutex_init(&hists
->lock
, NULL
);