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
)
103 hists
->stats
.total_period
-= he
->period
;
104 hist_entry__decay(he
);
105 hists
->stats
.total_period
+= he
->period
;
106 return he
->period
== 0;
109 void hists__decay_entries(struct hists
*hists
)
111 struct rb_node
*next
= rb_first(&hists
->entries
);
112 struct hist_entry
*n
;
115 n
= rb_entry(next
, struct hist_entry
, rb_node
);
116 next
= rb_next(&n
->rb_node
);
118 if (hists__decay_entry(hists
, n
)) {
119 rb_erase(&n
->rb_node
, &hists
->entries
);
121 if (sort__need_collapse
)
122 rb_erase(&n
->rb_node_in
, &hists
->entries_collapsed
);
131 * histogram, sorted on item, collects periods
134 static struct hist_entry
*hist_entry__new(struct hist_entry
*template)
136 size_t callchain_size
= symbol_conf
.use_callchain
? sizeof(struct callchain_root
) : 0;
137 struct hist_entry
*self
= malloc(sizeof(*self
) + callchain_size
);
143 self
->ms
.map
->referenced
= true;
144 if (symbol_conf
.use_callchain
)
145 callchain_init(self
->callchain
);
151 static void hists__inc_nr_entries(struct hists
*hists
, struct hist_entry
*h
)
154 hists__calc_col_len(hists
, h
);
156 hists
->stats
.total_period
+= h
->period
;
160 static u8
symbol__parent_filter(const struct symbol
*parent
)
162 if (symbol_conf
.exclude_other
&& parent
== NULL
)
163 return 1 << HIST_FILTER__PARENT
;
167 struct hist_entry
*__hists__add_entry(struct hists
*hists
,
168 struct addr_location
*al
,
169 struct symbol
*sym_parent
, u64 period
)
172 struct rb_node
*parent
= NULL
;
173 struct hist_entry
*he
;
174 struct hist_entry entry
= {
175 .thread
= al
->thread
,
184 .parent
= sym_parent
,
185 .filtered
= symbol__parent_filter(sym_parent
),
189 pthread_mutex_lock(&hists
->lock
);
191 p
= &hists
->entries_in
->rb_node
;
195 he
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
197 cmp
= hist_entry__cmp(&entry
, he
);
200 he
->period
+= period
;
211 he
= hist_entry__new(&entry
);
215 rb_link_node(&he
->rb_node_in
, parent
, p
);
216 rb_insert_color(&he
->rb_node_in
, hists
->entries_in
);
218 hist_entry__add_cpumode_period(he
, al
->cpumode
, period
);
220 pthread_mutex_unlock(&hists
->lock
);
225 hist_entry__cmp(struct hist_entry
*left
, struct hist_entry
*right
)
227 struct sort_entry
*se
;
230 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
231 cmp
= se
->se_cmp(left
, right
);
240 hist_entry__collapse(struct hist_entry
*left
, struct hist_entry
*right
)
242 struct sort_entry
*se
;
245 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
246 int64_t (*f
)(struct hist_entry
*, struct hist_entry
*);
248 f
= se
->se_collapse
?: se
->se_cmp
;
250 cmp
= f(left
, right
);
258 void hist_entry__free(struct hist_entry
*he
)
264 * collapse the histogram
267 static bool hists__collapse_insert_entry(struct hists
*hists
,
268 struct rb_root
*root
,
269 struct hist_entry
*he
)
271 struct rb_node
**p
= &root
->rb_node
;
272 struct rb_node
*parent
= NULL
;
273 struct hist_entry
*iter
;
278 iter
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
280 cmp
= hist_entry__collapse(iter
, he
);
283 iter
->period
+= he
->period
;
284 iter
->nr_events
+= he
->nr_events
;
285 if (symbol_conf
.use_callchain
) {
286 callchain_cursor_reset(&hists
->callchain_cursor
);
287 callchain_merge(&hists
->callchain_cursor
, iter
->callchain
,
290 hist_entry__free(he
);
300 rb_link_node(&he
->rb_node_in
, parent
, p
);
301 rb_insert_color(&he
->rb_node_in
, root
);
305 static struct rb_root
*hists__get_rotate_entries_in(struct hists
*hists
)
307 struct rb_root
*root
;
309 pthread_mutex_lock(&hists
->lock
);
311 root
= hists
->entries_in
;
312 if (++hists
->entries_in
> &hists
->entries_in_array
[1])
313 hists
->entries_in
= &hists
->entries_in_array
[0];
315 pthread_mutex_unlock(&hists
->lock
);
320 static void __hists__collapse_resort(struct hists
*hists
, bool threaded
)
322 struct rb_root
*root
;
323 struct rb_node
*next
;
324 struct hist_entry
*n
;
326 if (!sort__need_collapse
&& !threaded
)
329 root
= hists__get_rotate_entries_in(hists
);
330 next
= rb_first(root
);
331 hists
->stats
.total_period
= 0;
334 n
= rb_entry(next
, struct hist_entry
, rb_node_in
);
335 next
= rb_next(&n
->rb_node_in
);
337 rb_erase(&n
->rb_node_in
, root
);
338 if (hists__collapse_insert_entry(hists
, &hists
->entries_collapsed
, n
))
339 hists__inc_nr_entries(hists
, n
);
343 void hists__collapse_resort(struct hists
*hists
)
345 return __hists__collapse_resort(hists
, false);
348 void hists__collapse_resort_threaded(struct hists
*hists
)
350 return __hists__collapse_resort(hists
, true);
354 * reverse the map, sort on period.
357 static void __hists__insert_output_entry(struct rb_root
*entries
,
358 struct hist_entry
*he
,
359 u64 min_callchain_hits
)
361 struct rb_node
**p
= &entries
->rb_node
;
362 struct rb_node
*parent
= NULL
;
363 struct hist_entry
*iter
;
365 if (symbol_conf
.use_callchain
)
366 callchain_param
.sort(&he
->sorted_chain
, he
->callchain
,
367 min_callchain_hits
, &callchain_param
);
371 iter
= rb_entry(parent
, struct hist_entry
, rb_node
);
373 if (he
->period
> iter
->period
)
379 rb_link_node(&he
->rb_node
, parent
, p
);
380 rb_insert_color(&he
->rb_node
, entries
);
383 static void __hists__output_resort(struct hists
*hists
, bool threaded
)
385 struct rb_root
*root
;
386 struct rb_node
*next
;
387 struct hist_entry
*n
;
388 u64 min_callchain_hits
;
390 min_callchain_hits
= hists
->stats
.total_period
* (callchain_param
.min_percent
/ 100);
392 if (sort__need_collapse
|| threaded
)
393 root
= &hists
->entries_collapsed
;
395 root
= hists
->entries_in
;
397 next
= rb_first(root
);
398 hists
->entries
= RB_ROOT
;
400 hists
->nr_entries
= 0;
401 hists__reset_col_len(hists
);
404 n
= rb_entry(next
, struct hist_entry
, rb_node_in
);
405 next
= rb_next(&n
->rb_node_in
);
407 __hists__insert_output_entry(&hists
->entries
, n
, min_callchain_hits
);
408 hists__inc_nr_entries(hists
, n
);
412 void hists__output_resort(struct hists
*hists
)
414 return __hists__output_resort(hists
, false);
417 void hists__output_resort_threaded(struct hists
*hists
)
419 return __hists__output_resort(hists
, true);
422 static size_t callchain__fprintf_left_margin(FILE *fp
, int left_margin
)
425 int ret
= fprintf(fp
, " ");
427 for (i
= 0; i
< left_margin
; i
++)
428 ret
+= fprintf(fp
, " ");
433 static size_t ipchain__fprintf_graph_line(FILE *fp
, int depth
, int depth_mask
,
437 size_t ret
= callchain__fprintf_left_margin(fp
, left_margin
);
439 for (i
= 0; i
< depth
; i
++)
440 if (depth_mask
& (1 << i
))
441 ret
+= fprintf(fp
, "| ");
443 ret
+= fprintf(fp
, " ");
445 ret
+= fprintf(fp
, "\n");
450 static size_t ipchain__fprintf_graph(FILE *fp
, struct callchain_list
*chain
,
451 int depth
, int depth_mask
, int period
,
452 u64 total_samples
, u64 hits
,
458 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
459 for (i
= 0; i
< depth
; i
++) {
460 if (depth_mask
& (1 << i
))
461 ret
+= fprintf(fp
, "|");
463 ret
+= fprintf(fp
, " ");
464 if (!period
&& i
== depth
- 1) {
467 percent
= hits
* 100.0 / total_samples
;
468 ret
+= percent_color_fprintf(fp
, "--%2.2f%%-- ", percent
);
470 ret
+= fprintf(fp
, "%s", " ");
473 ret
+= fprintf(fp
, "%s\n", chain
->ms
.sym
->name
);
475 ret
+= fprintf(fp
, "%p\n", (void *)(long)chain
->ip
);
480 static struct symbol
*rem_sq_bracket
;
481 static struct callchain_list rem_hits
;
483 static void init_rem_hits(void)
485 rem_sq_bracket
= malloc(sizeof(*rem_sq_bracket
) + 6);
486 if (!rem_sq_bracket
) {
487 fprintf(stderr
, "Not enough memory to display remaining hits\n");
491 strcpy(rem_sq_bracket
->name
, "[...]");
492 rem_hits
.ms
.sym
= rem_sq_bracket
;
495 static size_t __callchain__fprintf_graph(FILE *fp
, struct callchain_node
*self
,
496 u64 total_samples
, int depth
,
497 int depth_mask
, int left_margin
)
499 struct rb_node
*node
, *next
;
500 struct callchain_node
*child
;
501 struct callchain_list
*chain
;
502 int new_depth_mask
= depth_mask
;
507 uint entries_printed
= 0;
509 if (callchain_param
.mode
== CHAIN_GRAPH_REL
)
510 new_total
= self
->children_hit
;
512 new_total
= total_samples
;
514 remaining
= new_total
;
516 node
= rb_first(&self
->rb_root
);
520 child
= rb_entry(node
, struct callchain_node
, rb_node
);
521 cumul
= callchain_cumul_hits(child
);
525 * The depth mask manages the output of pipes that show
526 * the depth. We don't want to keep the pipes of the current
527 * level for the last child of this depth.
528 * Except if we have remaining filtered hits. They will
529 * supersede the last child
531 next
= rb_next(node
);
532 if (!next
&& (callchain_param
.mode
!= CHAIN_GRAPH_REL
|| !remaining
))
533 new_depth_mask
&= ~(1 << (depth
- 1));
536 * But we keep the older depth mask for the line separator
537 * to keep the level link until we reach the last child
539 ret
+= ipchain__fprintf_graph_line(fp
, depth
, depth_mask
,
542 list_for_each_entry(chain
, &child
->val
, list
) {
543 ret
+= ipchain__fprintf_graph(fp
, chain
, depth
,
549 ret
+= __callchain__fprintf_graph(fp
, child
, new_total
,
551 new_depth_mask
| (1 << depth
),
554 if (++entries_printed
== callchain_param
.print_limit
)
558 if (callchain_param
.mode
== CHAIN_GRAPH_REL
&&
559 remaining
&& remaining
!= new_total
) {
564 new_depth_mask
&= ~(1 << (depth
- 1));
566 ret
+= ipchain__fprintf_graph(fp
, &rem_hits
, depth
,
567 new_depth_mask
, 0, new_total
,
568 remaining
, left_margin
);
574 static size_t callchain__fprintf_graph(FILE *fp
, struct callchain_node
*self
,
575 u64 total_samples
, int left_margin
)
577 struct callchain_list
*chain
;
578 bool printed
= false;
581 u32 entries_printed
= 0;
583 list_for_each_entry(chain
, &self
->val
, list
) {
584 if (!i
++ && sort__first_dimension
== SORT_SYM
)
588 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
589 ret
+= fprintf(fp
, "|\n");
590 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
591 ret
+= fprintf(fp
, "---");
596 ret
+= callchain__fprintf_left_margin(fp
, left_margin
);
599 ret
+= fprintf(fp
, " %s\n", chain
->ms
.sym
->name
);
601 ret
+= fprintf(fp
, " %p\n", (void *)(long)chain
->ip
);
603 if (++entries_printed
== callchain_param
.print_limit
)
607 ret
+= __callchain__fprintf_graph(fp
, self
, total_samples
, 1, 1, left_margin
);
612 static size_t callchain__fprintf_flat(FILE *fp
, struct callchain_node
*self
,
615 struct callchain_list
*chain
;
621 ret
+= callchain__fprintf_flat(fp
, self
->parent
, total_samples
);
624 list_for_each_entry(chain
, &self
->val
, list
) {
625 if (chain
->ip
>= PERF_CONTEXT_MAX
)
628 ret
+= fprintf(fp
, " %s\n", chain
->ms
.sym
->name
);
630 ret
+= fprintf(fp
, " %p\n",
631 (void *)(long)chain
->ip
);
637 static size_t hist_entry_callchain__fprintf(FILE *fp
, struct hist_entry
*self
,
638 u64 total_samples
, int left_margin
)
640 struct rb_node
*rb_node
;
641 struct callchain_node
*chain
;
643 u32 entries_printed
= 0;
645 rb_node
= rb_first(&self
->sorted_chain
);
649 chain
= rb_entry(rb_node
, struct callchain_node
, rb_node
);
650 percent
= chain
->hit
* 100.0 / total_samples
;
651 switch (callchain_param
.mode
) {
653 ret
+= percent_color_fprintf(fp
, " %6.2f%%\n",
655 ret
+= callchain__fprintf_flat(fp
, chain
, total_samples
);
657 case CHAIN_GRAPH_ABS
: /* Falldown */
658 case CHAIN_GRAPH_REL
:
659 ret
+= callchain__fprintf_graph(fp
, chain
, total_samples
,
665 ret
+= fprintf(fp
, "\n");
666 if (++entries_printed
== callchain_param
.print_limit
)
668 rb_node
= rb_next(rb_node
);
674 void hists__output_recalc_col_len(struct hists
*hists
, int max_rows
)
676 struct rb_node
*next
= rb_first(&hists
->entries
);
677 struct hist_entry
*n
;
680 hists__reset_col_len(hists
);
682 while (next
&& row
++ < max_rows
) {
683 n
= rb_entry(next
, struct hist_entry
, rb_node
);
684 hists__calc_col_len(hists
, n
);
685 next
= rb_next(&n
->rb_node
);
689 int hist_entry__snprintf(struct hist_entry
*self
, char *s
, size_t size
,
690 struct hists
*hists
, struct hists
*pair_hists
,
691 bool show_displacement
, long displacement
,
692 bool color
, u64 session_total
)
694 struct sort_entry
*se
;
695 u64 period
, total
, period_sys
, period_us
, period_guest_sys
, period_guest_us
;
697 const char *sep
= symbol_conf
.field_sep
;
700 if (symbol_conf
.exclude_other
&& !self
->parent
)
704 period
= self
->pair
? self
->pair
->period
: 0;
705 nr_events
= self
->pair
? self
->pair
->nr_events
: 0;
706 total
= pair_hists
->stats
.total_period
;
707 period_sys
= self
->pair
? self
->pair
->period_sys
: 0;
708 period_us
= self
->pair
? self
->pair
->period_us
: 0;
709 period_guest_sys
= self
->pair
? self
->pair
->period_guest_sys
: 0;
710 period_guest_us
= self
->pair
? self
->pair
->period_guest_us
: 0;
712 period
= self
->period
;
713 nr_events
= self
->nr_events
;
714 total
= session_total
;
715 period_sys
= self
->period_sys
;
716 period_us
= self
->period_us
;
717 period_guest_sys
= self
->period_guest_sys
;
718 period_guest_us
= self
->period_guest_us
;
723 ret
= percent_color_snprintf(s
, size
,
724 sep
? "%.2f" : " %6.2f%%",
725 (period
* 100.0) / total
);
727 ret
= snprintf(s
, size
, sep
? "%.2f" : " %6.2f%%",
728 (period
* 100.0) / total
);
729 if (symbol_conf
.show_cpu_utilization
) {
730 ret
+= percent_color_snprintf(s
+ ret
, size
- ret
,
731 sep
? "%.2f" : " %6.2f%%",
732 (period_sys
* 100.0) / total
);
733 ret
+= percent_color_snprintf(s
+ ret
, size
- ret
,
734 sep
? "%.2f" : " %6.2f%%",
735 (period_us
* 100.0) / total
);
737 ret
+= percent_color_snprintf(s
+ ret
,
739 sep
? "%.2f" : " %6.2f%%",
740 (period_guest_sys
* 100.0) /
742 ret
+= percent_color_snprintf(s
+ ret
,
744 sep
? "%.2f" : " %6.2f%%",
745 (period_guest_us
* 100.0) /
750 ret
= snprintf(s
, size
, sep
? "%" PRIu64
: "%12" PRIu64
" ", period
);
752 if (symbol_conf
.show_nr_samples
) {
754 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%" PRIu64
, *sep
, nr_events
);
756 ret
+= snprintf(s
+ ret
, size
- ret
, "%11" PRIu64
, nr_events
);
759 if (symbol_conf
.show_total_period
) {
761 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%" PRIu64
, *sep
, period
);
763 ret
+= snprintf(s
+ ret
, size
- ret
, " %12" PRIu64
, period
);
768 double old_percent
= 0, new_percent
= 0, diff
;
771 old_percent
= (period
* 100.0) / total
;
772 if (session_total
> 0)
773 new_percent
= (self
->period
* 100.0) / session_total
;
775 diff
= new_percent
- old_percent
;
777 if (fabs(diff
) >= 0.01)
778 snprintf(bf
, sizeof(bf
), "%+4.2F%%", diff
);
780 snprintf(bf
, sizeof(bf
), " ");
783 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%s", *sep
, bf
);
785 ret
+= snprintf(s
+ ret
, size
- ret
, "%11.11s", bf
);
787 if (show_displacement
) {
789 snprintf(bf
, sizeof(bf
), "%+4ld", displacement
);
791 snprintf(bf
, sizeof(bf
), " ");
794 ret
+= snprintf(s
+ ret
, size
- ret
, "%c%s", *sep
, bf
);
796 ret
+= snprintf(s
+ ret
, size
- ret
, "%6.6s", bf
);
800 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
804 ret
+= snprintf(s
+ ret
, size
- ret
, "%s", sep
?: " ");
805 ret
+= se
->se_snprintf(self
, s
+ ret
, size
- ret
,
806 hists__col_len(hists
, se
->se_width_idx
));
812 int hist_entry__fprintf(struct hist_entry
*he
, size_t size
, struct hists
*hists
,
813 struct hists
*pair_hists
, bool show_displacement
,
814 long displacement
, FILE *fp
, u64 session_total
)
818 if (size
== 0 || size
> sizeof(bf
))
821 hist_entry__snprintf(he
, bf
, size
, hists
, pair_hists
,
822 show_displacement
, displacement
,
823 true, session_total
);
824 return fprintf(fp
, "%s\n", bf
);
827 static size_t hist_entry__fprintf_callchain(struct hist_entry
*self
,
828 struct hists
*hists
, FILE *fp
,
833 if (sort__first_dimension
== SORT_COMM
) {
834 struct sort_entry
*se
= list_first_entry(&hist_entry__sort_list
,
836 left_margin
= hists__col_len(hists
, se
->se_width_idx
);
837 left_margin
-= thread__comm_len(self
->thread
);
840 return hist_entry_callchain__fprintf(fp
, self
, session_total
,
844 size_t hists__fprintf(struct hists
*hists
, struct hists
*pair
,
845 bool show_displacement
, bool show_header
, int max_rows
,
846 int max_cols
, FILE *fp
)
848 struct sort_entry
*se
;
851 unsigned long position
= 1;
852 long displacement
= 0;
854 const char *sep
= symbol_conf
.field_sep
;
855 const char *col_width
= symbol_conf
.col_width_list_str
;
863 fprintf(fp
, "# %s", pair
? "Baseline" : "Overhead");
865 if (symbol_conf
.show_nr_samples
) {
867 fprintf(fp
, "%cSamples", *sep
);
869 fputs(" Samples ", fp
);
872 if (symbol_conf
.show_total_period
) {
874 ret
+= fprintf(fp
, "%cPeriod", *sep
);
876 ret
+= fprintf(fp
, " Period ");
879 if (symbol_conf
.show_cpu_utilization
) {
881 ret
+= fprintf(fp
, "%csys", *sep
);
882 ret
+= fprintf(fp
, "%cus", *sep
);
884 ret
+= fprintf(fp
, "%cguest sys", *sep
);
885 ret
+= fprintf(fp
, "%cguest us", *sep
);
888 ret
+= fprintf(fp
, " sys ");
889 ret
+= fprintf(fp
, " us ");
891 ret
+= fprintf(fp
, " guest sys ");
892 ret
+= fprintf(fp
, " guest us ");
899 ret
+= fprintf(fp
, "%cDelta", *sep
);
901 ret
+= fprintf(fp
, " Delta ");
903 if (show_displacement
) {
905 ret
+= fprintf(fp
, "%cDisplacement", *sep
);
907 ret
+= fprintf(fp
, " Displ");
911 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
915 fprintf(fp
, "%c%s", *sep
, se
->se_header
);
918 width
= strlen(se
->se_header
);
919 if (symbol_conf
.col_width_list_str
) {
921 hists__set_col_len(hists
, se
->se_width_idx
,
923 col_width
= strchr(col_width
, ',');
928 if (!hists__new_col_len(hists
, se
->se_width_idx
, width
))
929 width
= hists__col_len(hists
, se
->se_width_idx
);
930 fprintf(fp
, " %*s", width
, se
->se_header
);
934 if (max_rows
&& ++nr_rows
>= max_rows
)
940 fprintf(fp
, "# ........");
941 if (symbol_conf
.show_nr_samples
)
942 fprintf(fp
, " ..........");
943 if (symbol_conf
.show_total_period
)
944 fprintf(fp
, " ............");
946 fprintf(fp
, " ..........");
947 if (show_displacement
)
948 fprintf(fp
, " .....");
950 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
957 width
= hists__col_len(hists
, se
->se_width_idx
);
959 width
= strlen(se
->se_header
);
960 for (i
= 0; i
< width
; i
++)
965 if (max_rows
&& ++nr_rows
>= max_rows
)
969 if (max_rows
&& ++nr_rows
>= max_rows
)
973 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
974 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
979 if (show_displacement
) {
981 displacement
= ((long)h
->pair
->position
-
987 ret
+= hist_entry__fprintf(h
, max_cols
, hists
, pair
, show_displacement
,
988 displacement
, fp
, hists
->stats
.total_period
);
990 if (symbol_conf
.use_callchain
)
991 ret
+= hist_entry__fprintf_callchain(h
, hists
, fp
,
992 hists
->stats
.total_period
);
993 if (max_rows
&& ++nr_rows
>= max_rows
)
996 if (h
->ms
.map
== NULL
&& verbose
> 1) {
997 __map_groups__fprintf_maps(&h
->thread
->mg
,
998 MAP__FUNCTION
, verbose
, fp
);
999 fprintf(fp
, "%.10s end\n", graph_dotted_line
);
1003 free(rem_sq_bracket
);
1009 * See hists__fprintf to match the column widths
1011 unsigned int hists__sort_list_width(struct hists
*hists
)
1013 struct sort_entry
*se
;
1014 int ret
= 9; /* total % */
1016 if (symbol_conf
.show_cpu_utilization
) {
1017 ret
+= 7; /* count_sys % */
1018 ret
+= 6; /* count_us % */
1020 ret
+= 13; /* count_guest_sys % */
1021 ret
+= 12; /* count_guest_us % */
1025 if (symbol_conf
.show_nr_samples
)
1028 if (symbol_conf
.show_total_period
)
1031 list_for_each_entry(se
, &hist_entry__sort_list
, list
)
1033 ret
+= 2 + hists__col_len(hists
, se
->se_width_idx
);
1035 if (verbose
) /* Addr + origin */
1036 ret
+= 3 + BITS_PER_LONG
/ 4;
1041 static void hists__remove_entry_filter(struct hists
*hists
, struct hist_entry
*h
,
1042 enum hist_filter filter
)
1044 h
->filtered
&= ~(1 << filter
);
1048 ++hists
->nr_entries
;
1050 hists
->nr_entries
+= h
->nr_rows
;
1052 hists
->stats
.total_period
+= h
->period
;
1053 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] += h
->nr_events
;
1055 hists__calc_col_len(hists
, h
);
1058 void hists__filter_by_dso(struct hists
*hists
, const struct dso
*dso
)
1062 hists
->nr_entries
= hists
->stats
.total_period
= 0;
1063 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
1064 hists__reset_col_len(hists
);
1066 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
1067 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
1069 if (symbol_conf
.exclude_other
&& !h
->parent
)
1072 if (dso
!= NULL
&& (h
->ms
.map
== NULL
|| h
->ms
.map
->dso
!= dso
)) {
1073 h
->filtered
|= (1 << HIST_FILTER__DSO
);
1077 hists__remove_entry_filter(hists
, h
, HIST_FILTER__DSO
);
1081 void hists__filter_by_thread(struct hists
*hists
, const struct thread
*thread
)
1085 hists
->nr_entries
= hists
->stats
.total_period
= 0;
1086 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
1087 hists__reset_col_len(hists
);
1089 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
1090 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
1092 if (thread
!= NULL
&& h
->thread
!= thread
) {
1093 h
->filtered
|= (1 << HIST_FILTER__THREAD
);
1097 hists__remove_entry_filter(hists
, h
, HIST_FILTER__THREAD
);
1101 int hist_entry__inc_addr_samples(struct hist_entry
*he
, int evidx
, u64 ip
)
1103 return symbol__inc_addr_samples(he
->ms
.sym
, he
->ms
.map
, evidx
, ip
);
1106 int hist_entry__annotate(struct hist_entry
*he
, size_t privsize
)
1108 return symbol__annotate(he
->ms
.sym
, he
->ms
.map
, privsize
);
1111 void hists__inc_nr_events(struct hists
*hists
, u32 type
)
1113 ++hists
->stats
.nr_events
[0];
1114 ++hists
->stats
.nr_events
[type
];
1117 size_t hists__fprintf_nr_events(struct hists
*hists
, FILE *fp
)
1122 for (i
= 0; i
< PERF_RECORD_HEADER_MAX
; ++i
) {
1125 if (hists
->stats
.nr_events
[i
] == 0)
1128 name
= perf_event__name(i
);
1129 if (!strcmp(name
, "UNKNOWN"))
1132 ret
+= fprintf(fp
, "%16s events: %10d\n", name
,
1133 hists
->stats
.nr_events
[i
]);
1139 void hists__init(struct hists
*hists
)
1141 memset(hists
, 0, sizeof(*hists
));
1142 hists
->entries_in_array
[0] = hists
->entries_in_array
[1] = RB_ROOT
;
1143 hists
->entries_in
= &hists
->entries_in_array
[0];
1144 hists
->entries_collapsed
= RB_ROOT
;
1145 hists
->entries
= RB_ROOT
;
1146 pthread_mutex_init(&hists
->lock
, NULL
);