5 struct callchain_param callchain_param = {
6 .mode = CHAIN_GRAPH_REL,
11 * histogram, sorted on item, collects counts
14 struct hist_entry *__perf_session__add_hist_entry(struct perf_session *self,
15 struct addr_location *al,
16 struct symbol *sym_parent,
19 struct rb_node **p = &self->hists.rb_node;
20 struct rb_node *parent = NULL;
21 struct hist_entry *he;
22 struct hist_entry entry = {
35 he = rb_entry(parent, struct hist_entry, rb_node);
37 cmp = hist_entry__cmp(&entry, he);
50 he = malloc(sizeof(*he));
54 rb_link_node(&he->rb_node, parent, p);
55 rb_insert_color(&he->rb_node, &self->hists);
61 hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
63 struct sort_entry *se;
66 list_for_each_entry(se, &hist_entry__sort_list, list) {
67 cmp = se->cmp(left, right);
76 hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
78 struct sort_entry *se;
81 list_for_each_entry(se, &hist_entry__sort_list, list) {
82 int64_t (*f)(struct hist_entry *, struct hist_entry *);
84 f = se->collapse ?: se->cmp;
94 void hist_entry__free(struct hist_entry *he)
100 * collapse the histogram
103 static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
105 struct rb_node **p = &root->rb_node;
106 struct rb_node *parent = NULL;
107 struct hist_entry *iter;
112 iter = rb_entry(parent, struct hist_entry, rb_node);
114 cmp = hist_entry__collapse(iter, he);
117 iter->count += he->count;
118 hist_entry__free(he);
128 rb_link_node(&he->rb_node, parent, p);
129 rb_insert_color(&he->rb_node, root);
132 void perf_session__collapse_resort(struct perf_session *self)
135 struct rb_node *next;
136 struct hist_entry *n;
138 if (!sort__need_collapse)
142 next = rb_first(&self->hists);
145 n = rb_entry(next, struct hist_entry, rb_node);
146 next = rb_next(&n->rb_node);
148 rb_erase(&n->rb_node, &self->hists);
149 collapse__insert_entry(&tmp, n);
156 * reverse the map, sort on count.
159 static void perf_session__insert_output_hist_entry(struct perf_session *self,
160 struct rb_root *root,
161 struct hist_entry *he,
162 u64 min_callchain_hits)
164 struct rb_node **p = &root->rb_node;
165 struct rb_node *parent = NULL;
166 struct hist_entry *iter;
168 if (self->use_callchain)
169 callchain_param.sort(&he->sorted_chain, &he->callchain,
170 min_callchain_hits, &callchain_param);
174 iter = rb_entry(parent, struct hist_entry, rb_node);
176 if (he->count > iter->count)
182 rb_link_node(&he->rb_node, parent, p);
183 rb_insert_color(&he->rb_node, root);
186 void perf_session__output_resort(struct perf_session *self, u64 total_samples)
189 struct rb_node *next;
190 struct hist_entry *n;
191 u64 min_callchain_hits;
194 total_samples * (callchain_param.min_percent / 100);
197 next = rb_first(&self->hists);
200 n = rb_entry(next, struct hist_entry, rb_node);
201 next = rb_next(&n->rb_node);
203 rb_erase(&n->rb_node, &self->hists);
204 perf_session__insert_output_hist_entry(self, &tmp, n,