blob: 9485c7024f5bb8ce020bb243b453fa3ed3aadf86 [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;
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300248 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200249 callchain_init(he->callchain);
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200250
251 INIT_LIST_HEAD(&he->pairs.node);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300252 }
253
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200254 return he;
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300255}
256
Namhyung Kim66f97ed2012-12-10 17:29:56 +0900257void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h)
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300258{
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300259 if (!h->filtered) {
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300260 hists__calc_col_len(hists, h);
261 ++hists->nr_entries;
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900262 hists->stats.total_period += h->stat.period;
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300263 }
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300264}
265
Arnaldo Carvalho de Melo7a007ca2010-07-21 09:19:41 -0300266static u8 symbol__parent_filter(const struct symbol *parent)
267{
268 if (symbol_conf.exclude_other && parent == NULL)
269 return 1 << HIST_FILTER__PARENT;
270 return 0;
271}
272
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100273static struct hist_entry *add_hist_entry(struct hists *hists,
274 struct hist_entry *entry,
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300275 struct addr_location *al,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100276 u64 period)
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300277{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300278 struct rb_node **p;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300279 struct rb_node *parent = NULL;
280 struct hist_entry *he;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300281 int cmp;
282
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300283 pthread_mutex_lock(&hists->lock);
284
285 p = &hists->entries_in->rb_node;
286
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300287 while (*p != NULL) {
288 parent = *p;
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300289 he = rb_entry(parent, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300290
Namhyung Kim9afcf932012-12-10 17:29:54 +0900291 /*
292 * Make sure that it receives arguments in a same order as
293 * hist_entry__collapse() so that we can use an appropriate
294 * function when searching an entry regardless which sort
295 * keys were used.
296 */
297 cmp = hist_entry__cmp(he, entry);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300298
299 if (!cmp) {
Namhyung Kim139c0812012-10-04 21:49:43 +0900300 he_stat__add_period(&he->stat, period);
David Miller63fa4712012-03-27 03:14:18 -0400301
302 /* If the map of an existing hist_entry has
303 * become out-of-date due to an exec() or
304 * similar, update it. Otherwise we will
305 * mis-adjust symbol addresses when computing
306 * the history counter to increment.
307 */
308 if (he->ms.map != entry->ms.map) {
309 he->ms.map = entry->ms.map;
310 if (he->ms.map)
311 he->ms.map->referenced = true;
312 }
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300313 goto out;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300314 }
315
316 if (cmp < 0)
317 p = &(*p)->rb_left;
318 else
319 p = &(*p)->rb_right;
320 }
321
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100322 he = hist_entry__new(entry);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300323 if (!he)
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300324 goto out_unlock;
325
326 rb_link_node(&he->rb_node_in, parent, p);
327 rb_insert_color(&he->rb_node_in, hists->entries_in);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300328out:
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300329 hist_entry__add_cpumode_period(he, al->cpumode, period);
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300330out_unlock:
331 pthread_mutex_unlock(&hists->lock);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300332 return he;
333}
334
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100335struct hist_entry *__hists__add_branch_entry(struct hists *self,
336 struct addr_location *al,
337 struct symbol *sym_parent,
338 struct branch_info *bi,
339 u64 period)
340{
341 struct hist_entry entry = {
342 .thread = al->thread,
343 .ms = {
344 .map = bi->to.map,
345 .sym = bi->to.sym,
346 },
347 .cpu = al->cpu,
348 .ip = bi->to.addr,
349 .level = al->level,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900350 .stat = {
351 .period = period,
Namhyung Kimc4b35352012-10-04 21:49:42 +0900352 .nr_events = 1,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900353 },
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100354 .parent = sym_parent,
355 .filtered = symbol__parent_filter(sym_parent),
356 .branch_info = bi,
Jiri Olsaae359f12012-10-04 21:49:35 +0900357 .hists = self,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100358 };
359
360 return add_hist_entry(self, &entry, al, period);
361}
362
363struct hist_entry *__hists__add_entry(struct hists *self,
364 struct addr_location *al,
365 struct symbol *sym_parent, u64 period)
366{
367 struct hist_entry entry = {
368 .thread = al->thread,
369 .ms = {
370 .map = al->map,
371 .sym = al->sym,
372 },
373 .cpu = al->cpu,
374 .ip = al->addr,
375 .level = al->level,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900376 .stat = {
377 .period = period,
Namhyung Kimc4b35352012-10-04 21:49:42 +0900378 .nr_events = 1,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900379 },
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100380 .parent = sym_parent,
381 .filtered = symbol__parent_filter(sym_parent),
Jiri Olsaae359f12012-10-04 21:49:35 +0900382 .hists = self,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100383 };
384
385 return add_hist_entry(self, &entry, al, period);
386}
387
John Kacur3d1d07e2009-09-28 15:32:55 +0200388int64_t
389hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
390{
391 struct sort_entry *se;
392 int64_t cmp = 0;
393
394 list_for_each_entry(se, &hist_entry__sort_list, list) {
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200395 cmp = se->se_cmp(left, right);
John Kacur3d1d07e2009-09-28 15:32:55 +0200396 if (cmp)
397 break;
398 }
399
400 return cmp;
401}
402
403int64_t
404hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
405{
406 struct sort_entry *se;
407 int64_t cmp = 0;
408
409 list_for_each_entry(se, &hist_entry__sort_list, list) {
410 int64_t (*f)(struct hist_entry *, struct hist_entry *);
411
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200412 f = se->se_collapse ?: se->se_cmp;
John Kacur3d1d07e2009-09-28 15:32:55 +0200413
414 cmp = f(left, right);
415 if (cmp)
416 break;
417 }
418
419 return cmp;
420}
421
422void hist_entry__free(struct hist_entry *he)
423{
Namhyung Kim580e3382012-11-07 16:27:14 +0900424 free(he->branch_info);
John Kacur3d1d07e2009-09-28 15:32:55 +0200425 free(he);
426}
427
428/*
429 * collapse the histogram
430 */
431
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300432static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100433 struct rb_root *root,
434 struct hist_entry *he)
John Kacur3d1d07e2009-09-28 15:32:55 +0200435{
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200436 struct rb_node **p = &root->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200437 struct rb_node *parent = NULL;
438 struct hist_entry *iter;
439 int64_t cmp;
440
441 while (*p != NULL) {
442 parent = *p;
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300443 iter = rb_entry(parent, struct hist_entry, rb_node_in);
John Kacur3d1d07e2009-09-28 15:32:55 +0200444
445 cmp = hist_entry__collapse(iter, he);
446
447 if (!cmp) {
Namhyung Kim139c0812012-10-04 21:49:43 +0900448 he_stat__add_stat(&iter->stat, &he->stat);
Namhyung Kim9ec60972012-09-26 16:47:28 +0900449
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100450 if (symbol_conf.use_callchain) {
Namhyung Kim47260642012-05-31 14:43:26 +0900451 callchain_cursor_reset(&callchain_cursor);
452 callchain_merge(&callchain_cursor,
453 iter->callchain,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100454 he->callchain);
455 }
John Kacur3d1d07e2009-09-28 15:32:55 +0200456 hist_entry__free(he);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300457 return false;
John Kacur3d1d07e2009-09-28 15:32:55 +0200458 }
459
460 if (cmp < 0)
461 p = &(*p)->rb_left;
462 else
463 p = &(*p)->rb_right;
464 }
465
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300466 rb_link_node(&he->rb_node_in, parent, p);
467 rb_insert_color(&he->rb_node_in, root);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300468 return true;
John Kacur3d1d07e2009-09-28 15:32:55 +0200469}
470
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300471static struct rb_root *hists__get_rotate_entries_in(struct hists *hists)
472{
473 struct rb_root *root;
474
475 pthread_mutex_lock(&hists->lock);
476
477 root = hists->entries_in;
478 if (++hists->entries_in > &hists->entries_in_array[1])
479 hists->entries_in = &hists->entries_in_array[0];
480
481 pthread_mutex_unlock(&hists->lock);
482
483 return root;
484}
485
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200486static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
487{
488 hists__filter_entry_by_dso(hists, he);
489 hists__filter_entry_by_thread(hists, he);
Namhyung Kime94d53e2012-03-16 17:50:51 +0900490 hists__filter_entry_by_symbol(hists, he);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200491}
492
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300493static void __hists__collapse_resort(struct hists *hists, bool threaded)
494{
495 struct rb_root *root;
496 struct rb_node *next;
497 struct hist_entry *n;
498
499 if (!sort__need_collapse && !threaded)
500 return;
501
502 root = hists__get_rotate_entries_in(hists);
503 next = rb_first(root);
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300504
505 while (next) {
506 n = rb_entry(next, struct hist_entry, rb_node_in);
507 next = rb_next(&n->rb_node_in);
508
509 rb_erase(&n->rb_node_in, root);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200510 if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) {
511 /*
512 * If it wasn't combined with one of the entries already
513 * collapsed, we need to apply the filters that may have
514 * been set by, say, the hist_browser.
515 */
516 hists__apply_filters(hists, n);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200517 }
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300518 }
519}
520
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300521void hists__collapse_resort(struct hists *hists)
John Kacur3d1d07e2009-09-28 15:32:55 +0200522{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300523 return __hists__collapse_resort(hists, false);
524}
John Kacur3d1d07e2009-09-28 15:32:55 +0200525
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300526void hists__collapse_resort_threaded(struct hists *hists)
527{
528 return __hists__collapse_resort(hists, true);
John Kacur3d1d07e2009-09-28 15:32:55 +0200529}
530
531/*
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300532 * reverse the map, sort on period.
John Kacur3d1d07e2009-09-28 15:32:55 +0200533 */
534
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300535static void __hists__insert_output_entry(struct rb_root *entries,
536 struct hist_entry *he,
537 u64 min_callchain_hits)
John Kacur3d1d07e2009-09-28 15:32:55 +0200538{
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300539 struct rb_node **p = &entries->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200540 struct rb_node *parent = NULL;
541 struct hist_entry *iter;
542
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200543 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Melob9fb9302010-04-02 09:50:42 -0300544 callchain_param.sort(&he->sorted_chain, he->callchain,
John Kacur3d1d07e2009-09-28 15:32:55 +0200545 min_callchain_hits, &callchain_param);
546
547 while (*p != NULL) {
548 parent = *p;
549 iter = rb_entry(parent, struct hist_entry, rb_node);
550
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900551 if (he->stat.period > iter->stat.period)
John Kacur3d1d07e2009-09-28 15:32:55 +0200552 p = &(*p)->rb_left;
553 else
554 p = &(*p)->rb_right;
555 }
556
557 rb_link_node(&he->rb_node, parent, p);
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300558 rb_insert_color(&he->rb_node, entries);
John Kacur3d1d07e2009-09-28 15:32:55 +0200559}
560
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300561static void __hists__output_resort(struct hists *hists, bool threaded)
John Kacur3d1d07e2009-09-28 15:32:55 +0200562{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300563 struct rb_root *root;
John Kacur3d1d07e2009-09-28 15:32:55 +0200564 struct rb_node *next;
565 struct hist_entry *n;
John Kacur3d1d07e2009-09-28 15:32:55 +0200566 u64 min_callchain_hits;
567
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300568 min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
John Kacur3d1d07e2009-09-28 15:32:55 +0200569
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300570 if (sort__need_collapse || threaded)
571 root = &hists->entries_collapsed;
572 else
573 root = hists->entries_in;
574
575 next = rb_first(root);
576 hists->entries = RB_ROOT;
John Kacur3d1d07e2009-09-28 15:32:55 +0200577
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300578 hists->nr_entries = 0;
Arnaldo Carvalho de Melo79286312011-10-27 09:19:48 -0200579 hists->stats.total_period = 0;
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300580 hists__reset_col_len(hists);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300581
John Kacur3d1d07e2009-09-28 15:32:55 +0200582 while (next) {
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300583 n = rb_entry(next, struct hist_entry, rb_node_in);
584 next = rb_next(&n->rb_node_in);
John Kacur3d1d07e2009-09-28 15:32:55 +0200585
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300586 __hists__insert_output_entry(&hists->entries, n, min_callchain_hits);
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300587 hists__inc_nr_entries(hists, n);
John Kacur3d1d07e2009-09-28 15:32:55 +0200588 }
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300589}
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200590
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300591void hists__output_resort(struct hists *hists)
592{
593 return __hists__output_resort(hists, false);
594}
595
596void hists__output_resort_threaded(struct hists *hists)
597{
598 return __hists__output_resort(hists, true);
John Kacur3d1d07e2009-09-28 15:32:55 +0200599}
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200600
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300601static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h,
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300602 enum hist_filter filter)
603{
604 h->filtered &= ~(1 << filter);
605 if (h->filtered)
606 return;
607
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300608 ++hists->nr_entries;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -0300609 if (h->ms.unfolded)
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300610 hists->nr_entries += h->nr_rows;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -0300611 h->row_offset = 0;
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900612 hists->stats.total_period += h->stat.period;
613 hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->stat.nr_events;
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300614
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300615 hists__calc_col_len(hists, h);
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300616}
617
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200618
619static bool hists__filter_entry_by_dso(struct hists *hists,
620 struct hist_entry *he)
621{
622 if (hists->dso_filter != NULL &&
623 (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
624 he->filtered |= (1 << HIST_FILTER__DSO);
625 return true;
626 }
627
628 return false;
629}
630
Arnaldo Carvalho de Melod7b76f02011-10-18 19:07:34 -0200631void hists__filter_by_dso(struct hists *hists)
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300632{
633 struct rb_node *nd;
634
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300635 hists->nr_entries = hists->stats.total_period = 0;
636 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
637 hists__reset_col_len(hists);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300638
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300639 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300640 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
641
642 if (symbol_conf.exclude_other && !h->parent)
643 continue;
644
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200645 if (hists__filter_entry_by_dso(hists, h))
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300646 continue;
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300647
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300648 hists__remove_entry_filter(hists, h, HIST_FILTER__DSO);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300649 }
650}
651
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200652static bool hists__filter_entry_by_thread(struct hists *hists,
653 struct hist_entry *he)
654{
655 if (hists->thread_filter != NULL &&
656 he->thread != hists->thread_filter) {
657 he->filtered |= (1 << HIST_FILTER__THREAD);
658 return true;
659 }
660
661 return false;
662}
663
Arnaldo Carvalho de Melod7b76f02011-10-18 19:07:34 -0200664void hists__filter_by_thread(struct hists *hists)
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300665{
666 struct rb_node *nd;
667
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300668 hists->nr_entries = hists->stats.total_period = 0;
669 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
670 hists__reset_col_len(hists);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300671
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300672 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300673 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
674
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200675 if (hists__filter_entry_by_thread(hists, h))
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300676 continue;
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300677
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300678 hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300679 }
680}
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300681
Namhyung Kime94d53e2012-03-16 17:50:51 +0900682static bool hists__filter_entry_by_symbol(struct hists *hists,
683 struct hist_entry *he)
684{
685 if (hists->symbol_filter_str != NULL &&
686 (!he->ms.sym || strstr(he->ms.sym->name,
687 hists->symbol_filter_str) == NULL)) {
688 he->filtered |= (1 << HIST_FILTER__SYMBOL);
689 return true;
690 }
691
692 return false;
693}
694
695void hists__filter_by_symbol(struct hists *hists)
696{
697 struct rb_node *nd;
698
699 hists->nr_entries = hists->stats.total_period = 0;
700 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
701 hists__reset_col_len(hists);
702
703 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
704 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
705
706 if (hists__filter_entry_by_symbol(hists, h))
707 continue;
708
709 hists__remove_entry_filter(hists, h, HIST_FILTER__SYMBOL);
710 }
711}
712
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200713int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300714{
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200715 return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300716}
717
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200718int hist_entry__annotate(struct hist_entry *he, size_t privsize)
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300719{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200720 return symbol__annotate(he->ms.sym, he->ms.map, privsize);
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300721}
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300722
Arnaldo Carvalho de Melo28a6b6a2012-12-18 16:24:46 -0300723void events_stats__inc(struct events_stats *stats, u32 type)
724{
725 ++stats->nr_events[0];
726 ++stats->nr_events[type];
727}
728
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300729void hists__inc_nr_events(struct hists *hists, u32 type)
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300730{
Arnaldo Carvalho de Melo28a6b6a2012-12-18 16:24:46 -0300731 events_stats__inc(&hists->stats, type);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300732}
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300733
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300734static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
735 struct hist_entry *pair)
736{
Namhyung Kimce74f602012-12-10 17:29:55 +0900737 struct rb_root *root;
738 struct rb_node **p;
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300739 struct rb_node *parent = NULL;
740 struct hist_entry *he;
741 int cmp;
742
Namhyung Kimce74f602012-12-10 17:29:55 +0900743 if (sort__need_collapse)
744 root = &hists->entries_collapsed;
745 else
746 root = hists->entries_in;
747
748 p = &root->rb_node;
749
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300750 while (*p != NULL) {
751 parent = *p;
Namhyung Kimce74f602012-12-10 17:29:55 +0900752 he = rb_entry(parent, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300753
Namhyung Kimce74f602012-12-10 17:29:55 +0900754 cmp = hist_entry__collapse(he, pair);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300755
756 if (!cmp)
757 goto out;
758
759 if (cmp < 0)
760 p = &(*p)->rb_left;
761 else
762 p = &(*p)->rb_right;
763 }
764
765 he = hist_entry__new(pair);
766 if (he) {
Arnaldo Carvalho de Melo30193d72012-11-12 13:20:03 -0300767 memset(&he->stat, 0, sizeof(he->stat));
768 he->hists = hists;
Namhyung Kimce74f602012-12-10 17:29:55 +0900769 rb_link_node(&he->rb_node_in, parent, p);
770 rb_insert_color(&he->rb_node_in, root);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300771 hists__inc_nr_entries(hists, he);
772 }
773out:
774 return he;
775}
776
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300777static struct hist_entry *hists__find_entry(struct hists *hists,
778 struct hist_entry *he)
779{
Namhyung Kimce74f602012-12-10 17:29:55 +0900780 struct rb_node *n;
781
782 if (sort__need_collapse)
783 n = hists->entries_collapsed.rb_node;
784 else
785 n = hists->entries_in->rb_node;
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300786
787 while (n) {
Namhyung Kimce74f602012-12-10 17:29:55 +0900788 struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in);
789 int64_t cmp = hist_entry__collapse(iter, he);
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300790
791 if (cmp < 0)
792 n = n->rb_left;
793 else if (cmp > 0)
794 n = n->rb_right;
795 else
796 return iter;
797 }
798
799 return NULL;
800}
801
802/*
803 * Look for pairs to link to the leader buckets (hist_entries):
804 */
805void hists__match(struct hists *leader, struct hists *other)
806{
Namhyung Kimce74f602012-12-10 17:29:55 +0900807 struct rb_root *root;
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300808 struct rb_node *nd;
809 struct hist_entry *pos, *pair;
810
Namhyung Kimce74f602012-12-10 17:29:55 +0900811 if (sort__need_collapse)
812 root = &leader->entries_collapsed;
813 else
814 root = leader->entries_in;
815
816 for (nd = rb_first(root); nd; nd = rb_next(nd)) {
817 pos = rb_entry(nd, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300818 pair = hists__find_entry(other, pos);
819
820 if (pair)
Namhyung Kim5fa90412012-11-29 15:38:34 +0900821 hist_entry__add_pair(pair, pos);
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300822 }
823}
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300824
825/*
826 * Look for entries in the other hists that are not present in the leader, if
827 * we find them, just add a dummy entry on the leader hists, with period=0,
828 * nr_events=0, to serve as the list header.
829 */
830int hists__link(struct hists *leader, struct hists *other)
831{
Namhyung Kimce74f602012-12-10 17:29:55 +0900832 struct rb_root *root;
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300833 struct rb_node *nd;
834 struct hist_entry *pos, *pair;
835
Namhyung Kimce74f602012-12-10 17:29:55 +0900836 if (sort__need_collapse)
837 root = &other->entries_collapsed;
838 else
839 root = other->entries_in;
840
841 for (nd = rb_first(root); nd; nd = rb_next(nd)) {
842 pos = rb_entry(nd, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300843
844 if (!hist_entry__has_pairs(pos)) {
845 pair = hists__add_dummy_entry(leader, pos);
846 if (pair == NULL)
847 return -1;
Namhyung Kim5fa90412012-11-29 15:38:34 +0900848 hist_entry__add_pair(pos, pair);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300849 }
850 }
851
852 return 0;
853}