blob: 965ebf948f2f39432a7c90dbc4f5e8c45fa5a80e [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
85 if (h->branch_info) {
86 int symlen;
87 /*
88 * +4 accounts for '[x] ' priv level info
89 * +2 account of 0x prefix on raw addresses
90 */
91 if (h->branch_info->from.sym) {
92 symlen = (int)h->branch_info->from.sym->namelen + 4;
93 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
94
95 symlen = dso__name_len(h->branch_info->from.map->dso);
96 hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
97 } else {
98 symlen = unresolved_col_width + 4 + 2;
99 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
100 hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM);
101 }
102
103 if (h->branch_info->to.sym) {
104 symlen = (int)h->branch_info->to.sym->namelen + 4;
105 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
106
107 symlen = dso__name_len(h->branch_info->to.map->dso);
108 hists__new_col_len(hists, HISTC_DSO_TO, symlen);
109 } else {
110 symlen = unresolved_col_width + 4 + 2;
111 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
112 hists__set_unres_dso_col_len(hists, HISTC_DSO_TO);
113 }
114 }
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300115}
116
Namhyung Kim7ccf4f92012-08-20 13:52:05 +0900117void hists__output_recalc_col_len(struct hists *hists, int max_rows)
118{
119 struct rb_node *next = rb_first(&hists->entries);
120 struct hist_entry *n;
121 int row = 0;
122
123 hists__reset_col_len(hists);
124
125 while (next && row++ < max_rows) {
126 n = rb_entry(next, struct hist_entry, rb_node);
127 if (!n->filtered)
128 hists__calc_col_len(hists, n);
129 next = rb_next(&n->rb_node);
130 }
131}
132
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200133static void hist_entry__add_cpumode_period(struct hist_entry *he,
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300134 unsigned int cpumode, u64 period)
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800135{
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300136 switch (cpumode) {
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800137 case PERF_RECORD_MISC_KERNEL:
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900138 he->stat.period_sys += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800139 break;
140 case PERF_RECORD_MISC_USER:
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900141 he->stat.period_us += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800142 break;
143 case PERF_RECORD_MISC_GUEST_KERNEL:
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900144 he->stat.period_guest_sys += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800145 break;
146 case PERF_RECORD_MISC_GUEST_USER:
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900147 he->stat.period_guest_us += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800148 break;
149 default:
150 break;
151 }
152}
153
Namhyung Kim139c0812012-10-04 21:49:43 +0900154static void he_stat__add_period(struct he_stat *he_stat, u64 period)
155{
156 he_stat->period += period;
157 he_stat->nr_events += 1;
158}
159
160static void he_stat__add_stat(struct he_stat *dest, struct he_stat *src)
161{
162 dest->period += src->period;
163 dest->period_sys += src->period_sys;
164 dest->period_us += src->period_us;
165 dest->period_guest_sys += src->period_guest_sys;
166 dest->period_guest_us += src->period_guest_us;
167 dest->nr_events += src->nr_events;
168}
169
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300170static void hist_entry__decay(struct hist_entry *he)
171{
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900172 he->stat.period = (he->stat.period * 7) / 8;
173 he->stat.nr_events = (he->stat.nr_events * 7) / 8;
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300174}
175
176static bool hists__decay_entry(struct hists *hists, struct hist_entry *he)
177{
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900178 u64 prev_period = he->stat.period;
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200179
180 if (prev_period == 0)
Arnaldo Carvalho de Melodf71d952011-10-13 08:01:33 -0300181 return true;
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200182
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300183 hist_entry__decay(he);
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200184
185 if (!he->filtered)
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900186 hists->stats.total_period -= prev_period - he->stat.period;
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200187
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900188 return he->stat.period == 0;
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300189}
190
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200191static void __hists__decay_entries(struct hists *hists, bool zap_user,
192 bool zap_kernel, bool threaded)
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300193{
194 struct rb_node *next = rb_first(&hists->entries);
195 struct hist_entry *n;
196
197 while (next) {
198 n = rb_entry(next, struct hist_entry, rb_node);
199 next = rb_next(&n->rb_node);
Arnaldo Carvalho de Melodf71d952011-10-13 08:01:33 -0300200 /*
201 * We may be annotating this, for instance, so keep it here in
202 * case some it gets new samples, we'll eventually free it when
203 * the user stops browsing and it agains gets fully decayed.
204 */
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200205 if (((zap_user && n->level == '.') ||
206 (zap_kernel && n->level != '.') ||
207 hists__decay_entry(hists, n)) &&
208 !n->used) {
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300209 rb_erase(&n->rb_node, &hists->entries);
210
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300211 if (sort__need_collapse || threaded)
Arnaldo Carvalho de Meloab81f3f2011-10-05 19:16:15 -0300212 rb_erase(&n->rb_node_in, &hists->entries_collapsed);
213
214 hist_entry__free(n);
215 --hists->nr_entries;
216 }
217 }
218}
219
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200220void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300221{
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200222 return __hists__decay_entries(hists, zap_user, zap_kernel, false);
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300223}
224
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200225void hists__decay_entries_threaded(struct hists *hists,
226 bool zap_user, bool zap_kernel)
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300227{
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200228 return __hists__decay_entries(hists, zap_user, zap_kernel, true);
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300229}
230
John Kacur3d1d07e2009-09-28 15:32:55 +0200231/*
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300232 * histogram, sorted on item, collects periods
John Kacur3d1d07e2009-09-28 15:32:55 +0200233 */
234
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300235static struct hist_entry *hist_entry__new(struct hist_entry *template)
236{
Frederic Weisbeckerd2009c52010-08-22 20:05:22 +0200237 size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0;
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200238 struct hist_entry *he = malloc(sizeof(*he) + callchain_size);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300239
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200240 if (he != NULL) {
241 *he = *template;
Namhyung Kimc4b35352012-10-04 21:49:42 +0900242
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200243 if (he->ms.map)
244 he->ms.map->referenced = true;
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300245 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200246 callchain_init(he->callchain);
Arnaldo Carvalho de Melob821c732012-10-25 14:42:45 -0200247
248 INIT_LIST_HEAD(&he->pairs.node);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300249 }
250
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200251 return he;
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300252}
253
Namhyung Kim66f97ed2012-12-10 17:29:56 +0900254void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h)
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300255{
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300256 if (!h->filtered) {
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300257 hists__calc_col_len(hists, h);
258 ++hists->nr_entries;
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900259 hists->stats.total_period += h->stat.period;
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300260 }
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300261}
262
Arnaldo Carvalho de Melo7a007ca2010-07-21 09:19:41 -0300263static u8 symbol__parent_filter(const struct symbol *parent)
264{
265 if (symbol_conf.exclude_other && parent == NULL)
266 return 1 << HIST_FILTER__PARENT;
267 return 0;
268}
269
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100270static struct hist_entry *add_hist_entry(struct hists *hists,
271 struct hist_entry *entry,
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300272 struct addr_location *al,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100273 u64 period)
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300274{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300275 struct rb_node **p;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300276 struct rb_node *parent = NULL;
277 struct hist_entry *he;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300278 int cmp;
279
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300280 pthread_mutex_lock(&hists->lock);
281
282 p = &hists->entries_in->rb_node;
283
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300284 while (*p != NULL) {
285 parent = *p;
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300286 he = rb_entry(parent, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300287
Namhyung Kim9afcf932012-12-10 17:29:54 +0900288 /*
289 * Make sure that it receives arguments in a same order as
290 * hist_entry__collapse() so that we can use an appropriate
291 * function when searching an entry regardless which sort
292 * keys were used.
293 */
294 cmp = hist_entry__cmp(he, entry);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300295
296 if (!cmp) {
Namhyung Kim139c0812012-10-04 21:49:43 +0900297 he_stat__add_period(&he->stat, period);
David Miller63fa4712012-03-27 03:14:18 -0400298
299 /* If the map of an existing hist_entry has
300 * become out-of-date due to an exec() or
301 * similar, update it. Otherwise we will
302 * mis-adjust symbol addresses when computing
303 * the history counter to increment.
304 */
305 if (he->ms.map != entry->ms.map) {
306 he->ms.map = entry->ms.map;
307 if (he->ms.map)
308 he->ms.map->referenced = true;
309 }
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300310 goto out;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300311 }
312
313 if (cmp < 0)
314 p = &(*p)->rb_left;
315 else
316 p = &(*p)->rb_right;
317 }
318
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100319 he = hist_entry__new(entry);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300320 if (!he)
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300321 goto out_unlock;
322
323 rb_link_node(&he->rb_node_in, parent, p);
324 rb_insert_color(&he->rb_node_in, hists->entries_in);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300325out:
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300326 hist_entry__add_cpumode_period(he, al->cpumode, period);
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300327out_unlock:
328 pthread_mutex_unlock(&hists->lock);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300329 return he;
330}
331
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100332struct hist_entry *__hists__add_branch_entry(struct hists *self,
333 struct addr_location *al,
334 struct symbol *sym_parent,
335 struct branch_info *bi,
336 u64 period)
337{
338 struct hist_entry entry = {
339 .thread = al->thread,
340 .ms = {
341 .map = bi->to.map,
342 .sym = bi->to.sym,
343 },
344 .cpu = al->cpu,
345 .ip = bi->to.addr,
346 .level = al->level,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900347 .stat = {
348 .period = period,
Namhyung Kimc4b35352012-10-04 21:49:42 +0900349 .nr_events = 1,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900350 },
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100351 .parent = sym_parent,
352 .filtered = symbol__parent_filter(sym_parent),
353 .branch_info = bi,
Jiri Olsaae359f12012-10-04 21:49:35 +0900354 .hists = self,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100355 };
356
357 return add_hist_entry(self, &entry, al, period);
358}
359
360struct hist_entry *__hists__add_entry(struct hists *self,
361 struct addr_location *al,
362 struct symbol *sym_parent, u64 period)
363{
364 struct hist_entry entry = {
365 .thread = al->thread,
366 .ms = {
367 .map = al->map,
368 .sym = al->sym,
369 },
370 .cpu = al->cpu,
371 .ip = al->addr,
372 .level = al->level,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900373 .stat = {
374 .period = period,
Namhyung Kimc4b35352012-10-04 21:49:42 +0900375 .nr_events = 1,
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900376 },
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100377 .parent = sym_parent,
378 .filtered = symbol__parent_filter(sym_parent),
Jiri Olsaae359f12012-10-04 21:49:35 +0900379 .hists = self,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100380 };
381
382 return add_hist_entry(self, &entry, al, period);
383}
384
John Kacur3d1d07e2009-09-28 15:32:55 +0200385int64_t
386hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
387{
388 struct sort_entry *se;
389 int64_t cmp = 0;
390
391 list_for_each_entry(se, &hist_entry__sort_list, list) {
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200392 cmp = se->se_cmp(left, right);
John Kacur3d1d07e2009-09-28 15:32:55 +0200393 if (cmp)
394 break;
395 }
396
397 return cmp;
398}
399
400int64_t
401hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
402{
403 struct sort_entry *se;
404 int64_t cmp = 0;
405
406 list_for_each_entry(se, &hist_entry__sort_list, list) {
407 int64_t (*f)(struct hist_entry *, struct hist_entry *);
408
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200409 f = se->se_collapse ?: se->se_cmp;
John Kacur3d1d07e2009-09-28 15:32:55 +0200410
411 cmp = f(left, right);
412 if (cmp)
413 break;
414 }
415
416 return cmp;
417}
418
419void hist_entry__free(struct hist_entry *he)
420{
Namhyung Kim580e3382012-11-07 16:27:14 +0900421 free(he->branch_info);
John Kacur3d1d07e2009-09-28 15:32:55 +0200422 free(he);
423}
424
425/*
426 * collapse the histogram
427 */
428
Irina Tirdea1d037ca2012-09-11 01:15:03 +0300429static bool hists__collapse_insert_entry(struct hists *hists __maybe_unused,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100430 struct rb_root *root,
431 struct hist_entry *he)
John Kacur3d1d07e2009-09-28 15:32:55 +0200432{
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200433 struct rb_node **p = &root->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200434 struct rb_node *parent = NULL;
435 struct hist_entry *iter;
436 int64_t cmp;
437
438 while (*p != NULL) {
439 parent = *p;
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300440 iter = rb_entry(parent, struct hist_entry, rb_node_in);
John Kacur3d1d07e2009-09-28 15:32:55 +0200441
442 cmp = hist_entry__collapse(iter, he);
443
444 if (!cmp) {
Namhyung Kim139c0812012-10-04 21:49:43 +0900445 he_stat__add_stat(&iter->stat, &he->stat);
Namhyung Kim9ec60972012-09-26 16:47:28 +0900446
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100447 if (symbol_conf.use_callchain) {
Namhyung Kim47260642012-05-31 14:43:26 +0900448 callchain_cursor_reset(&callchain_cursor);
449 callchain_merge(&callchain_cursor,
450 iter->callchain,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100451 he->callchain);
452 }
John Kacur3d1d07e2009-09-28 15:32:55 +0200453 hist_entry__free(he);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300454 return false;
John Kacur3d1d07e2009-09-28 15:32:55 +0200455 }
456
457 if (cmp < 0)
458 p = &(*p)->rb_left;
459 else
460 p = &(*p)->rb_right;
461 }
462
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300463 rb_link_node(&he->rb_node_in, parent, p);
464 rb_insert_color(&he->rb_node_in, root);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300465 return true;
John Kacur3d1d07e2009-09-28 15:32:55 +0200466}
467
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300468static struct rb_root *hists__get_rotate_entries_in(struct hists *hists)
469{
470 struct rb_root *root;
471
472 pthread_mutex_lock(&hists->lock);
473
474 root = hists->entries_in;
475 if (++hists->entries_in > &hists->entries_in_array[1])
476 hists->entries_in = &hists->entries_in_array[0];
477
478 pthread_mutex_unlock(&hists->lock);
479
480 return root;
481}
482
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200483static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
484{
485 hists__filter_entry_by_dso(hists, he);
486 hists__filter_entry_by_thread(hists, he);
Namhyung Kime94d53e2012-03-16 17:50:51 +0900487 hists__filter_entry_by_symbol(hists, he);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200488}
489
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300490static void __hists__collapse_resort(struct hists *hists, bool threaded)
491{
492 struct rb_root *root;
493 struct rb_node *next;
494 struct hist_entry *n;
495
496 if (!sort__need_collapse && !threaded)
497 return;
498
499 root = hists__get_rotate_entries_in(hists);
500 next = rb_first(root);
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300501
502 while (next) {
503 n = rb_entry(next, struct hist_entry, rb_node_in);
504 next = rb_next(&n->rb_node_in);
505
506 rb_erase(&n->rb_node_in, root);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200507 if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) {
508 /*
509 * If it wasn't combined with one of the entries already
510 * collapsed, we need to apply the filters that may have
511 * been set by, say, the hist_browser.
512 */
513 hists__apply_filters(hists, n);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200514 }
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300515 }
516}
517
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300518void hists__collapse_resort(struct hists *hists)
John Kacur3d1d07e2009-09-28 15:32:55 +0200519{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300520 return __hists__collapse_resort(hists, false);
521}
John Kacur3d1d07e2009-09-28 15:32:55 +0200522
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300523void hists__collapse_resort_threaded(struct hists *hists)
524{
525 return __hists__collapse_resort(hists, true);
John Kacur3d1d07e2009-09-28 15:32:55 +0200526}
527
528/*
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300529 * reverse the map, sort on period.
John Kacur3d1d07e2009-09-28 15:32:55 +0200530 */
531
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300532static void __hists__insert_output_entry(struct rb_root *entries,
533 struct hist_entry *he,
534 u64 min_callchain_hits)
John Kacur3d1d07e2009-09-28 15:32:55 +0200535{
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300536 struct rb_node **p = &entries->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200537 struct rb_node *parent = NULL;
538 struct hist_entry *iter;
539
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200540 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Melob9fb9302010-04-02 09:50:42 -0300541 callchain_param.sort(&he->sorted_chain, he->callchain,
John Kacur3d1d07e2009-09-28 15:32:55 +0200542 min_callchain_hits, &callchain_param);
543
544 while (*p != NULL) {
545 parent = *p;
546 iter = rb_entry(parent, struct hist_entry, rb_node);
547
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900548 if (he->stat.period > iter->stat.period)
John Kacur3d1d07e2009-09-28 15:32:55 +0200549 p = &(*p)->rb_left;
550 else
551 p = &(*p)->rb_right;
552 }
553
554 rb_link_node(&he->rb_node, parent, p);
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300555 rb_insert_color(&he->rb_node, entries);
John Kacur3d1d07e2009-09-28 15:32:55 +0200556}
557
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300558static void __hists__output_resort(struct hists *hists, bool threaded)
John Kacur3d1d07e2009-09-28 15:32:55 +0200559{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300560 struct rb_root *root;
John Kacur3d1d07e2009-09-28 15:32:55 +0200561 struct rb_node *next;
562 struct hist_entry *n;
John Kacur3d1d07e2009-09-28 15:32:55 +0200563 u64 min_callchain_hits;
564
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300565 min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
John Kacur3d1d07e2009-09-28 15:32:55 +0200566
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300567 if (sort__need_collapse || threaded)
568 root = &hists->entries_collapsed;
569 else
570 root = hists->entries_in;
571
572 next = rb_first(root);
573 hists->entries = RB_ROOT;
John Kacur3d1d07e2009-09-28 15:32:55 +0200574
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300575 hists->nr_entries = 0;
Arnaldo Carvalho de Melo79286312011-10-27 09:19:48 -0200576 hists->stats.total_period = 0;
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300577 hists__reset_col_len(hists);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300578
John Kacur3d1d07e2009-09-28 15:32:55 +0200579 while (next) {
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300580 n = rb_entry(next, struct hist_entry, rb_node_in);
581 next = rb_next(&n->rb_node_in);
John Kacur3d1d07e2009-09-28 15:32:55 +0200582
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300583 __hists__insert_output_entry(&hists->entries, n, min_callchain_hits);
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300584 hists__inc_nr_entries(hists, n);
John Kacur3d1d07e2009-09-28 15:32:55 +0200585 }
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300586}
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200587
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300588void hists__output_resort(struct hists *hists)
589{
590 return __hists__output_resort(hists, false);
591}
592
593void hists__output_resort_threaded(struct hists *hists)
594{
595 return __hists__output_resort(hists, true);
John Kacur3d1d07e2009-09-28 15:32:55 +0200596}
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200597
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300598static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h,
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300599 enum hist_filter filter)
600{
601 h->filtered &= ~(1 << filter);
602 if (h->filtered)
603 return;
604
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300605 ++hists->nr_entries;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -0300606 if (h->ms.unfolded)
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300607 hists->nr_entries += h->nr_rows;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -0300608 h->row_offset = 0;
Namhyung Kimb24c28f2012-10-04 21:49:41 +0900609 hists->stats.total_period += h->stat.period;
610 hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->stat.nr_events;
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300611
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300612 hists__calc_col_len(hists, h);
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300613}
614
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200615
616static bool hists__filter_entry_by_dso(struct hists *hists,
617 struct hist_entry *he)
618{
619 if (hists->dso_filter != NULL &&
620 (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
621 he->filtered |= (1 << HIST_FILTER__DSO);
622 return true;
623 }
624
625 return false;
626}
627
Arnaldo Carvalho de Melod7b76f02011-10-18 19:07:34 -0200628void hists__filter_by_dso(struct hists *hists)
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300629{
630 struct rb_node *nd;
631
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300632 hists->nr_entries = hists->stats.total_period = 0;
633 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
634 hists__reset_col_len(hists);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300635
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300636 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300637 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
638
639 if (symbol_conf.exclude_other && !h->parent)
640 continue;
641
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200642 if (hists__filter_entry_by_dso(hists, h))
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300643 continue;
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300644
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300645 hists__remove_entry_filter(hists, h, HIST_FILTER__DSO);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300646 }
647}
648
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200649static bool hists__filter_entry_by_thread(struct hists *hists,
650 struct hist_entry *he)
651{
652 if (hists->thread_filter != NULL &&
653 he->thread != hists->thread_filter) {
654 he->filtered |= (1 << HIST_FILTER__THREAD);
655 return true;
656 }
657
658 return false;
659}
660
Arnaldo Carvalho de Melod7b76f02011-10-18 19:07:34 -0200661void hists__filter_by_thread(struct hists *hists)
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300662{
663 struct rb_node *nd;
664
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300665 hists->nr_entries = hists->stats.total_period = 0;
666 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
667 hists__reset_col_len(hists);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300668
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300669 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300670 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
671
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200672 if (hists__filter_entry_by_thread(hists, h))
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300673 continue;
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -0300674
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300675 hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -0300676 }
677}
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300678
Namhyung Kime94d53e2012-03-16 17:50:51 +0900679static bool hists__filter_entry_by_symbol(struct hists *hists,
680 struct hist_entry *he)
681{
682 if (hists->symbol_filter_str != NULL &&
683 (!he->ms.sym || strstr(he->ms.sym->name,
684 hists->symbol_filter_str) == NULL)) {
685 he->filtered |= (1 << HIST_FILTER__SYMBOL);
686 return true;
687 }
688
689 return false;
690}
691
692void hists__filter_by_symbol(struct hists *hists)
693{
694 struct rb_node *nd;
695
696 hists->nr_entries = hists->stats.total_period = 0;
697 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
698 hists__reset_col_len(hists);
699
700 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
701 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
702
703 if (hists__filter_entry_by_symbol(hists, h))
704 continue;
705
706 hists__remove_entry_filter(hists, h, HIST_FILTER__SYMBOL);
707 }
708}
709
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200710int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300711{
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -0200712 return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300713}
714
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200715int hist_entry__annotate(struct hist_entry *he, size_t privsize)
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300716{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -0200717 return symbol__annotate(he->ms.sym, he->ms.map, privsize);
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -0300718}
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300719
Arnaldo Carvalho de Melo28a6b6a2012-12-18 16:24:46 -0300720void events_stats__inc(struct events_stats *stats, u32 type)
721{
722 ++stats->nr_events[0];
723 ++stats->nr_events[type];
724}
725
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300726void hists__inc_nr_events(struct hists *hists, u32 type)
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300727{
Arnaldo Carvalho de Melo28a6b6a2012-12-18 16:24:46 -0300728 events_stats__inc(&hists->stats, type);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -0300729}
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300730
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300731static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
732 struct hist_entry *pair)
733{
Namhyung Kimce74f602012-12-10 17:29:55 +0900734 struct rb_root *root;
735 struct rb_node **p;
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300736 struct rb_node *parent = NULL;
737 struct hist_entry *he;
738 int cmp;
739
Namhyung Kimce74f602012-12-10 17:29:55 +0900740 if (sort__need_collapse)
741 root = &hists->entries_collapsed;
742 else
743 root = hists->entries_in;
744
745 p = &root->rb_node;
746
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300747 while (*p != NULL) {
748 parent = *p;
Namhyung Kimce74f602012-12-10 17:29:55 +0900749 he = rb_entry(parent, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300750
Namhyung Kimce74f602012-12-10 17:29:55 +0900751 cmp = hist_entry__collapse(he, pair);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300752
753 if (!cmp)
754 goto out;
755
756 if (cmp < 0)
757 p = &(*p)->rb_left;
758 else
759 p = &(*p)->rb_right;
760 }
761
762 he = hist_entry__new(pair);
763 if (he) {
Arnaldo Carvalho de Melo30193d72012-11-12 13:20:03 -0300764 memset(&he->stat, 0, sizeof(he->stat));
765 he->hists = hists;
Namhyung Kimce74f602012-12-10 17:29:55 +0900766 rb_link_node(&he->rb_node_in, parent, p);
767 rb_insert_color(&he->rb_node_in, root);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300768 hists__inc_nr_entries(hists, he);
769 }
770out:
771 return he;
772}
773
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300774static struct hist_entry *hists__find_entry(struct hists *hists,
775 struct hist_entry *he)
776{
Namhyung Kimce74f602012-12-10 17:29:55 +0900777 struct rb_node *n;
778
779 if (sort__need_collapse)
780 n = hists->entries_collapsed.rb_node;
781 else
782 n = hists->entries_in->rb_node;
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300783
784 while (n) {
Namhyung Kimce74f602012-12-10 17:29:55 +0900785 struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in);
786 int64_t cmp = hist_entry__collapse(iter, he);
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300787
788 if (cmp < 0)
789 n = n->rb_left;
790 else if (cmp > 0)
791 n = n->rb_right;
792 else
793 return iter;
794 }
795
796 return NULL;
797}
798
799/*
800 * Look for pairs to link to the leader buckets (hist_entries):
801 */
802void hists__match(struct hists *leader, struct hists *other)
803{
Namhyung Kimce74f602012-12-10 17:29:55 +0900804 struct rb_root *root;
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300805 struct rb_node *nd;
806 struct hist_entry *pos, *pair;
807
Namhyung Kimce74f602012-12-10 17:29:55 +0900808 if (sort__need_collapse)
809 root = &leader->entries_collapsed;
810 else
811 root = leader->entries_in;
812
813 for (nd = rb_first(root); nd; nd = rb_next(nd)) {
814 pos = rb_entry(nd, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300815 pair = hists__find_entry(other, pos);
816
817 if (pair)
Namhyung Kim5fa90412012-11-29 15:38:34 +0900818 hist_entry__add_pair(pair, pos);
Arnaldo Carvalho de Melo95529be2012-11-08 17:54:33 -0300819 }
820}
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300821
822/*
823 * Look for entries in the other hists that are not present in the leader, if
824 * we find them, just add a dummy entry on the leader hists, with period=0,
825 * nr_events=0, to serve as the list header.
826 */
827int hists__link(struct hists *leader, struct hists *other)
828{
Namhyung Kimce74f602012-12-10 17:29:55 +0900829 struct rb_root *root;
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300830 struct rb_node *nd;
831 struct hist_entry *pos, *pair;
832
Namhyung Kimce74f602012-12-10 17:29:55 +0900833 if (sort__need_collapse)
834 root = &other->entries_collapsed;
835 else
836 root = other->entries_in;
837
838 for (nd = rb_first(root); nd; nd = rb_next(nd)) {
839 pos = rb_entry(nd, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300840
841 if (!hist_entry__has_pairs(pos)) {
842 pair = hists__add_dummy_entry(leader, pos);
843 if (pair == NULL)
844 return -1;
Namhyung Kim5fa90412012-11-29 15:38:34 +0900845 hist_entry__add_pair(pos, pair);
Arnaldo Carvalho de Melo494d70a2012-11-08 18:03:09 -0300846 }
847 }
848
849 return 0;
850}