blob: 8170a3d11ffad0612080afa4ead1c54549ae4409 [file] [log] [blame]
Arnaldo Carvalho de Melo78f7def2011-02-04 09:45:46 -02001#include "annotate.h"
Frederic Weisbecker8a0ecfb2010-05-13 19:47:16 +02002#include "util.h"
Frederic Weisbecker598357e2010-05-21 12:48:39 +02003#include "build-id.h"
John Kacur3d1d07e2009-09-28 15:32:55 +02004#include "hist.h"
Arnaldo Carvalho de Melo4e4f06e2009-12-14 13:10:39 -02005#include "session.h"
6#include "sort.h"
Arnaldo Carvalho de Melo9b338272009-12-16 14:31:49 -02007#include <math.h>
John Kacur3d1d07e2009-09-28 15:32:55 +02008
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -02009static bool hists__filter_entry_by_dso(struct hists *hists,
10 struct hist_entry *he);
11static bool hists__filter_entry_by_thread(struct hists *hists,
12 struct hist_entry *he);
Namhyung Kime94d53e2012-03-16 17:50:51 +090013static bool hists__filter_entry_by_symbol(struct hists *hists,
14 struct hist_entry *he);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -020015
Arnaldo Carvalho de Melo7a007ca2010-07-21 09:19:41 -030016enum hist_filter {
17 HIST_FILTER__DSO,
18 HIST_FILTER__THREAD,
19 HIST_FILTER__PARENT,
Namhyung Kime94d53e2012-03-16 17:50:51 +090020 HIST_FILTER__SYMBOL,
Arnaldo Carvalho de Melo7a007ca2010-07-21 09:19:41 -030021};
22
John Kacur3d1d07e2009-09-28 15:32:55 +020023struct callchain_param callchain_param = {
24 .mode = CHAIN_GRAPH_REL,
Sam Liaod797fdc2011-06-07 23:49:46 +080025 .min_percent = 0.5,
26 .order = ORDER_CALLEE
John Kacur3d1d07e2009-09-28 15:32:55 +020027};
28
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030029u16 hists__col_len(struct hists *hists, enum hist_column col)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030030{
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030031 return hists->col_len[col];
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030032}
33
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030034void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030035{
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030036 hists->col_len[col] = len;
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030037}
38
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030039bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030040{
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030041 if (len > hists__col_len(hists, col)) {
42 hists__set_col_len(hists, col, len);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030043 return true;
44 }
45 return false;
46}
47
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090048void hists__reset_col_len(struct hists *hists)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030049{
50 enum hist_column col;
51
52 for (col = 0; col < HISTC_NR_COLS; ++col)
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030053 hists__set_col_len(hists, col, 0);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030054}
55
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010056static void hists__set_unres_dso_col_len(struct hists *hists, int dso)
57{
58 const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
59
60 if (hists__col_len(hists, dso) < unresolved_col_width &&
61 !symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
62 !symbol_conf.dso_list)
63 hists__set_col_len(hists, dso, unresolved_col_width);
64}
65
Namhyung Kim7ccf4f92012-08-20 13:52:05 +090066void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030067{
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010068 const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030069 u16 len;
70
71 if (h->ms.sym)
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010072 hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen + 4);
73 else
74 hists__set_unres_dso_col_len(hists, HISTC_DSO);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030075
76 len = thread__comm_len(h->thread);
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030077 if (hists__new_col_len(hists, HISTC_COMM, len))
78 hists__set_col_len(hists, HISTC_THREAD, len + 6);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030079
80 if (h->ms.map) {
81 len = dso__name_len(h->ms.map->dso);
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030082 hists__new_col_len(hists, HISTC_DSO, len);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030083 }
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010084
Namhyung Kimcb993742012-12-27 18:11:42 +090085 if (h->parent)
86 hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen);
87
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010088 if (h->branch_info) {
89 int symlen;
90 /*
91 * +4 accounts for '[x] ' priv level info
92 * +2 account of 0x prefix on raw addresses
93 */
94 if (h->branch_info->from.sym) {
95 symlen = (int)h->branch_info->from.sym->namelen + 4;
96 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
97
98 symlen = dso__name_len(h->branch_info->from.map->dso);
99 hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
100 } else {
101 symlen = unresolved_col_width + 4 + 2;
102 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
103 hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM);
104 }
105
106 if (h->branch_info->to.sym) {
107 symlen = (int)h->branch_info->to.sym->namelen + 4;
108 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
109
110 symlen = dso__name_len(h->branch_info->to.map->dso);
111 hists__new_col_len(hists, HISTC_DSO_TO, symlen);
112 } else {
113 symlen = unresolved_col_width + 4 + 2;
114 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
115 hists__set_unres_dso_col_len(hists, HISTC_DSO_TO);
116 }
117 }
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300118}
119
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900120void hists__output_recalc_col_len(struct hists *hists, int max_rows)
121{
122 struct rb_node *next = rb_first(&hists->entries);
123 struct hist_entry *n;
124 int row = 0;
125
126 hists__reset_col_len(hists);
127
128 while (next && row++ < max_rows) {
129 n = rb_entry(next, struct hist_entry, rb_node);
130 if (!n->filtered)
131 hists__calc_col_len(hists, n);
132 next = rb_next(&n->rb_node);
133 }
134}
135
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200136static void hist_entry__add_cpumode_period(struct hist_entry *he,
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300137 unsigned int cpumode, u64 period)
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800138{
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300139 switch (cpumode) {
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800140 case PERF_RECORD_MISC_KERNEL:
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900141 he->stat.period_sys += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800142 break;
143 case PERF_RECORD_MISC_USER:
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900144 he->stat.period_us += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800145 break;
146 case PERF_RECORD_MISC_GUEST_KERNEL:
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900147 he->stat.period_guest_sys += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800148 break;
149 case PERF_RECORD_MISC_GUEST_USER:
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900150 he->stat.period_guest_us += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800151 break;
152 default:
153 break;
154 }
155}
156
Namhyung Kim139c0812012-10-04 21:49:43 +0900157static void he_stat__add_period(struct he_stat *he_stat, u64 period)
158{
159 he_stat->period += period;
160 he_stat->nr_events += 1;
161}
162
163static void he_stat__add_stat(struct he_stat *dest, struct he_stat *src)
164{
165 dest->period += src->period;
166 dest->period_sys += src->period_sys;
167 dest->period_us += src->period_us;
168 dest->period_guest_sys += src->period_guest_sys;
169 dest->period_guest_us += src->period_guest_us;
170 dest->nr_events += src->nr_events;
171}
172
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300173static void hist_entry__decay(struct hist_entry *he)
174{
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900175 he->stat.period = (he->stat.period * 7) / 8;
176 he->stat.nr_events = (he->stat.nr_events * 7) / 8;
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300177}
178
179static bool hists__decay_entry(struct hists *hists, struct hist_entry *he)
180{
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900181 u64 prev_period = he->stat.period;
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200182
183 if (prev_period == 0)
Arnaldo Carvalho de Melodf71d952011-10-13 08:01:33 -0300184 return true;
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200185
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300186 hist_entry__decay(he);
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200187
188 if (!he->filtered)
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900189 hists->stats.total_period -= prev_period - he->stat.period;
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200190
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900191 return he->stat.period == 0;
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300192}
193
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200194static void __hists__decay_entries(struct hists *hists, bool zap_user,
195 bool zap_kernel, bool threaded)
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300196{
197 struct rb_node *next = rb_first(&hists->entries);
198 struct hist_entry *n;
199
200 while (next) {
201 n = rb_entry(next, struct hist_entry, rb_node);
202 next = rb_next(&n->rb_node);
Arnaldo Carvalho de Melodf71d952011-10-13 08:01:33 -0300203 /*
204 * We may be annotating this, for instance, so keep it here in
205 * case some it gets new samples, we'll eventually free it when
206 * the user stops browsing and it agains gets fully decayed.
207 */
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200208 if (((zap_user && n->level == '.') ||
209 (zap_kernel && n->level != '.') ||
210 hists__decay_entry(hists, n)) &&
211 !n->used) {
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300212 rb_erase(&n->rb_node, &hists->entries);
213
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300214 if (sort__need_collapse || threaded)
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300215 rb_erase(&n->rb_node_in, &hists->entries_collapsed);
216
217 hist_entry__free(n);
218 --hists->nr_entries;
219 }
220 }
221}
222
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200223void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300224{
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200225 return __hists__decay_entries(hists, zap_user, zap_kernel, false);
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300226}
227
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200228void hists__decay_entries_threaded(struct hists *hists,
229 bool zap_user, bool zap_kernel)
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300230{
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200231 return __hists__decay_entries(hists, zap_user, zap_kernel, true);
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300232}
233
John Kacur3d1d07e2009-09-28 15:32:55 +0200234/*
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300235 * histogram, sorted on item, collects periods
John Kacur3d1d07e2009-09-28 15:32:55 +0200236 */
237
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300238static struct hist_entry *hist_entry__new(struct hist_entry *template)
239{
Frederic Weisbeckerd2009c52010-08-22 20:05:22 +0200240 size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0;
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200241 struct hist_entry *he = malloc(sizeof(*he) + callchain_size);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300242
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200243 if (he != NULL) {
244 *he = *template;
Namhyung Kimc4b35352012-10-04 21:49:42 +0900245
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200246 if (he->ms.map)
247 he->ms.map->referenced = true;
Stephane Eranian3cf0cb12013-01-14 15:02:45 +0100248
249 if (he->branch_info) {
250 if (he->branch_info->from.map)
251 he->branch_info->from.map->referenced = true;
252 if (he->branch_info->to.map)
253 he->branch_info->to.map->referenced = true;
254 }
255
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300256 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200257 callchain_init(he->callchain);
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200258
259 INIT_LIST_HEAD(&he->pairs.node);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300260 }
261
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200262 return he;
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300263}
264
Namhyung Kim66f97ed2012-12-10 17:29:56 +0900265void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h)
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300266{
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300267 if (!h->filtered) {
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300268 hists__calc_col_len(hists, h);
269 ++hists->nr_entries;
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900270 hists->stats.total_period += h->stat.period;
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300271 }
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300272}
273
Arnaldo Carvalho de Melo7a007ca2010-07-21 09:19:41 -0300274static u8 symbol__parent_filter(const struct symbol *parent)
275{
276 if (symbol_conf.exclude_other && parent == NULL)
277 return 1 << HIST_FILTER__PARENT;
278 return 0;
279}
280
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100281static struct hist_entry *add_hist_entry(struct hists *hists,
282 struct hist_entry *entry,
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300283 struct addr_location *al,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100284 u64 period)
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300285{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300286 struct rb_node **p;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300287 struct rb_node *parent = NULL;
288 struct hist_entry *he;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300289 int cmp;
290
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300291 pthread_mutex_lock(&hists->lock);
292
293 p = &hists->entries_in->rb_node;
294
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300295 while (*p != NULL) {
296 parent = *p;
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300297 he = rb_entry(parent, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300298
Namhyung Kim9afcf932012-12-10 17:29:54 +0900299 /*
300 * Make sure that it receives arguments in a same order as
301 * hist_entry__collapse() so that we can use an appropriate
302 * function when searching an entry regardless which sort
303 * keys were used.
304 */
305 cmp = hist_entry__cmp(he, entry);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300306
307 if (!cmp) {
Namhyung Kim139c0812012-10-04 21:49:43 +0900308 he_stat__add_period(&he->stat, period);
David Miller63fa4712012-03-27 03:14:18 -0400309
310 /* If the map of an existing hist_entry has
311 * become out-of-date due to an exec() or
312 * similar, update it. Otherwise we will
313 * mis-adjust symbol addresses when computing
314 * the history counter to increment.
315 */
316 if (he->ms.map != entry->ms.map) {
317 he->ms.map = entry->ms.map;
318 if (he->ms.map)
319 he->ms.map->referenced = true;
320 }
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300321 goto out;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300322 }
323
324 if (cmp < 0)
325 p = &(*p)->rb_left;
326 else
327 p = &(*p)->rb_right;
328 }
329
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100330 he = hist_entry__new(entry);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300331 if (!he)
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300332 goto out_unlock;
333
334 rb_link_node(&he->rb_node_in, parent, p);
335 rb_insert_color(&he->rb_node_in, hists->entries_in);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300336out:
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300337 hist_entry__add_cpumode_period(he, al->cpumode, period);
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300338out_unlock:
339 pthread_mutex_unlock(&hists->lock);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300340 return he;
341}
342
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100343struct hist_entry *__hists__add_branch_entry(struct hists *self,
344 struct addr_location *al,
345 struct symbol *sym_parent,
346 struct branch_info *bi,
347 u64 period)
348{
349 struct hist_entry entry = {
350 .thread = al->thread,
351 .ms = {
352 .map = bi->to.map,
353 .sym = bi->to.sym,
354 },
355 .cpu = al->cpu,
356 .ip = bi->to.addr,
357 .level = al->level,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900358 .stat = {
359 .period = period,
Namhyung Kimc4b35352012-10-04 21:49:42 +0900360 .nr_events = 1,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900361 },
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100362 .parent = sym_parent,
363 .filtered = symbol__parent_filter(sym_parent),
364 .branch_info = bi,
Jiri Olsaae359f12012-10-04 21:49:35 +0900365 .hists = self,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100366 };
367
368 return add_hist_entry(self, &entry, al, period);
369}
370
371struct hist_entry *__hists__add_entry(struct hists *self,
372 struct addr_location *al,
373 struct symbol *sym_parent, u64 period)
374{
375 struct hist_entry entry = {
376 .thread = al->thread,
377 .ms = {
378 .map = al->map,
379 .sym = al->sym,
380 },
381 .cpu = al->cpu,
382 .ip = al->addr,
383 .level = al->level,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900384 .stat = {
385 .period = period,
Namhyung Kimc4b35352012-10-04 21:49:42 +0900386 .nr_events = 1,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900387 },
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100388 .parent = sym_parent,
389 .filtered = symbol__parent_filter(sym_parent),
Jiri Olsaae359f12012-10-04 21:49:35 +0900390 .hists = self,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100391 };
392
393 return add_hist_entry(self, &entry, al, period);
394}
395
John Kacur3d1d07e2009-09-28 15:32:55 +0200396int64_t
397hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
398{
399 struct sort_entry *se;
400 int64_t cmp = 0;
401
402 list_for_each_entry(se, &hist_entry__sort_list, list) {
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200403 cmp = se->se_cmp(left, right);
John Kacur3d1d07e2009-09-28 15:32:55 +0200404 if (cmp)
405 break;
406 }
407
408 return cmp;
409}
410
411int64_t
412hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
413{
414 struct sort_entry *se;
415 int64_t cmp = 0;
416
417 list_for_each_entry(se, &hist_entry__sort_list, list) {
418 int64_t (*f)(struct hist_entry *, struct hist_entry *);
419
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200420 f = se->se_collapse ?: se->se_cmp;
John Kacur3d1d07e2009-09-28 15:32:55 +0200421
422 cmp = f(left, right);
423 if (cmp)
424 break;
425 }
426
427 return cmp;
428}
429
430void hist_entry__free(struct hist_entry *he)
431{
Namhyung Kim580e3382012-11-07 16:27:14 +0900432 free(he->branch_info);
John Kacur3d1d07e2009-09-28 15:32:55 +0200433 free(he);
434}
435
436/*
437 * collapse the histogram
438 */
439
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300440static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100441 struct rb_root *root,
442 struct hist_entry *he)
John Kacur3d1d07e2009-09-28 15:32:55 +0200443{
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200444 struct rb_node **p = &root->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200445 struct rb_node *parent = NULL;
446 struct hist_entry *iter;
447 int64_t cmp;
448
449 while (*p != NULL) {
450 parent = *p;
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300451 iter = rb_entry(parent, struct hist_entry, rb_node_in);
John Kacur3d1d07e2009-09-28 15:32:55 +0200452
453 cmp = hist_entry__collapse(iter, he);
454
455 if (!cmp) {
Namhyung Kim139c0812012-10-04 21:49:43 +0900456 he_stat__add_stat(&iter->stat, &he->stat);
Namhyung Kim9ec60972012-09-26 16:47:28 +0900457
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100458 if (symbol_conf.use_callchain) {
Namhyung Kim47260642012-05-31 14:43:26 +0900459 callchain_cursor_reset(&callchain_cursor);
460 callchain_merge(&callchain_cursor,
461 iter->callchain,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100462 he->callchain);
463 }
John Kacur3d1d07e2009-09-28 15:32:55 +0200464 hist_entry__free(he);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300465 return false;
John Kacur3d1d07e2009-09-28 15:32:55 +0200466 }
467
468 if (cmp < 0)
469 p = &(*p)->rb_left;
470 else
471 p = &(*p)->rb_right;
472 }
473
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300474 rb_link_node(&he->rb_node_in, parent, p);
475 rb_insert_color(&he->rb_node_in, root);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300476 return true;
John Kacur3d1d07e2009-09-28 15:32:55 +0200477}
478
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300479static struct rb_root *hists__get_rotate_entries_in(struct hists *hists)
480{
481 struct rb_root *root;
482
483 pthread_mutex_lock(&hists->lock);
484
485 root = hists->entries_in;
486 if (++hists->entries_in > &hists->entries_in_array[1])
487 hists->entries_in = &hists->entries_in_array[0];
488
489 pthread_mutex_unlock(&hists->lock);
490
491 return root;
492}
493
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200494static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
495{
496 hists__filter_entry_by_dso(hists, he);
497 hists__filter_entry_by_thread(hists, he);
Namhyung Kime94d53e2012-03-16 17:50:51 +0900498 hists__filter_entry_by_symbol(hists, he);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200499}
500
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300501static void __hists__collapse_resort(struct hists *hists, bool threaded)
502{
503 struct rb_root *root;
504 struct rb_node *next;
505 struct hist_entry *n;
506
507 if (!sort__need_collapse && !threaded)
508 return;
509
510 root = hists__get_rotate_entries_in(hists);
511 next = rb_first(root);
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300512
513 while (next) {
514 n = rb_entry(next, struct hist_entry, rb_node_in);
515 next = rb_next(&n->rb_node_in);
516
517 rb_erase(&n->rb_node_in, root);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200518 if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) {
519 /*
520 * If it wasn't combined with one of the entries already
521 * collapsed, we need to apply the filters that may have
522 * been set by, say, the hist_browser.
523 */
524 hists__apply_filters(hists, n);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200525 }
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300526 }
527}
528
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300529void hists__collapse_resort(struct hists *hists)
John Kacur3d1d07e2009-09-28 15:32:55 +0200530{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300531 return __hists__collapse_resort(hists, false);
532}
John Kacur3d1d07e2009-09-28 15:32:55 +0200533
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300534void hists__collapse_resort_threaded(struct hists *hists)
535{
536 return __hists__collapse_resort(hists, true);
John Kacur3d1d07e2009-09-28 15:32:55 +0200537}
538
539/*
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300540 * reverse the map, sort on period.
John Kacur3d1d07e2009-09-28 15:32:55 +0200541 */
542
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300543static void __hists__insert_output_entry(struct rb_root *entries,
544 struct hist_entry *he,
545 u64 min_callchain_hits)
John Kacur3d1d07e2009-09-28 15:32:55 +0200546{
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300547 struct rb_node **p = &entries->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200548 struct rb_node *parent = NULL;
549 struct hist_entry *iter;
550
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200551 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Melob9fb9302010-04-02 09:50:42 -0300552 callchain_param.sort(&he->sorted_chain, he->callchain,
John Kacur3d1d07e2009-09-28 15:32:55 +0200553 min_callchain_hits, &callchain_param);
554
555 while (*p != NULL) {
556 parent = *p;
557 iter = rb_entry(parent, struct hist_entry, rb_node);
558
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900559 if (he->stat.period > iter->stat.period)
John Kacur3d1d07e2009-09-28 15:32:55 +0200560 p = &(*p)->rb_left;
561 else
562 p = &(*p)->rb_right;
563 }
564
565 rb_link_node(&he->rb_node, parent, p);
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300566 rb_insert_color(&he->rb_node, entries);
John Kacur3d1d07e2009-09-28 15:32:55 +0200567}
568
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300569static void __hists__output_resort(struct hists *hists, bool threaded)
John Kacur3d1d07e2009-09-28 15:32:55 +0200570{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300571 struct rb_root *root;
John Kacur3d1d07e2009-09-28 15:32:55 +0200572 struct rb_node *next;
573 struct hist_entry *n;
John Kacur3d1d07e2009-09-28 15:32:55 +0200574 u64 min_callchain_hits;
575
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300576 min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
John Kacur3d1d07e2009-09-28 15:32:55 +0200577
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300578 if (sort__need_collapse || threaded)
579 root = &hists->entries_collapsed;
580 else
581 root = hists->entries_in;
582
583 next = rb_first(root);
584 hists->entries = RB_ROOT;
John Kacur3d1d07e2009-09-28 15:32:55 +0200585
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300586 hists->nr_entries = 0;
Arnaldo Carvalho de Melo79286312011-10-27 09:19:48 -0200587 hists->stats.total_period = 0;
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300588 hists__reset_col_len(hists);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300589
John Kacur3d1d07e2009-09-28 15:32:55 +0200590 while (next) {
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300591 n = rb_entry(next, struct hist_entry, rb_node_in);
592 next = rb_next(&n->rb_node_in);
John Kacur3d1d07e2009-09-28 15:32:55 +0200593
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300594 __hists__insert_output_entry(&hists->entries, n, min_callchain_hits);
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300595 hists__inc_nr_entries(hists, n);
John Kacur3d1d07e2009-09-28 15:32:55 +0200596 }
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300597}
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200598
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300599void hists__output_resort(struct hists *hists)
600{
601 return __hists__output_resort(hists, false);
602}
603
604void hists__output_resort_threaded(struct hists *hists)
605{
606 return __hists__output_resort(hists, true);
John Kacur3d1d07e2009-09-28 15:32:55 +0200607}
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200608
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300609static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h,
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300610 enum hist_filter filter)
611{
612 h->filtered &= ~(1 << filter);
613 if (h->filtered)
614 return;
615
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300616 ++hists->nr_entries;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -0300617 if (h->ms.unfolded)
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300618 hists->nr_entries += h->nr_rows;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -0300619 h->row_offset = 0;
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900620 hists->stats.total_period += h->stat.period;
621 hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->stat.nr_events;
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300622
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300623 hists__calc_col_len(hists, h);
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300624}
625
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200626
627static bool hists__filter_entry_by_dso(struct hists *hists,
628 struct hist_entry *he)
629{
630 if (hists->dso_filter != NULL &&
631 (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
632 he->filtered |= (1 << HIST_FILTER__DSO);
633 return true;
634 }
635
636 return false;
637}
638
Arnaldo Carvalho de Melod7b76f02011-10-18 19:07:34 -0200639void hists__filter_by_dso(struct hists *hists)
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300640{
641 struct rb_node *nd;
642
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300643 hists->nr_entries = hists->stats.total_period = 0;
644 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
645 hists__reset_col_len(hists);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300646
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300647 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300648 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
649
650 if (symbol_conf.exclude_other && !h->parent)
651 continue;
652
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200653 if (hists__filter_entry_by_dso(hists, h))
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300654 continue;
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300655
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300656 hists__remove_entry_filter(hists, h, HIST_FILTER__DSO);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300657 }
658}
659
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200660static bool hists__filter_entry_by_thread(struct hists *hists,
661 struct hist_entry *he)
662{
663 if (hists->thread_filter != NULL &&
664 he->thread != hists->thread_filter) {
665 he->filtered |= (1 << HIST_FILTER__THREAD);
666 return true;
667 }
668
669 return false;
670}
671
Arnaldo Carvalho de Melod7b76f02011-10-18 19:07:34 -0200672void hists__filter_by_thread(struct hists *hists)
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300673{
674 struct rb_node *nd;
675
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300676 hists->nr_entries = hists->stats.total_period = 0;
677 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
678 hists__reset_col_len(hists);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300679
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300680 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300681 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
682
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200683 if (hists__filter_entry_by_thread(hists, h))
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300684 continue;
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300685
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300686 hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300687 }
688}
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300689
Namhyung Kime94d53e2012-03-16 17:50:51 +0900690static bool hists__filter_entry_by_symbol(struct hists *hists,
691 struct hist_entry *he)
692{
693 if (hists->symbol_filter_str != NULL &&
694 (!he->ms.sym || strstr(he->ms.sym->name,
695 hists->symbol_filter_str) == NULL)) {
696 he->filtered |= (1 << HIST_FILTER__SYMBOL);
697 return true;
698 }
699
700 return false;
701}
702
703void hists__filter_by_symbol(struct hists *hists)
704{
705 struct rb_node *nd;
706
707 hists->nr_entries = hists->stats.total_period = 0;
708 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
709 hists__reset_col_len(hists);
710
711 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
712 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
713
714 if (hists__filter_entry_by_symbol(hists, h))
715 continue;
716
717 hists__remove_entry_filter(hists, h, HIST_FILTER__SYMBOL);
718 }
719}
720
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200721int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300722{
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200723 return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300724}
725
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200726int hist_entry__annotate(struct hist_entry *he, size_t privsize)
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300727{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200728 return symbol__annotate(he->ms.sym, he->ms.map, privsize);
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300729}
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300730
Arnaldo Carvalho de Melo28a6b6a2012-12-18 16:24:46 -0300731void events_stats__inc(struct events_stats *stats, u32 type)
732{
733 ++stats->nr_events[0];
734 ++stats->nr_events[type];
735}
736
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300737void hists__inc_nr_events(struct hists *hists, u32 type)
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300738{
Arnaldo Carvalho de Melo28a6b6a2012-12-18 16:24:46 -0300739 events_stats__inc(&hists->stats, type);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300740}
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300741
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300742static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
743 struct hist_entry *pair)
744{
Namhyung Kimce74f602012-12-10 17:29:55 +0900745 struct rb_root *root;
746 struct rb_node **p;
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300747 struct rb_node *parent = NULL;
748 struct hist_entry *he;
749 int cmp;
750
Namhyung Kimce74f602012-12-10 17:29:55 +0900751 if (sort__need_collapse)
752 root = &hists->entries_collapsed;
753 else
754 root = hists->entries_in;
755
756 p = &root->rb_node;
757
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300758 while (*p != NULL) {
759 parent = *p;
Namhyung Kimce74f602012-12-10 17:29:55 +0900760 he = rb_entry(parent, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300761
Namhyung Kimce74f602012-12-10 17:29:55 +0900762 cmp = hist_entry__collapse(he, pair);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300763
764 if (!cmp)
765 goto out;
766
767 if (cmp < 0)
768 p = &(*p)->rb_left;
769 else
770 p = &(*p)->rb_right;
771 }
772
773 he = hist_entry__new(pair);
774 if (he) {
Arnaldo Carvalho de Melo30193d72012-11-12 13:20:03 -0300775 memset(&he->stat, 0, sizeof(he->stat));
776 he->hists = hists;
Namhyung Kimce74f602012-12-10 17:29:55 +0900777 rb_link_node(&he->rb_node_in, parent, p);
778 rb_insert_color(&he->rb_node_in, root);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300779 hists__inc_nr_entries(hists, he);
780 }
781out:
782 return he;
783}
784
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300785static struct hist_entry *hists__find_entry(struct hists *hists,
786 struct hist_entry *he)
787{
Namhyung Kimce74f602012-12-10 17:29:55 +0900788 struct rb_node *n;
789
790 if (sort__need_collapse)
791 n = hists->entries_collapsed.rb_node;
792 else
793 n = hists->entries_in->rb_node;
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300794
795 while (n) {
Namhyung Kimce74f602012-12-10 17:29:55 +0900796 struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in);
797 int64_t cmp = hist_entry__collapse(iter, he);
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300798
799 if (cmp < 0)
800 n = n->rb_left;
801 else if (cmp > 0)
802 n = n->rb_right;
803 else
804 return iter;
805 }
806
807 return NULL;
808}
809
810/*
811 * Look for pairs to link to the leader buckets (hist_entries):
812 */
813void hists__match(struct hists *leader, struct hists *other)
814{
Namhyung Kimce74f602012-12-10 17:29:55 +0900815 struct rb_root *root;
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300816 struct rb_node *nd;
817 struct hist_entry *pos, *pair;
818
Namhyung Kimce74f602012-12-10 17:29:55 +0900819 if (sort__need_collapse)
820 root = &leader->entries_collapsed;
821 else
822 root = leader->entries_in;
823
824 for (nd = rb_first(root); nd; nd = rb_next(nd)) {
825 pos = rb_entry(nd, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300826 pair = hists__find_entry(other, pos);
827
828 if (pair)
Namhyung Kim5fa90412012-11-29 15:38:34 +0900829 hist_entry__add_pair(pair, pos);
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300830 }
831}
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300832
833/*
834 * Look for entries in the other hists that are not present in the leader, if
835 * we find them, just add a dummy entry on the leader hists, with period=0,
836 * nr_events=0, to serve as the list header.
837 */
838int hists__link(struct hists *leader, struct hists *other)
839{
Namhyung Kimce74f602012-12-10 17:29:55 +0900840 struct rb_root *root;
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300841 struct rb_node *nd;
842 struct hist_entry *pos, *pair;
843
Namhyung Kimce74f602012-12-10 17:29:55 +0900844 if (sort__need_collapse)
845 root = &other->entries_collapsed;
846 else
847 root = other->entries_in;
848
849 for (nd = rb_first(root); nd; nd = rb_next(nd)) {
850 pos = rb_entry(nd, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300851
852 if (!hist_entry__has_pairs(pos)) {
853 pair = hists__add_dummy_entry(leader, pos);
854 if (pair == NULL)
855 return -1;
Namhyung Kim5fa90412012-11-29 15:38:34 +0900856 hist_entry__add_pair(pos, pair);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300857 }
858 }
859
860 return 0;
861}