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
,
30 u16
hists__col_len(struct hists
*hists
, enum hist_column col
)
32 return hists
->col_len
[col
];
35 void hists__set_col_len(struct hists
*hists
, enum hist_column col
, u16 len
)
37 hists
->col_len
[col
] = len
;
40 bool hists__new_col_len(struct hists
*hists
, enum hist_column col
, u16 len
)
42 if (len
> hists__col_len(hists
, col
)) {
43 hists__set_col_len(hists
, col
, len
);
49 void hists__reset_col_len(struct hists
*hists
)
53 for (col
= 0; col
< HISTC_NR_COLS
; ++col
)
54 hists__set_col_len(hists
, col
, 0);
57 static void hists__set_unres_dso_col_len(struct hists
*hists
, int dso
)
59 const unsigned int unresolved_col_width
= BITS_PER_LONG
/ 4;
61 if (hists__col_len(hists
, dso
) < unresolved_col_width
&&
62 !symbol_conf
.col_width_list_str
&& !symbol_conf
.field_sep
&&
63 !symbol_conf
.dso_list
)
64 hists__set_col_len(hists
, dso
, unresolved_col_width
);
67 void hists__calc_col_len(struct hists
*hists
, struct hist_entry
*h
)
69 const unsigned int unresolved_col_width
= BITS_PER_LONG
/ 4;
74 * +4 accounts for '[x] ' priv level info
75 * +2 accounts for 0x prefix on raw addresses
76 * +3 accounts for ' y ' symtab origin info
79 symlen
= h
->ms
.sym
->namelen
+ 4;
81 symlen
+= BITS_PER_LONG
/ 4 + 2 + 3;
82 hists__new_col_len(hists
, HISTC_SYMBOL
, symlen
);
84 symlen
= unresolved_col_width
+ 4 + 2;
85 hists__new_col_len(hists
, HISTC_SYMBOL
, symlen
);
86 hists__set_unres_dso_col_len(hists
, HISTC_DSO
);
89 len
= thread__comm_len(h
->thread
);
90 if (hists__new_col_len(hists
, HISTC_COMM
, len
))
91 hists__set_col_len(hists
, HISTC_THREAD
, len
+ 6);
94 len
= dso__name_len(h
->ms
.map
->dso
);
95 hists__new_col_len(hists
, HISTC_DSO
, len
);
99 hists__new_col_len(hists
, HISTC_PARENT
, h
->parent
->namelen
);
101 if (h
->branch_info
) {
102 if (h
->branch_info
->from
.sym
) {
103 symlen
= (int)h
->branch_info
->from
.sym
->namelen
+ 4;
105 symlen
+= BITS_PER_LONG
/ 4 + 2 + 3;
106 hists__new_col_len(hists
, HISTC_SYMBOL_FROM
, symlen
);
108 symlen
= dso__name_len(h
->branch_info
->from
.map
->dso
);
109 hists__new_col_len(hists
, HISTC_DSO_FROM
, symlen
);
111 symlen
= unresolved_col_width
+ 4 + 2;
112 hists__new_col_len(hists
, HISTC_SYMBOL_FROM
, symlen
);
113 hists__set_unres_dso_col_len(hists
, HISTC_DSO_FROM
);
116 if (h
->branch_info
->to
.sym
) {
117 symlen
= (int)h
->branch_info
->to
.sym
->namelen
+ 4;
119 symlen
+= BITS_PER_LONG
/ 4 + 2 + 3;
120 hists__new_col_len(hists
, HISTC_SYMBOL_TO
, symlen
);
122 symlen
= dso__name_len(h
->branch_info
->to
.map
->dso
);
123 hists__new_col_len(hists
, HISTC_DSO_TO
, symlen
);
125 symlen
= unresolved_col_width
+ 4 + 2;
126 hists__new_col_len(hists
, HISTC_SYMBOL_TO
, symlen
);
127 hists__set_unres_dso_col_len(hists
, HISTC_DSO_TO
);
132 if (h
->mem_info
->daddr
.sym
) {
133 symlen
= (int)h
->mem_info
->daddr
.sym
->namelen
+ 4
134 + unresolved_col_width
+ 2;
135 hists__new_col_len(hists
, HISTC_MEM_DADDR_SYMBOL
,
138 symlen
= unresolved_col_width
+ 4 + 2;
139 hists__new_col_len(hists
, HISTC_MEM_DADDR_SYMBOL
,
142 if (h
->mem_info
->daddr
.map
) {
143 symlen
= dso__name_len(h
->mem_info
->daddr
.map
->dso
);
144 hists__new_col_len(hists
, HISTC_MEM_DADDR_DSO
,
147 symlen
= unresolved_col_width
+ 4 + 2;
148 hists__set_unres_dso_col_len(hists
, HISTC_MEM_DADDR_DSO
);
151 symlen
= unresolved_col_width
+ 4 + 2;
152 hists__new_col_len(hists
, HISTC_MEM_DADDR_SYMBOL
, symlen
);
153 hists__set_unres_dso_col_len(hists
, HISTC_MEM_DADDR_DSO
);
156 hists__new_col_len(hists
, HISTC_MEM_LOCKED
, 6);
157 hists__new_col_len(hists
, HISTC_MEM_TLB
, 22);
158 hists__new_col_len(hists
, HISTC_MEM_SNOOP
, 12);
159 hists__new_col_len(hists
, HISTC_MEM_LVL
, 21 + 3);
160 hists__new_col_len(hists
, HISTC_LOCAL_WEIGHT
, 12);
161 hists__new_col_len(hists
, HISTC_GLOBAL_WEIGHT
, 12);
164 void hists__output_recalc_col_len(struct hists
*hists
, int max_rows
)
166 struct rb_node
*next
= rb_first(&hists
->entries
);
167 struct hist_entry
*n
;
170 hists__reset_col_len(hists
);
172 while (next
&& row
++ < max_rows
) {
173 n
= rb_entry(next
, struct hist_entry
, rb_node
);
175 hists__calc_col_len(hists
, n
);
176 next
= rb_next(&n
->rb_node
);
180 static void hist_entry__add_cpumode_period(struct hist_entry
*he
,
181 unsigned int cpumode
, u64 period
)
184 case PERF_RECORD_MISC_KERNEL
:
185 he
->stat
.period_sys
+= period
;
187 case PERF_RECORD_MISC_USER
:
188 he
->stat
.period_us
+= period
;
190 case PERF_RECORD_MISC_GUEST_KERNEL
:
191 he
->stat
.period_guest_sys
+= period
;
193 case PERF_RECORD_MISC_GUEST_USER
:
194 he
->stat
.period_guest_us
+= period
;
201 static void he_stat__add_period(struct he_stat
*he_stat
, u64 period
,
205 he_stat
->period
+= period
;
206 he_stat
->weight
+= weight
;
207 he_stat
->nr_events
+= 1;
210 static void he_stat__add_stat(struct he_stat
*dest
, struct he_stat
*src
)
212 dest
->period
+= src
->period
;
213 dest
->period_sys
+= src
->period_sys
;
214 dest
->period_us
+= src
->period_us
;
215 dest
->period_guest_sys
+= src
->period_guest_sys
;
216 dest
->period_guest_us
+= src
->period_guest_us
;
217 dest
->nr_events
+= src
->nr_events
;
218 dest
->weight
+= src
->weight
;
221 static void hist_entry__decay(struct hist_entry
*he
)
223 he
->stat
.period
= (he
->stat
.period
* 7) / 8;
224 he
->stat
.nr_events
= (he
->stat
.nr_events
* 7) / 8;
225 /* XXX need decay for weight too? */
228 static bool hists__decay_entry(struct hists
*hists
, struct hist_entry
*he
)
230 u64 prev_period
= he
->stat
.period
;
232 if (prev_period
== 0)
235 hist_entry__decay(he
);
238 hists
->stats
.total_period
-= prev_period
- he
->stat
.period
;
240 return he
->stat
.period
== 0;
243 static void __hists__decay_entries(struct hists
*hists
, bool zap_user
,
244 bool zap_kernel
, bool threaded
)
246 struct rb_node
*next
= rb_first(&hists
->entries
);
247 struct hist_entry
*n
;
250 n
= rb_entry(next
, struct hist_entry
, rb_node
);
251 next
= rb_next(&n
->rb_node
);
253 * We may be annotating this, for instance, so keep it here in
254 * case some it gets new samples, we'll eventually free it when
255 * the user stops browsing and it agains gets fully decayed.
257 if (((zap_user
&& n
->level
== '.') ||
258 (zap_kernel
&& n
->level
!= '.') ||
259 hists__decay_entry(hists
, n
)) &&
261 rb_erase(&n
->rb_node
, &hists
->entries
);
263 if (sort__need_collapse
|| threaded
)
264 rb_erase(&n
->rb_node_in
, &hists
->entries_collapsed
);
272 void hists__decay_entries(struct hists
*hists
, bool zap_user
, bool zap_kernel
)
274 return __hists__decay_entries(hists
, zap_user
, zap_kernel
, false);
277 void hists__decay_entries_threaded(struct hists
*hists
,
278 bool zap_user
, bool zap_kernel
)
280 return __hists__decay_entries(hists
, zap_user
, zap_kernel
, true);
284 * histogram, sorted on item, collects periods
287 static struct hist_entry
*hist_entry__new(struct hist_entry
*template)
289 size_t callchain_size
= symbol_conf
.use_callchain
? sizeof(struct callchain_root
) : 0;
290 struct hist_entry
*he
= zalloc(sizeof(*he
) + callchain_size
);
296 he
->ms
.map
->referenced
= true;
298 if (he
->branch_info
) {
300 * This branch info is (a part of) allocated from
301 * machine__resolve_bstack() and will be freed after
302 * adding new entries. So we need to save a copy.
304 he
->branch_info
= malloc(sizeof(*he
->branch_info
));
305 if (he
->branch_info
== NULL
) {
310 memcpy(he
->branch_info
, template->branch_info
,
311 sizeof(*he
->branch_info
));
313 if (he
->branch_info
->from
.map
)
314 he
->branch_info
->from
.map
->referenced
= true;
315 if (he
->branch_info
->to
.map
)
316 he
->branch_info
->to
.map
->referenced
= true;
320 if (he
->mem_info
->iaddr
.map
)
321 he
->mem_info
->iaddr
.map
->referenced
= true;
322 if (he
->mem_info
->daddr
.map
)
323 he
->mem_info
->daddr
.map
->referenced
= true;
326 if (symbol_conf
.use_callchain
)
327 callchain_init(he
->callchain
);
329 INIT_LIST_HEAD(&he
->pairs
.node
);
335 void hists__inc_nr_entries(struct hists
*hists
, struct hist_entry
*h
)
338 hists__calc_col_len(hists
, h
);
340 hists
->stats
.total_period
+= h
->stat
.period
;
344 static u8
symbol__parent_filter(const struct symbol
*parent
)
346 if (symbol_conf
.exclude_other
&& parent
== NULL
)
347 return 1 << HIST_FILTER__PARENT
;
351 static struct hist_entry
*add_hist_entry(struct hists
*hists
,
352 struct hist_entry
*entry
,
353 struct addr_location
*al
,
358 struct rb_node
*parent
= NULL
;
359 struct hist_entry
*he
;
362 pthread_mutex_lock(&hists
->lock
);
364 p
= &hists
->entries_in
->rb_node
;
368 he
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
371 * Make sure that it receives arguments in a same order as
372 * hist_entry__collapse() so that we can use an appropriate
373 * function when searching an entry regardless which sort
376 cmp
= hist_entry__cmp(he
, entry
);
379 he_stat__add_period(&he
->stat
, period
, weight
);
382 * This mem info was allocated from machine__resolve_mem
383 * and will not be used anymore.
385 free(entry
->mem_info
);
387 /* If the map of an existing hist_entry has
388 * become out-of-date due to an exec() or
389 * similar, update it. Otherwise we will
390 * mis-adjust symbol addresses when computing
391 * the history counter to increment.
393 if (he
->ms
.map
!= entry
->ms
.map
) {
394 he
->ms
.map
= entry
->ms
.map
;
396 he
->ms
.map
->referenced
= true;
407 he
= hist_entry__new(entry
);
411 rb_link_node(&he
->rb_node_in
, parent
, p
);
412 rb_insert_color(&he
->rb_node_in
, hists
->entries_in
);
414 hist_entry__add_cpumode_period(he
, al
->cpumode
, period
);
416 pthread_mutex_unlock(&hists
->lock
);
420 struct hist_entry
*__hists__add_mem_entry(struct hists
*self
,
421 struct addr_location
*al
,
422 struct symbol
*sym_parent
,
427 struct hist_entry entry
= {
428 .thread
= al
->thread
,
441 .parent
= sym_parent
,
442 .filtered
= symbol__parent_filter(sym_parent
),
447 return add_hist_entry(self
, &entry
, al
, period
, weight
);
450 struct hist_entry
*__hists__add_branch_entry(struct hists
*self
,
451 struct addr_location
*al
,
452 struct symbol
*sym_parent
,
453 struct branch_info
*bi
,
457 struct hist_entry entry
= {
458 .thread
= al
->thread
,
471 .parent
= sym_parent
,
472 .filtered
= symbol__parent_filter(sym_parent
),
478 return add_hist_entry(self
, &entry
, al
, period
, weight
);
481 struct hist_entry
*__hists__add_entry(struct hists
*self
,
482 struct addr_location
*al
,
483 struct symbol
*sym_parent
, u64 period
,
486 struct hist_entry entry
= {
487 .thread
= al
->thread
,
500 .parent
= sym_parent
,
501 .filtered
= symbol__parent_filter(sym_parent
),
507 return add_hist_entry(self
, &entry
, al
, period
, weight
);
511 hist_entry__cmp(struct hist_entry
*left
, struct hist_entry
*right
)
513 struct sort_entry
*se
;
516 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
517 cmp
= se
->se_cmp(left
, right
);
526 hist_entry__collapse(struct hist_entry
*left
, struct hist_entry
*right
)
528 struct sort_entry
*se
;
531 list_for_each_entry(se
, &hist_entry__sort_list
, list
) {
532 int64_t (*f
)(struct hist_entry
*, struct hist_entry
*);
534 f
= se
->se_collapse
?: se
->se_cmp
;
536 cmp
= f(left
, right
);
544 void hist_entry__free(struct hist_entry
*he
)
546 free(he
->branch_info
);
552 * collapse the histogram
555 static bool hists__collapse_insert_entry(struct hists
*hists __maybe_unused
,
556 struct rb_root
*root
,
557 struct hist_entry
*he
)
559 struct rb_node
**p
= &root
->rb_node
;
560 struct rb_node
*parent
= NULL
;
561 struct hist_entry
*iter
;
566 iter
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
568 cmp
= hist_entry__collapse(iter
, he
);
571 he_stat__add_stat(&iter
->stat
, &he
->stat
);
573 if (symbol_conf
.use_callchain
) {
574 callchain_cursor_reset(&callchain_cursor
);
575 callchain_merge(&callchain_cursor
,
579 hist_entry__free(he
);
589 rb_link_node(&he
->rb_node_in
, parent
, p
);
590 rb_insert_color(&he
->rb_node_in
, root
);
594 static struct rb_root
*hists__get_rotate_entries_in(struct hists
*hists
)
596 struct rb_root
*root
;
598 pthread_mutex_lock(&hists
->lock
);
600 root
= hists
->entries_in
;
601 if (++hists
->entries_in
> &hists
->entries_in_array
[1])
602 hists
->entries_in
= &hists
->entries_in_array
[0];
604 pthread_mutex_unlock(&hists
->lock
);
609 static void hists__apply_filters(struct hists
*hists
, struct hist_entry
*he
)
611 hists__filter_entry_by_dso(hists
, he
);
612 hists__filter_entry_by_thread(hists
, he
);
613 hists__filter_entry_by_symbol(hists
, he
);
616 static void __hists__collapse_resort(struct hists
*hists
, bool threaded
)
618 struct rb_root
*root
;
619 struct rb_node
*next
;
620 struct hist_entry
*n
;
622 if (!sort__need_collapse
&& !threaded
)
625 root
= hists__get_rotate_entries_in(hists
);
626 next
= rb_first(root
);
629 n
= rb_entry(next
, struct hist_entry
, rb_node_in
);
630 next
= rb_next(&n
->rb_node_in
);
632 rb_erase(&n
->rb_node_in
, root
);
633 if (hists__collapse_insert_entry(hists
, &hists
->entries_collapsed
, n
)) {
635 * If it wasn't combined with one of the entries already
636 * collapsed, we need to apply the filters that may have
637 * been set by, say, the hist_browser.
639 hists__apply_filters(hists
, n
);
644 void hists__collapse_resort(struct hists
*hists
)
646 return __hists__collapse_resort(hists
, false);
649 void hists__collapse_resort_threaded(struct hists
*hists
)
651 return __hists__collapse_resort(hists
, true);
655 * reverse the map, sort on period.
658 static int period_cmp(u64 period_a
, u64 period_b
)
660 if (period_a
> period_b
)
662 if (period_a
< period_b
)
667 static int hist_entry__sort_on_period(struct hist_entry
*a
,
668 struct hist_entry
*b
)
672 struct perf_evsel
*evsel
;
673 struct hist_entry
*pair
;
674 u64
*periods_a
, *periods_b
;
676 ret
= period_cmp(a
->stat
.period
, b
->stat
.period
);
677 if (ret
|| !symbol_conf
.event_group
)
680 evsel
= hists_to_evsel(a
->hists
);
681 nr_members
= evsel
->nr_members
;
685 periods_a
= zalloc(sizeof(periods_a
) * nr_members
);
686 periods_b
= zalloc(sizeof(periods_b
) * nr_members
);
688 if (!periods_a
|| !periods_b
)
691 list_for_each_entry(pair
, &a
->pairs
.head
, pairs
.node
) {
692 evsel
= hists_to_evsel(pair
->hists
);
693 periods_a
[perf_evsel__group_idx(evsel
)] = pair
->stat
.period
;
696 list_for_each_entry(pair
, &b
->pairs
.head
, pairs
.node
) {
697 evsel
= hists_to_evsel(pair
->hists
);
698 periods_b
[perf_evsel__group_idx(evsel
)] = pair
->stat
.period
;
701 for (i
= 1; i
< nr_members
; i
++) {
702 ret
= period_cmp(periods_a
[i
], periods_b
[i
]);
714 static void __hists__insert_output_entry(struct rb_root
*entries
,
715 struct hist_entry
*he
,
716 u64 min_callchain_hits
)
718 struct rb_node
**p
= &entries
->rb_node
;
719 struct rb_node
*parent
= NULL
;
720 struct hist_entry
*iter
;
722 if (symbol_conf
.use_callchain
)
723 callchain_param
.sort(&he
->sorted_chain
, he
->callchain
,
724 min_callchain_hits
, &callchain_param
);
728 iter
= rb_entry(parent
, struct hist_entry
, rb_node
);
730 if (hist_entry__sort_on_period(he
, iter
) > 0)
736 rb_link_node(&he
->rb_node
, parent
, p
);
737 rb_insert_color(&he
->rb_node
, entries
);
740 static void __hists__output_resort(struct hists
*hists
, bool threaded
)
742 struct rb_root
*root
;
743 struct rb_node
*next
;
744 struct hist_entry
*n
;
745 u64 min_callchain_hits
;
747 min_callchain_hits
= hists
->stats
.total_period
* (callchain_param
.min_percent
/ 100);
749 if (sort__need_collapse
|| threaded
)
750 root
= &hists
->entries_collapsed
;
752 root
= hists
->entries_in
;
754 next
= rb_first(root
);
755 hists
->entries
= RB_ROOT
;
757 hists
->nr_entries
= 0;
758 hists
->stats
.total_period
= 0;
759 hists__reset_col_len(hists
);
762 n
= rb_entry(next
, struct hist_entry
, rb_node_in
);
763 next
= rb_next(&n
->rb_node_in
);
765 __hists__insert_output_entry(&hists
->entries
, n
, min_callchain_hits
);
766 hists__inc_nr_entries(hists
, n
);
770 void hists__output_resort(struct hists
*hists
)
772 return __hists__output_resort(hists
, false);
775 void hists__output_resort_threaded(struct hists
*hists
)
777 return __hists__output_resort(hists
, true);
780 static void hists__remove_entry_filter(struct hists
*hists
, struct hist_entry
*h
,
781 enum hist_filter filter
)
783 h
->filtered
&= ~(1 << filter
);
789 hists
->nr_entries
+= h
->nr_rows
;
791 hists
->stats
.total_period
+= h
->stat
.period
;
792 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] += h
->stat
.nr_events
;
794 hists__calc_col_len(hists
, h
);
798 static bool hists__filter_entry_by_dso(struct hists
*hists
,
799 struct hist_entry
*he
)
801 if (hists
->dso_filter
!= NULL
&&
802 (he
->ms
.map
== NULL
|| he
->ms
.map
->dso
!= hists
->dso_filter
)) {
803 he
->filtered
|= (1 << HIST_FILTER__DSO
);
810 void hists__filter_by_dso(struct hists
*hists
)
814 hists
->nr_entries
= hists
->stats
.total_period
= 0;
815 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
816 hists__reset_col_len(hists
);
818 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
819 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
821 if (symbol_conf
.exclude_other
&& !h
->parent
)
824 if (hists__filter_entry_by_dso(hists
, h
))
827 hists__remove_entry_filter(hists
, h
, HIST_FILTER__DSO
);
831 static bool hists__filter_entry_by_thread(struct hists
*hists
,
832 struct hist_entry
*he
)
834 if (hists
->thread_filter
!= NULL
&&
835 he
->thread
!= hists
->thread_filter
) {
836 he
->filtered
|= (1 << HIST_FILTER__THREAD
);
843 void hists__filter_by_thread(struct hists
*hists
)
847 hists
->nr_entries
= hists
->stats
.total_period
= 0;
848 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
849 hists__reset_col_len(hists
);
851 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
852 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
854 if (hists__filter_entry_by_thread(hists
, h
))
857 hists__remove_entry_filter(hists
, h
, HIST_FILTER__THREAD
);
861 static bool hists__filter_entry_by_symbol(struct hists
*hists
,
862 struct hist_entry
*he
)
864 if (hists
->symbol_filter_str
!= NULL
&&
865 (!he
->ms
.sym
|| strstr(he
->ms
.sym
->name
,
866 hists
->symbol_filter_str
) == NULL
)) {
867 he
->filtered
|= (1 << HIST_FILTER__SYMBOL
);
874 void hists__filter_by_symbol(struct hists
*hists
)
878 hists
->nr_entries
= hists
->stats
.total_period
= 0;
879 hists
->stats
.nr_events
[PERF_RECORD_SAMPLE
] = 0;
880 hists__reset_col_len(hists
);
882 for (nd
= rb_first(&hists
->entries
); nd
; nd
= rb_next(nd
)) {
883 struct hist_entry
*h
= rb_entry(nd
, struct hist_entry
, rb_node
);
885 if (hists__filter_entry_by_symbol(hists
, h
))
888 hists__remove_entry_filter(hists
, h
, HIST_FILTER__SYMBOL
);
892 int hist_entry__inc_addr_samples(struct hist_entry
*he
, int evidx
, u64 ip
)
894 return symbol__inc_addr_samples(he
->ms
.sym
, he
->ms
.map
, evidx
, ip
);
897 int hist_entry__annotate(struct hist_entry
*he
, size_t privsize
)
899 return symbol__annotate(he
->ms
.sym
, he
->ms
.map
, privsize
);
902 void events_stats__inc(struct events_stats
*stats
, u32 type
)
904 ++stats
->nr_events
[0];
905 ++stats
->nr_events
[type
];
908 void hists__inc_nr_events(struct hists
*hists
, u32 type
)
910 events_stats__inc(&hists
->stats
, type
);
913 static struct hist_entry
*hists__add_dummy_entry(struct hists
*hists
,
914 struct hist_entry
*pair
)
916 struct rb_root
*root
;
918 struct rb_node
*parent
= NULL
;
919 struct hist_entry
*he
;
922 if (sort__need_collapse
)
923 root
= &hists
->entries_collapsed
;
925 root
= hists
->entries_in
;
931 he
= rb_entry(parent
, struct hist_entry
, rb_node_in
);
933 cmp
= hist_entry__collapse(he
, pair
);
944 he
= hist_entry__new(pair
);
946 memset(&he
->stat
, 0, sizeof(he
->stat
));
948 rb_link_node(&he
->rb_node_in
, parent
, p
);
949 rb_insert_color(&he
->rb_node_in
, root
);
950 hists__inc_nr_entries(hists
, he
);
956 static struct hist_entry
*hists__find_entry(struct hists
*hists
,
957 struct hist_entry
*he
)
961 if (sort__need_collapse
)
962 n
= hists
->entries_collapsed
.rb_node
;
964 n
= hists
->entries_in
->rb_node
;
967 struct hist_entry
*iter
= rb_entry(n
, struct hist_entry
, rb_node_in
);
968 int64_t cmp
= hist_entry__collapse(iter
, he
);
982 * Look for pairs to link to the leader buckets (hist_entries):
984 void hists__match(struct hists
*leader
, struct hists
*other
)
986 struct rb_root
*root
;
988 struct hist_entry
*pos
, *pair
;
990 if (sort__need_collapse
)
991 root
= &leader
->entries_collapsed
;
993 root
= leader
->entries_in
;
995 for (nd
= rb_first(root
); nd
; nd
= rb_next(nd
)) {
996 pos
= rb_entry(nd
, struct hist_entry
, rb_node_in
);
997 pair
= hists__find_entry(other
, pos
);
1000 hist_entry__add_pair(pair
, pos
);
1005 * Look for entries in the other hists that are not present in the leader, if
1006 * we find them, just add a dummy entry on the leader hists, with period=0,
1007 * nr_events=0, to serve as the list header.
1009 int hists__link(struct hists
*leader
, struct hists
*other
)
1011 struct rb_root
*root
;
1013 struct hist_entry
*pos
, *pair
;
1015 if (sort__need_collapse
)
1016 root
= &other
->entries_collapsed
;
1018 root
= other
->entries_in
;
1020 for (nd
= rb_first(root
); nd
; nd
= rb_next(nd
)) {
1021 pos
= rb_entry(nd
, struct hist_entry
, rb_node_in
);
1023 if (!hist_entry__has_pairs(pos
)) {
1024 pair
= hists__add_dummy_entry(leader
, pos
);
1027 hist_entry__add_pair(pos
, pair
);