10 static bool hists__filter_entry_by_dso(struct hists
*hists
,
11 struct hist_entry
*he
);
12 static bool hists__filter_entry_by_thread(struct hists
*hists
,
13 struct hist_entry
*he
);
14 static bool hists__filter_entry_by_symbol(struct hists
*hists
,
15 struct hist_entry
*he
);
24 struct callchain_param callchain_param
= {
25 .mode
= CHAIN_GRAPH_REL
,
27 .order
= ORDER_CALLEE
,
31 u16
hists__col_len(struct hists
*hists
, enum hist_column col
)
33 return hists
->col_len
[col
];
36 void hists__set_col_len(struct hists
*hists
, enum hist_column col
, u16 len
)
38 hists
->col_len
[col
] = len
;
41 bool hists__new_col_len(struct hists
*hists
, enum hist_column col
, u16 len
)
43 if (len
> hists__col_len(hists
, col
)) {
44 hists__set_col_len(hists
, col
, len
);
50 void hists__reset_col_len(struct hists
*hists
)
54 for (col
= 0; col
< HISTC_NR_COLS
; ++col
)
55 hists__set_col_len(hists
, col
, 0);
58 static void hists__set_unres_dso_col_len(struct hists
*hists
, int dso
)
60 const unsigned int unresolved_col_width
= BITS_PER_LONG
/ 4;
62 if (hists__col_len(hists
, dso
) < unresolved_col_width
&&
63 !symbol_conf
.col_width_list_str
&& !symbol_conf
.field_sep
&&
64 !symbol_conf
.dso_list
)
65 hists__set_col_len(hists
, dso
, unresolved_col_width
);
68 void hists__calc_col_len(struct hists
*hists
, struct hist_entry
*h
)
70 const unsigned int unresolved_col_width
= BITS_PER_LONG
/ 4;
75 * +4 accounts for '[x] ' priv level info
76 * +2 accounts for 0x prefix on raw addresses
77 * +3 accounts for ' y ' symtab origin info
80 symlen
= h
->ms
.sym
->namelen
+ 4;
82 symlen
+= BITS_PER_LONG
/ 4 + 2 + 3;
83 hists__new_col_len(hists
, HISTC_SYMBOL
, symlen
);
85 symlen
= unresolved_col_width
+ 4 + 2;
86 hists__new_col_len(hists
, HISTC_SYMBOL
, symlen
);
87 hists__set_unres_dso_col_len(hists
, HISTC_DSO
);
90 len
= thread__comm_len(h
->thread
);
91 if (hists__new_col_len(hists
, HISTC_COMM
, len
))
92 hists__set_col_len(hists
, HISTC_THREAD
, len
+ 6);
95 len
= dso__name_len(h
->ms
.map
->dso
);
96 hists__new_col_len(hists
, HISTC_DSO
, len
);
100 hists__new_col_len(hists
, HISTC_PARENT
, h
->parent
->namelen
);
102 if (h
->branch_info
) {
103 if (h
->branch_info
->from
.sym
) {
104 symlen
= (int)h
->branch_info
->from
.sym
->namelen
+ 4;
106 symlen
+= BITS_PER_LONG
/ 4 + 2 + 3;
107 hists__new_col_len(hists
, HISTC_SYMBOL_FROM
, symlen
);
109 symlen
= dso__name_len(h
->branch_info
->from
.map
->dso
);
110 hists__new_col_len(hists
, HISTC_DSO_FROM
, symlen
);
112 symlen
= unresolved_col_width
+ 4 + 2;
113 hists__new_col_len(hists
, HISTC_SYMBOL_FROM
, symlen
);
114 hists__set_unres_dso_col_len(hists
, HISTC_DSO_FROM
);
117 if (h
->branch_info
->to
.sym
) {
118 symlen
= (int)h
->branch_info
->to
.sym
->namelen
+ 4;
120 symlen
+= BITS_PER_LONG
/ 4 + 2 + 3;
121 hists__new_col_len(hists
, HISTC_SYMBOL_TO
, symlen
);
123 symlen
= dso__name_len(h
->branch_info
->to
.map
->dso
);
124 hists__new_col_len(hists
, HISTC_DSO_TO
, symlen
);
126 symlen
= unresolved_col_width
+ 4 + 2;
127 hists__new_col_len(hists
, HISTC_SYMBOL_TO
, symlen
);
128 hists__set_unres_dso_col_len(hists
, HISTC_DSO_TO
);
133 if (h
->mem_info
->daddr
.sym
) {
134 symlen
= (int)h
->mem_info
->daddr
.sym
->namelen
+ 4
135 + unresolved_col_width
+ 2;
136 hists__new_col_len(hists
, HISTC_MEM_DADDR_SYMBOL
,
139 symlen
= unresolved_col_width
+ 4 + 2;
140 hists__new_col_len(hists
, HISTC_MEM_DADDR_SYMBOL
,
143 if (h
->mem_info
->daddr
.map
) {
144 symlen
= dso__name_len(h
->mem_info
->daddr
.map
->dso
);
145 hists__new_col_len(hists
, HISTC_MEM_DADDR_DSO
,
148 symlen
= unresolved_col_width
+ 4 + 2;
149 hists__set_unres_dso_col_len(hists
, HISTC_MEM_DADDR_DSO
);
152 symlen
= unresolved_col_width
+ 4 + 2;
153 hists__new_col_len(hists
, HISTC_MEM_DADDR_SYMBOL
, symlen
);
154 hists__set_unres_dso_col_len(hists
, HISTC_MEM_DADDR_DSO
);
157 hists__new_col_len(hists
, HISTC_MEM_LOCKED
, 6);
158 hists__new_col_len(hists
, HISTC_MEM_TLB
, 22);
159 hists__new_col_len(hists
, HISTC_MEM_SNOOP
, 12);
160 hists__new_col_len(hists
, HISTC_MEM_LVL
, 21 + 3);
161 hists__new_col_len(hists
, HISTC_LOCAL_WEIGHT
, 12);
162 hists__new_col_len(hists
, HISTC_GLOBAL_WEIGHT
, 12);
165 hists__new_col_len(hists
, HISTC_TRANSACTION
,
166 hist_entry__transaction_len());
169 void hists__output_recalc_col_len(struct hists
*hists
, int max_rows
)
171 struct rb_node
*next
= rb_first(&hists
->entries
);
172 struct hist_entry
*n
;
175 hists__reset_col_len(hists
);
177 while (next
&& row
++ < max_rows
) {
178 n
= rb_entry(next
, struct hist_entry
, rb_node
);
180 hists__calc_col_len(hists
, n
);
181 next
= rb_next(&n
->rb_node
);
185 static void hist_entry__add_cpumode_period(struct hist_entry
*he
,
186 unsigned int cpumode
, u64 period
)
189 case PERF_RECORD_MISC_KERNEL
:
190 he
->stat
.period_sys
+= period
;
192 case PERF_RECORD_MISC_USER
:
193 he
->stat
.period_us
+= period
;
195 case PERF_RECORD_MISC_GUEST_KERNEL
:
196 he
->stat
.period_guest_sys
+= period
;
198 case PERF_RECORD_MISC_GUEST_USER
:
199 he
->stat
.period_guest_us
+= period
;
206 static void he_stat__add_period(struct he_stat
*he_stat
, u64 period
,
210 he_stat
->period
+= period
;
211 he_stat
->weight
+= weight
;
212 he_stat
->nr_events
+= 1;
215 static void he_stat__add_stat(struct he_stat
*dest
, struct he_stat
*src
)
217 dest
->period
+= src
->period
;
218 dest
->period_sys
+= src
->period_sys
;
219 dest
->period_us
+= src
->period_us
;
220 dest
->period_guest_sys
+= src
->period_guest_sys
;
221 dest
->period_guest_us
+= src
->period_guest_us
;
222 dest
->nr_events
+= src
->nr_events
;
223 dest
->weight
+= src
->weight
;
226 static void hist_entry__decay(struct hist_entry
*he
)
228 he
->stat
.period
= (he
->stat
.period
* 7) / 8;
229 he
->stat
.nr_events
= (he
->stat
.nr_events
* 7) / 8;
230 /* XXX need decay for weight too? */
233 static bool hists__decay_entry(struct hists
*hists
, struct hist_entry
*he
)
235 u64 prev_period
= he
->stat
.period
;
237 if (prev_period
== 0)
240 hist_entry__decay(he
);
243 hists
->stats
.total_period
-= prev_period
- he
->stat
.period
;
245 return he
->stat
.period
== 0;
248 void hists__decay_entries(struct hists
*hists
, bool zap_user
, bool zap_kernel
)
250 struct rb_node
*next
= rb_first(&hists
->entries
);
251 struct hist_entry
*n
;
254 n
= rb_entry(next
, struct hist_entry
, rb_node
);
255 next
= rb_next(&n
->rb_node
);
257 * We may be annotating this, for instance, so keep it here in
258 * case some it gets new samples, we'll eventually free it when
259 * the user stops browsing and it agains gets fully decayed.
261 if (((zap_user
&& n
->level
== '.') ||
262 (zap_kernel
&& n
->level
!= '.') ||
263 hists__decay_entry(hists
, n
)) &&
265 rb_erase(&n
->rb_node
, &hists
->entries
);
267 if (sort__need_collapse
)
268 rb_erase(&n
->rb_node_in
, &hists
->entries_collapsed
);
277 * histogram, sorted on item, collects periods
280 static struct hist_entry
*hist_entry__new(struct hist_entry
*template)
282 size_t callchain_size
= symbol_conf
.use_callchain
? sizeof(struct callchain_root
) : 0;
283 struct hist_entry
*he
= zalloc(sizeof(*he
) + callchain_size
);
289 he
->ms
.map
->referenced
= true;
291 if (he
->branch_info
) {
293 * This branch info is (a part of) allocated from
294 * machine__resolve_bstack() and will be freed after
295 * adding new entries. So we need to save a copy.
297 he
->branch_info
= malloc(sizeof(*he
->branch_info
));
298 if (he
->branch_info
== NULL
) {
303 memcpy(he
->branch_info
, template->branch_info
,
304 sizeof(*he
->branch_info
));
306 if (he
->branch_info
->from
.map
)
307 he
->branch_info
->from
.map
->referenced
= true;
308 if (he
->branch_info
->to
.map
)
309 he
->branch_info
->to
.map
->referenced
= true;
313 if (he
->mem_info
->iaddr
.map
)
314 he
->mem_info
->iaddr
.map
->referenced
= true;
315 if (he
->mem_info
->daddr
.map
)
316 he
->mem_info
->daddr
.map
->referenced
= true;
319 if (symbol_conf
.use_callchain
)
320 callchain_init(he
->callchain
);
322 INIT_LIST_HEAD(&he
->pairs
.node
);
328 void hists__inc_nr_entries(struct hists
*hists
, struct hist_entry
*h
)
331 hists__calc_col_len(hists
, h
);
333 hists
->stats
.total_period
+= h
->stat
.period
;
337 static u8
symbol__parent_filter(const struct symbol
*parent
)
339 if (symbol_conf
.exclude_other
&& parent
== NULL
)
340 return 1 << HIST_FILTER__PARENT
;
344 static struct hist_entry
*add_hist_entry(struct hists
*hists
,
345 struct hist_entry
*entry
,
346 struct addr_location
*al
,
351 struct rb_node
*parent
= NULL
;
352 struct hist_entry
*he
;
355 p
= &hists
->entries_in
->rb_node
;
359 he
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
362 * Make sure that it receives arguments in a same order as
363 * hist_entry__collapse() so that we can use an appropriate
364 * function when searching an entry regardless which sort
367 cmp
= hist_entry__cmp(he
, entry
);
370 he_stat__add_period(&he
->stat
, period
, weight
);
373 * This mem info was allocated from machine__resolve_mem
374 * and will not be used anymore.
376 free(entry
->mem_info
);
378 /* If the map of an existing hist_entry has
379 * become out-of-date due to an exec() or
380 * similar, update it. Otherwise we will
381 * mis-adjust symbol addresses when computing
382 * the history counter to increment.
384 if (he
->ms
.map
!= entry
->ms
.map
) {
385 he
->ms
.map
= entry
->ms
.map
;
387 he
->ms
.map
->referenced
= true;
398 he
= hist_entry__new(entry
);
402 rb_link_node(&he
->rb_node_in
, parent
, p
);
403 rb_insert_color(&he
->rb_node_in
, hists
->entries_in
);
405 hist_entry__add_cpumode_period(he
, al
->cpumode
, period
);
409 struct hist_entry
*__hists__add_mem_entry(struct hists
*self
,
410 struct addr_location
*al
,
411 struct symbol
*sym_parent
,
416 struct hist_entry entry
= {
417 .thread
= al
->thread
,
430 .parent
= sym_parent
,
431 .filtered
= symbol__parent_filter(sym_parent
),
436 return add_hist_entry(self
, &entry
, al
, period
, weight
);
439 struct hist_entry
*__hists__add_branch_entry(struct hists
*self
,
440 struct addr_location
*al
,
441 struct symbol
*sym_parent
,
442 struct branch_info
*bi
,
446 struct hist_entry entry
= {
447 .thread
= al
->thread
,
460 .parent
= sym_parent
,
461 .filtered
= symbol__parent_filter(sym_parent
),
467 return add_hist_entry(self
, &entry
, al
, period
, weight
);
470 struct hist_entry
*__hists__add_entry(struct hists
*self
,
471 struct addr_location
*al
,
472 struct symbol
*sym_parent
, u64 period
,
473 u64 weight
, u64 transaction
)
475 struct hist_entry entry
= {
476 .thread
= al
->thread
,
489 .parent
= sym_parent
,
490 .filtered
= symbol__parent_filter(sym_parent
),
494 .transaction
= transaction
,
497 return add_hist_entry(self
, &entry
, al
, period
, weight
);
501 hist_entry__cmp(struct hist_entry
*left
, struct hist_entry
*right
)
503 struct sort_entry
*se
;
506 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
507 cmp
= se
->se_cmp(left
, right
);
516 hist_entry__collapse(struct hist_entry
*left
, struct hist_entry
*right
)
518 struct sort_entry
*se
;
521 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
522 int64_t (*f
)(struct hist_entry
*, struct hist_entry
*);
524 f
= se
->se_collapse
?: se
->se_cmp
;
526 cmp
= f(left
, right
);
534 void hist_entry__free(struct hist_entry
*he
)
536 free(he
->branch_info
);
542 * collapse the histogram
545 static bool hists__collapse_insert_entry(struct hists
*hists __maybe_unused
,
546 struct rb_root
*root
,
547 struct hist_entry
*he
)
549 struct rb_node
**p
= &root
->rb_node
;
550 struct rb_node
*parent
= NULL
;
551 struct hist_entry
*iter
;
556 iter
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
558 cmp
= hist_entry__collapse(iter
, he
);
561 he_stat__add_stat(&iter
->stat
, &he
->stat
);
563 if (symbol_conf
.use_callchain
) {
564 callchain_cursor_reset(&callchain_cursor
);
565 callchain_merge(&callchain_cursor
,
569 hist_entry__free(he
);
579 rb_link_node(&he
->rb_node_in
, parent
, p
);
580 rb_insert_color(&he
->rb_node_in
, root
);
584 static struct rb_root
*hists__get_rotate_entries_in(struct hists
*hists
)
586 struct rb_root
*root
;
588 pthread_mutex_lock(&hists
->lock
);
590 root
= hists
->entries_in
;
591 if (++hists
->entries_in
> &hists
->entries_in_array
[1])
592 hists
->entries_in
= &hists
->entries_in_array
[0];
594 pthread_mutex_unlock(&hists
->lock
);
599 static void hists__apply_filters(struct hists
*hists
, struct hist_entry
*he
)
601 hists__filter_entry_by_dso(hists
, he
);
602 hists__filter_entry_by_thread(hists
, he
);
603 hists__filter_entry_by_symbol(hists
, he
);
606 void hists__collapse_resort(struct hists
*hists
)
608 struct rb_root
*root
;
609 struct rb_node
*next
;
610 struct hist_entry
*n
;
612 if (!sort__need_collapse
)
615 root
= hists__get_rotate_entries_in(hists
);
616 next
= rb_first(root
);
621 n
= rb_entry(next
, struct hist_entry
, rb_node_in
);
622 next
= rb_next(&n
->rb_node_in
);
624 rb_erase(&n
->rb_node_in
, root
);
625 if (hists__collapse_insert_entry(hists
, &hists
->entries_collapsed
, n
)) {
627 * If it wasn't combined with one of the entries already
628 * collapsed, we need to apply the filters that may have
629 * been set by, say, the hist_browser.
631 hists__apply_filters(hists
, n
);
637 * reverse the map, sort on period.
640 static int period_cmp(u64 period_a
, u64 period_b
)
642 if (period_a
> period_b
)
644 if (period_a
< period_b
)
649 static int hist_entry__sort_on_period(struct hist_entry
*a
,
650 struct hist_entry
*b
)
654 struct perf_evsel
*evsel
;
655 struct hist_entry
*pair
;
656 u64
*periods_a
, *periods_b
;
658 ret
= period_cmp(a
->stat
.period
, b
->stat
.period
);
659 if (ret
|| !symbol_conf
.event_group
)
662 evsel
= hists_to_evsel(a
->hists
);
663 nr_members
= evsel
->nr_members
;
667 periods_a
= zalloc(sizeof(periods_a
) * nr_members
);
668 periods_b
= zalloc(sizeof(periods_b
) * nr_members
);
670 if (!periods_a
|| !periods_b
)
673 list_for_each_entry(pair
, &a
->pairs
.head
, pairs
.node
) {
674 evsel
= hists_to_evsel(pair
->hists
);
675 periods_a
[perf_evsel__group_idx(evsel
)] = pair
->stat
.period
;
678 list_for_each_entry(pair
, &b
->pairs
.head
, pairs
.node
) {
679 evsel
= hists_to_evsel(pair
->hists
);
680 periods_b
[perf_evsel__group_idx(evsel
)] = pair
->stat
.period
;
683 for (i
= 1; i
< nr_members
; i
++) {
684 ret
= period_cmp(periods_a
[i
], periods_b
[i
]);
696 static void __hists__insert_output_entry(struct rb_root
*entries
,
697 struct hist_entry
*he
,
698 u64 min_callchain_hits
)
700 struct rb_node
**p
= &entries
->rb_node
;
701 struct rb_node
*parent
= NULL
;
702 struct hist_entry
*iter
;
704 if (symbol_conf
.use_callchain
)
705 callchain_param
.sort(&he
->sorted_chain
, he
->callchain
,
706 min_callchain_hits
, &callchain_param
);
710 iter
= rb_entry(parent
, struct hist_entry
, rb_node
);
712 if (hist_entry__sort_on_period(he
, iter
) > 0)
718 rb_link_node(&he
->rb_node
, parent
, p
);
719 rb_insert_color(&he
->rb_node
, entries
);
722 void hists__output_resort(struct hists
*hists
)
724 struct rb_root
*root
;
725 struct rb_node
*next
;
726 struct hist_entry
*n
;
727 u64 min_callchain_hits
;
729 min_callchain_hits
= hists
->stats
.total_period
* (callchain_param
.min_percent
/ 100);
731 if (sort__need_collapse
)
732 root
= &hists
->entries_collapsed
;
734 root
= hists
->entries_in
;
736 next
= rb_first(root
);
737 hists
->entries
= RB_ROOT
;
739 hists
->nr_entries
= 0;
740 hists
->stats
.total_period
= 0;
741 hists__reset_col_len(hists
);
744 n
= rb_entry(next
, struct hist_entry
, rb_node_in
);
745 next
= rb_next(&n
->rb_node_in
);
747 __hists__insert_output_entry(&hists
->entries
, n
, min_callchain_hits
);
748 hists__inc_nr_entries(hists
, n
);
752 static void hists__remove_entry_filter(struct hists
*hists
, struct hist_entry
*h
,
753 enum hist_filter filter
)
755 h
->filtered
&= ~(1 << filter
);
761 hists
->nr_entries
+= h
->nr_rows
;
763 hists
->stats
.total_period
+= h
->stat
.period
;
764 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] += h
->stat
.nr_events
;
766 hists__calc_col_len(hists
, h
);
770 static bool hists__filter_entry_by_dso(struct hists
*hists
,
771 struct hist_entry
*he
)
773 if (hists
->dso_filter
!= NULL
&&
774 (he
->ms
.map
== NULL
|| he
->ms
.map
->dso
!= hists
->dso_filter
)) {
775 he
->filtered
|= (1 << HIST_FILTER__DSO
);
782 void hists__filter_by_dso(struct hists
*hists
)
786 hists
->nr_entries
= hists
->stats
.total_period
= 0;
787 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
788 hists__reset_col_len(hists
);
790 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
791 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
793 if (symbol_conf
.exclude_other
&& !h
->parent
)
796 if (hists__filter_entry_by_dso(hists
, h
))
799 hists__remove_entry_filter(hists
, h
, HIST_FILTER__DSO
);
803 static bool hists__filter_entry_by_thread(struct hists
*hists
,
804 struct hist_entry
*he
)
806 if (hists
->thread_filter
!= NULL
&&
807 he
->thread
!= hists
->thread_filter
) {
808 he
->filtered
|= (1 << HIST_FILTER__THREAD
);
815 void hists__filter_by_thread(struct hists
*hists
)
819 hists
->nr_entries
= hists
->stats
.total_period
= 0;
820 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
821 hists__reset_col_len(hists
);
823 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
824 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
826 if (hists__filter_entry_by_thread(hists
, h
))
829 hists__remove_entry_filter(hists
, h
, HIST_FILTER__THREAD
);
833 static bool hists__filter_entry_by_symbol(struct hists
*hists
,
834 struct hist_entry
*he
)
836 if (hists
->symbol_filter_str
!= NULL
&&
837 (!he
->ms
.sym
|| strstr(he
->ms
.sym
->name
,
838 hists
->symbol_filter_str
) == NULL
)) {
839 he
->filtered
|= (1 << HIST_FILTER__SYMBOL
);
846 void hists__filter_by_symbol(struct hists
*hists
)
850 hists
->nr_entries
= hists
->stats
.total_period
= 0;
851 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
852 hists__reset_col_len(hists
);
854 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
855 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
857 if (hists__filter_entry_by_symbol(hists
, h
))
860 hists__remove_entry_filter(hists
, h
, HIST_FILTER__SYMBOL
);
864 int hist_entry__inc_addr_samples(struct hist_entry
*he
, int evidx
, u64 ip
)
866 return symbol__inc_addr_samples(he
->ms
.sym
, he
->ms
.map
, evidx
, ip
);
869 int hist_entry__annotate(struct hist_entry
*he
, size_t privsize
)
871 return symbol__annotate(he
->ms
.sym
, he
->ms
.map
, privsize
);
874 void events_stats__inc(struct events_stats
*stats
, u32 type
)
876 ++stats
->nr_events
[0];
877 ++stats
->nr_events
[type
];
880 void hists__inc_nr_events(struct hists
*hists
, u32 type
)
882 events_stats__inc(&hists
->stats
, type
);
885 static struct hist_entry
*hists__add_dummy_entry(struct hists
*hists
,
886 struct hist_entry
*pair
)
888 struct rb_root
*root
;
890 struct rb_node
*parent
= NULL
;
891 struct hist_entry
*he
;
894 if (sort__need_collapse
)
895 root
= &hists
->entries_collapsed
;
897 root
= hists
->entries_in
;
903 he
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
905 cmp
= hist_entry__collapse(he
, pair
);
916 he
= hist_entry__new(pair
);
918 memset(&he
->stat
, 0, sizeof(he
->stat
));
920 rb_link_node(&he
->rb_node_in
, parent
, p
);
921 rb_insert_color(&he
->rb_node_in
, root
);
922 hists__inc_nr_entries(hists
, he
);
929 static struct hist_entry
*hists__find_entry(struct hists
*hists
,
930 struct hist_entry
*he
)
934 if (sort__need_collapse
)
935 n
= hists
->entries_collapsed
.rb_node
;
937 n
= hists
->entries_in
->rb_node
;
940 struct hist_entry
*iter
= rb_entry(n
, struct hist_entry
, rb_node_in
);
941 int64_t cmp
= hist_entry__collapse(iter
, he
);
955 * Look for pairs to link to the leader buckets (hist_entries):
957 void hists__match(struct hists
*leader
, struct hists
*other
)
959 struct rb_root
*root
;
961 struct hist_entry
*pos
, *pair
;
963 if (sort__need_collapse
)
964 root
= &leader
->entries_collapsed
;
966 root
= leader
->entries_in
;
968 for (nd
= rb_first(root
); nd
; nd
= rb_next(nd
)) {
969 pos
= rb_entry(nd
, struct hist_entry
, rb_node_in
);
970 pair
= hists__find_entry(other
, pos
);
973 hist_entry__add_pair(pair
, pos
);
978 * Look for entries in the other hists that are not present in the leader, if
979 * we find them, just add a dummy entry on the leader hists, with period=0,
980 * nr_events=0, to serve as the list header.
982 int hists__link(struct hists
*leader
, struct hists
*other
)
984 struct rb_root
*root
;
986 struct hist_entry
*pos
, *pair
;
988 if (sort__need_collapse
)
989 root
= &other
->entries_collapsed
;
991 root
= other
->entries_in
;
993 for (nd
= rb_first(root
); nd
; nd
= rb_next(nd
)) {
994 pos
= rb_entry(nd
, struct hist_entry
, rb_node_in
);
996 if (!hist_entry__has_pairs(pos
)) {
997 pair
= hists__add_dummy_entry(leader
, pos
);
1000 hist_entry__add_pair(pos
, pair
);