blob: 8380c3db1c920d9c2f0a6b72c777127e1323c852 [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);
13
Arnaldo Carvalho de Melo7a007ca2010-07-21 09:19:41 -030014enum hist_filter {
15 HIST_FILTER__DSO,
16 HIST_FILTER__THREAD,
17 HIST_FILTER__PARENT,
18};
19
John Kacur3d1d07e2009-09-28 15:32:55 +020020struct callchain_param callchain_param = {
21 .mode = CHAIN_GRAPH_REL,
Sam Liaod797fdc2011-06-07 23:49:46 +080022 .min_percent = 0.5,
23 .order = ORDER_CALLEE
John Kacur3d1d07e2009-09-28 15:32:55 +020024};
25
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030026u16 hists__col_len(struct hists *hists, enum hist_column col)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030027{
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030028 return hists->col_len[col];
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030029}
30
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030031void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030032{
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030033 hists->col_len[col] = len;
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030034}
35
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030036bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030037{
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030038 if (len > hists__col_len(hists, col)) {
39 hists__set_col_len(hists, col, len);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030040 return true;
41 }
42 return false;
43}
44
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030045static void hists__reset_col_len(struct hists *hists)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030046{
47 enum hist_column col;
48
49 for (col = 0; col < HISTC_NR_COLS; ++col)
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030050 hists__set_col_len(hists, col, 0);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030051}
52
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010053static void hists__set_unres_dso_col_len(struct hists *hists, int dso)
54{
55 const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
56
57 if (hists__col_len(hists, dso) < unresolved_col_width &&
58 !symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
59 !symbol_conf.dso_list)
60 hists__set_col_len(hists, dso, unresolved_col_width);
61}
62
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030063static void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030064{
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010065 const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030066 u16 len;
67
68 if (h->ms.sym)
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010069 hists__new_col_len(hists, HISTC_SYMBOL, h->ms.sym->namelen + 4);
70 else
71 hists__set_unres_dso_col_len(hists, HISTC_DSO);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030072
73 len = thread__comm_len(h->thread);
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030074 if (hists__new_col_len(hists, HISTC_COMM, len))
75 hists__set_col_len(hists, HISTC_THREAD, len + 6);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030076
77 if (h->ms.map) {
78 len = dso__name_len(h->ms.map->dso);
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -030079 hists__new_col_len(hists, HISTC_DSO, len);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -030080 }
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +010081
82 if (h->branch_info) {
83 int symlen;
84 /*
85 * +4 accounts for '[x] ' priv level info
86 * +2 account of 0x prefix on raw addresses
87 */
88 if (h->branch_info->from.sym) {
89 symlen = (int)h->branch_info->from.sym->namelen + 4;
90 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
91
92 symlen = dso__name_len(h->branch_info->from.map->dso);
93 hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
94 } else {
95 symlen = unresolved_col_width + 4 + 2;
96 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
97 hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM);
98 }
99
100 if (h->branch_info->to.sym) {
101 symlen = (int)h->branch_info->to.sym->namelen + 4;
102 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
103
104 symlen = dso__name_len(h->branch_info->to.map->dso);
105 hists__new_col_len(hists, HISTC_DSO_TO, symlen);
106 } else {
107 symlen = unresolved_col_width + 4 + 2;
108 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
109 hists__set_unres_dso_col_len(hists, HISTC_DSO_TO);
110 }
111 }
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300112}
113
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200114static void hist_entry__add_cpumode_period(struct hist_entry *he,
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300115 unsigned int cpumode, u64 period)
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800116{
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300117 switch (cpumode) {
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800118 case PERF_RECORD_MISC_KERNEL:
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200119 he->period_sys += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800120 break;
121 case PERF_RECORD_MISC_USER:
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200122 he->period_us += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800123 break;
124 case PERF_RECORD_MISC_GUEST_KERNEL:
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200125 he->period_guest_sys += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800126 break;
127 case PERF_RECORD_MISC_GUEST_USER:
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200128 he->period_guest_us += period;
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800129 break;
130 default:
131 break;
132 }
133}
134
Arnaldo Carvalho de Meloab81f3fd2011-10-05 19:16:15 -0300135static void hist_entry__decay(struct hist_entry *he)
136{
137 he->period = (he->period * 7) / 8;
138 he->nr_events = (he->nr_events * 7) / 8;
139}
140
141static bool hists__decay_entry(struct hists *hists, struct hist_entry *he)
142{
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200143 u64 prev_period = he->period;
144
145 if (prev_period == 0)
Arnaldo Carvalho de Melodf71d952011-10-13 08:01:33 -0300146 return true;
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200147
Arnaldo Carvalho de Meloab81f3fd2011-10-05 19:16:15 -0300148 hist_entry__decay(he);
Arnaldo Carvalho de Meloc64550c2011-10-20 06:45:44 -0200149
150 if (!he->filtered)
151 hists->stats.total_period -= prev_period - he->period;
152
Arnaldo Carvalho de Meloab81f3fd2011-10-05 19:16:15 -0300153 return he->period == 0;
154}
155
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200156static void __hists__decay_entries(struct hists *hists, bool zap_user,
157 bool zap_kernel, bool threaded)
Arnaldo Carvalho de Meloab81f3fd2011-10-05 19:16:15 -0300158{
159 struct rb_node *next = rb_first(&hists->entries);
160 struct hist_entry *n;
161
162 while (next) {
163 n = rb_entry(next, struct hist_entry, rb_node);
164 next = rb_next(&n->rb_node);
Arnaldo Carvalho de Melodf71d952011-10-13 08:01:33 -0300165 /*
166 * We may be annotating this, for instance, so keep it here in
167 * case some it gets new samples, we'll eventually free it when
168 * the user stops browsing and it agains gets fully decayed.
169 */
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200170 if (((zap_user && n->level == '.') ||
171 (zap_kernel && n->level != '.') ||
172 hists__decay_entry(hists, n)) &&
173 !n->used) {
Arnaldo Carvalho de Meloab81f3fd2011-10-05 19:16:15 -0300174 rb_erase(&n->rb_node, &hists->entries);
175
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300176 if (sort__need_collapse || threaded)
Arnaldo Carvalho de Meloab81f3fd2011-10-05 19:16:15 -0300177 rb_erase(&n->rb_node_in, &hists->entries_collapsed);
178
179 hist_entry__free(n);
180 --hists->nr_entries;
181 }
182 }
183}
184
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200185void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300186{
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200187 return __hists__decay_entries(hists, zap_user, zap_kernel, false);
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300188}
189
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200190void hists__decay_entries_threaded(struct hists *hists,
191 bool zap_user, bool zap_kernel)
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300192{
Arnaldo Carvalho de Melob079d4e2011-10-17 09:05:04 -0200193 return __hists__decay_entries(hists, zap_user, zap_kernel, true);
Arnaldo Carvalho de Meloe345fa12011-10-13 09:06:54 -0300194}
195
John Kacur3d1d07e2009-09-28 15:32:55 +0200196/*
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300197 * histogram, sorted on item, collects periods
John Kacur3d1d07e2009-09-28 15:32:55 +0200198 */
199
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300200static struct hist_entry *hist_entry__new(struct hist_entry *template)
201{
Frederic Weisbeckerd2009c52010-08-22 20:05:22 +0200202 size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_root) : 0;
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200203 struct hist_entry *he = malloc(sizeof(*he) + callchain_size);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300204
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200205 if (he != NULL) {
206 *he = *template;
207 he->nr_events = 1;
208 if (he->ms.map)
209 he->ms.map->referenced = true;
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300210 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200211 callchain_init(he->callchain);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300212 }
213
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200214 return he;
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300215}
216
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300217static void hists__inc_nr_entries(struct hists *hists, struct hist_entry *h)
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300218{
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300219 if (!h->filtered) {
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300220 hists__calc_col_len(hists, h);
221 ++hists->nr_entries;
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300222 hists->stats.total_period += h->period;
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300223 }
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300224}
225
Arnaldo Carvalho de Melo7a007ca2010-07-21 09:19:41 -0300226static u8 symbol__parent_filter(const struct symbol *parent)
227{
228 if (symbol_conf.exclude_other && parent == NULL)
229 return 1 << HIST_FILTER__PARENT;
230 return 0;
231}
232
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100233static struct hist_entry *add_hist_entry(struct hists *hists,
234 struct hist_entry *entry,
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300235 struct addr_location *al,
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100236 u64 period)
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300237{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300238 struct rb_node **p;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300239 struct rb_node *parent = NULL;
240 struct hist_entry *he;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300241 int cmp;
242
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300243 pthread_mutex_lock(&hists->lock);
244
245 p = &hists->entries_in->rb_node;
246
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300247 while (*p != NULL) {
248 parent = *p;
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300249 he = rb_entry(parent, struct hist_entry, rb_node_in);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300250
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100251 cmp = hist_entry__cmp(entry, he);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300252
253 if (!cmp) {
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300254 he->period += period;
255 ++he->nr_events;
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300256 goto out;
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300257 }
258
259 if (cmp < 0)
260 p = &(*p)->rb_left;
261 else
262 p = &(*p)->rb_right;
263 }
264
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100265 he = hist_entry__new(entry);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300266 if (!he)
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300267 goto out_unlock;
268
269 rb_link_node(&he->rb_node_in, parent, p);
270 rb_insert_color(&he->rb_node_in, hists->entries_in);
Arnaldo Carvalho de Melo28e2a102010-05-09 13:02:23 -0300271out:
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300272 hist_entry__add_cpumode_period(he, al->cpumode, period);
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300273out_unlock:
274 pthread_mutex_unlock(&hists->lock);
Arnaldo Carvalho de Melo9735abf2009-10-03 10:42:45 -0300275 return he;
276}
277
Roberto Agostino Vitillob5387522012-02-09 23:21:01 +0100278struct hist_entry *__hists__add_branch_entry(struct hists *self,
279 struct addr_location *al,
280 struct symbol *sym_parent,
281 struct branch_info *bi,
282 u64 period)
283{
284 struct hist_entry entry = {
285 .thread = al->thread,
286 .ms = {
287 .map = bi->to.map,
288 .sym = bi->to.sym,
289 },
290 .cpu = al->cpu,
291 .ip = bi->to.addr,
292 .level = al->level,
293 .period = period,
294 .parent = sym_parent,
295 .filtered = symbol__parent_filter(sym_parent),
296 .branch_info = bi,
297 };
298
299 return add_hist_entry(self, &entry, al, period);
300}
301
302struct hist_entry *__hists__add_entry(struct hists *self,
303 struct addr_location *al,
304 struct symbol *sym_parent, u64 period)
305{
306 struct hist_entry entry = {
307 .thread = al->thread,
308 .ms = {
309 .map = al->map,
310 .sym = al->sym,
311 },
312 .cpu = al->cpu,
313 .ip = al->addr,
314 .level = al->level,
315 .period = period,
316 .parent = sym_parent,
317 .filtered = symbol__parent_filter(sym_parent),
318 };
319
320 return add_hist_entry(self, &entry, al, period);
321}
322
John Kacur3d1d07e2009-09-28 15:32:55 +0200323int64_t
324hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
325{
326 struct sort_entry *se;
327 int64_t cmp = 0;
328
329 list_for_each_entry(se, &hist_entry__sort_list, list) {
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200330 cmp = se->se_cmp(left, right);
John Kacur3d1d07e2009-09-28 15:32:55 +0200331 if (cmp)
332 break;
333 }
334
335 return cmp;
336}
337
338int64_t
339hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
340{
341 struct sort_entry *se;
342 int64_t cmp = 0;
343
344 list_for_each_entry(se, &hist_entry__sort_list, list) {
345 int64_t (*f)(struct hist_entry *, struct hist_entry *);
346
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +0200347 f = se->se_collapse ?: se->se_cmp;
John Kacur3d1d07e2009-09-28 15:32:55 +0200348
349 cmp = f(left, right);
350 if (cmp)
351 break;
352 }
353
354 return cmp;
355}
356
357void hist_entry__free(struct hist_entry *he)
358{
359 free(he);
360}
361
362/*
363 * collapse the histogram
364 */
365
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300366static bool hists__collapse_insert_entry(struct hists *hists,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100367 struct rb_root *root,
368 struct hist_entry *he)
John Kacur3d1d07e2009-09-28 15:32:55 +0200369{
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200370 struct rb_node **p = &root->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200371 struct rb_node *parent = NULL;
372 struct hist_entry *iter;
373 int64_t cmp;
374
375 while (*p != NULL) {
376 parent = *p;
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300377 iter = rb_entry(parent, struct hist_entry, rb_node_in);
John Kacur3d1d07e2009-09-28 15:32:55 +0200378
379 cmp = hist_entry__collapse(iter, he);
380
381 if (!cmp) {
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300382 iter->period += he->period;
Stephane Eraniane39622c2011-10-03 11:38:15 +0200383 iter->nr_events += he->nr_events;
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100384 if (symbol_conf.use_callchain) {
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300385 callchain_cursor_reset(&hists->callchain_cursor);
386 callchain_merge(&hists->callchain_cursor, iter->callchain,
Frederic Weisbecker1b3a0e92011-01-14 04:51:58 +0100387 he->callchain);
388 }
John Kacur3d1d07e2009-09-28 15:32:55 +0200389 hist_entry__free(he);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300390 return false;
John Kacur3d1d07e2009-09-28 15:32:55 +0200391 }
392
393 if (cmp < 0)
394 p = &(*p)->rb_left;
395 else
396 p = &(*p)->rb_right;
397 }
398
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300399 rb_link_node(&he->rb_node_in, parent, p);
400 rb_insert_color(&he->rb_node_in, root);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300401 return true;
John Kacur3d1d07e2009-09-28 15:32:55 +0200402}
403
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300404static struct rb_root *hists__get_rotate_entries_in(struct hists *hists)
405{
406 struct rb_root *root;
407
408 pthread_mutex_lock(&hists->lock);
409
410 root = hists->entries_in;
411 if (++hists->entries_in > &hists->entries_in_array[1])
412 hists->entries_in = &hists->entries_in_array[0];
413
414 pthread_mutex_unlock(&hists->lock);
415
416 return root;
417}
418
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200419static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
420{
421 hists__filter_entry_by_dso(hists, he);
422 hists__filter_entry_by_thread(hists, he);
423}
424
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300425static void __hists__collapse_resort(struct hists *hists, bool threaded)
426{
427 struct rb_root *root;
428 struct rb_node *next;
429 struct hist_entry *n;
430
431 if (!sort__need_collapse && !threaded)
432 return;
433
434 root = hists__get_rotate_entries_in(hists);
435 next = rb_first(root);
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300436
437 while (next) {
438 n = rb_entry(next, struct hist_entry, rb_node_in);
439 next = rb_next(&n->rb_node_in);
440
441 rb_erase(&n->rb_node_in, root);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200442 if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) {
443 /*
444 * If it wasn't combined with one of the entries already
445 * collapsed, we need to apply the filters that may have
446 * been set by, say, the hist_browser.
447 */
448 hists__apply_filters(hists, n);
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -0200449 }
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300450 }
451}
452
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300453void hists__collapse_resort(struct hists *hists)
John Kacur3d1d07e2009-09-28 15:32:55 +0200454{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300455 return __hists__collapse_resort(hists, false);
456}
John Kacur3d1d07e2009-09-28 15:32:55 +0200457
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300458void hists__collapse_resort_threaded(struct hists *hists)
459{
460 return __hists__collapse_resort(hists, true);
John Kacur3d1d07e2009-09-28 15:32:55 +0200461}
462
463/*
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300464 * reverse the map, sort on period.
John Kacur3d1d07e2009-09-28 15:32:55 +0200465 */
466
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300467static void __hists__insert_output_entry(struct rb_root *entries,
468 struct hist_entry *he,
469 u64 min_callchain_hits)
John Kacur3d1d07e2009-09-28 15:32:55 +0200470{
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300471 struct rb_node **p = &entries->rb_node;
John Kacur3d1d07e2009-09-28 15:32:55 +0200472 struct rb_node *parent = NULL;
473 struct hist_entry *iter;
474
Arnaldo Carvalho de Melod599db32009-12-15 20:04:42 -0200475 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Melob9fb9302010-04-02 09:50:42 -0300476 callchain_param.sort(&he->sorted_chain, he->callchain,
John Kacur3d1d07e2009-09-28 15:32:55 +0200477 min_callchain_hits, &callchain_param);
478
479 while (*p != NULL) {
480 parent = *p;
481 iter = rb_entry(parent, struct hist_entry, rb_node);
482
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300483 if (he->period > iter->period)
John Kacur3d1d07e2009-09-28 15:32:55 +0200484 p = &(*p)->rb_left;
485 else
486 p = &(*p)->rb_right;
487 }
488
489 rb_link_node(&he->rb_node, parent, p);
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300490 rb_insert_color(&he->rb_node, entries);
John Kacur3d1d07e2009-09-28 15:32:55 +0200491}
492
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300493static void __hists__output_resort(struct hists *hists, bool threaded)
John Kacur3d1d07e2009-09-28 15:32:55 +0200494{
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300495 struct rb_root *root;
John Kacur3d1d07e2009-09-28 15:32:55 +0200496 struct rb_node *next;
497 struct hist_entry *n;
John Kacur3d1d07e2009-09-28 15:32:55 +0200498 u64 min_callchain_hits;
499
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300500 min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100);
John Kacur3d1d07e2009-09-28 15:32:55 +0200501
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300502 if (sort__need_collapse || threaded)
503 root = &hists->entries_collapsed;
504 else
505 root = hists->entries_in;
506
507 next = rb_first(root);
508 hists->entries = RB_ROOT;
John Kacur3d1d07e2009-09-28 15:32:55 +0200509
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300510 hists->nr_entries = 0;
Arnaldo Carvalho de Melo79286312011-10-27 09:19:48 -0200511 hists->stats.total_period = 0;
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300512 hists__reset_col_len(hists);
Arnaldo Carvalho de Melofefb0b92010-05-10 13:57:51 -0300513
John Kacur3d1d07e2009-09-28 15:32:55 +0200514 while (next) {
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300515 n = rb_entry(next, struct hist_entry, rb_node_in);
516 next = rb_next(&n->rb_node_in);
John Kacur3d1d07e2009-09-28 15:32:55 +0200517
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300518 __hists__insert_output_entry(&hists->entries, n, min_callchain_hits);
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300519 hists__inc_nr_entries(hists, n);
John Kacur3d1d07e2009-09-28 15:32:55 +0200520 }
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300521}
Arnaldo Carvalho de Melob9bf0892009-12-14 11:37:11 -0200522
Arnaldo Carvalho de Melo1980c2eb2011-10-05 17:50:23 -0300523void hists__output_resort(struct hists *hists)
524{
525 return __hists__output_resort(hists, false);
526}
527
528void hists__output_resort_threaded(struct hists *hists)
529{
530 return __hists__output_resort(hists, true);
John Kacur3d1d07e2009-09-28 15:32:55 +0200531}
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200532
533static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
534{
535 int i;
536 int ret = fprintf(fp, " ");
537
538 for (i = 0; i < left_margin; i++)
539 ret += fprintf(fp, " ");
540
541 return ret;
542}
543
544static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
545 int left_margin)
546{
547 int i;
548 size_t ret = callchain__fprintf_left_margin(fp, left_margin);
549
550 for (i = 0; i < depth; i++)
551 if (depth_mask & (1 << i))
552 ret += fprintf(fp, "| ");
553 else
554 ret += fprintf(fp, " ");
555
556 ret += fprintf(fp, "\n");
557
558 return ret;
559}
560
561static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300562 int depth, int depth_mask, int period,
Frederic Weisbeckerd425de52011-01-03 16:13:11 +0100563 u64 total_samples, u64 hits,
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200564 int left_margin)
565{
566 int i;
567 size_t ret = 0;
568
569 ret += callchain__fprintf_left_margin(fp, left_margin);
570 for (i = 0; i < depth; i++) {
571 if (depth_mask & (1 << i))
572 ret += fprintf(fp, "|");
573 else
574 ret += fprintf(fp, " ");
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300575 if (!period && i == depth - 1) {
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200576 double percent;
577
578 percent = hits * 100.0 / total_samples;
579 ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
580 } else
581 ret += fprintf(fp, "%s", " ");
582 }
Arnaldo Carvalho de Melob3c9ac02010-03-24 16:40:18 -0300583 if (chain->ms.sym)
584 ret += fprintf(fp, "%s\n", chain->ms.sym->name);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200585 else
586 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
587
588 return ret;
589}
590
591static struct symbol *rem_sq_bracket;
592static struct callchain_list rem_hits;
593
594static void init_rem_hits(void)
595{
596 rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
597 if (!rem_sq_bracket) {
598 fprintf(stderr, "Not enough memory to display remaining hits\n");
599 return;
600 }
601
602 strcpy(rem_sq_bracket->name, "[...]");
Arnaldo Carvalho de Melob3c9ac02010-03-24 16:40:18 -0300603 rem_hits.ms.sym = rem_sq_bracket;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200604}
605
606static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
607 u64 total_samples, int depth,
608 int depth_mask, int left_margin)
609{
610 struct rb_node *node, *next;
611 struct callchain_node *child;
612 struct callchain_list *chain;
613 int new_depth_mask = depth_mask;
614 u64 new_total;
615 u64 remaining;
616 size_t ret = 0;
617 int i;
Arnaldo Carvalho de Melo232a5c92010-05-09 20:28:10 -0300618 uint entries_printed = 0;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200619
620 if (callchain_param.mode == CHAIN_GRAPH_REL)
621 new_total = self->children_hit;
622 else
623 new_total = total_samples;
624
625 remaining = new_total;
626
627 node = rb_first(&self->rb_root);
628 while (node) {
629 u64 cumul;
630
631 child = rb_entry(node, struct callchain_node, rb_node);
Frederic Weisbeckerf08c3152011-01-14 04:51:59 +0100632 cumul = callchain_cumul_hits(child);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200633 remaining -= cumul;
634
635 /*
636 * The depth mask manages the output of pipes that show
637 * the depth. We don't want to keep the pipes of the current
638 * level for the last child of this depth.
639 * Except if we have remaining filtered hits. They will
640 * supersede the last child
641 */
642 next = rb_next(node);
643 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
644 new_depth_mask &= ~(1 << (depth - 1));
645
646 /*
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800647 * But we keep the older depth mask for the line separator
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200648 * to keep the level link until we reach the last child
649 */
650 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
651 left_margin);
652 i = 0;
653 list_for_each_entry(chain, &child->val, list) {
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200654 ret += ipchain__fprintf_graph(fp, chain, depth,
655 new_depth_mask, i++,
656 new_total,
657 cumul,
658 left_margin);
659 }
660 ret += __callchain__fprintf_graph(fp, child, new_total,
661 depth + 1,
662 new_depth_mask | (1 << depth),
663 left_margin);
664 node = next;
Arnaldo Carvalho de Melo232a5c92010-05-09 20:28:10 -0300665 if (++entries_printed == callchain_param.print_limit)
666 break;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200667 }
668
669 if (callchain_param.mode == CHAIN_GRAPH_REL &&
670 remaining && remaining != new_total) {
671
672 if (!rem_sq_bracket)
673 return ret;
674
675 new_depth_mask &= ~(1 << (depth - 1));
676
677 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
678 new_depth_mask, 0, new_total,
679 remaining, left_margin);
680 }
681
682 return ret;
683}
684
685static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
686 u64 total_samples, int left_margin)
687{
688 struct callchain_list *chain;
689 bool printed = false;
690 int i = 0;
691 int ret = 0;
Arnaldo Carvalho de Melo232a5c92010-05-09 20:28:10 -0300692 u32 entries_printed = 0;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200693
694 list_for_each_entry(chain, &self->val, list) {
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200695 if (!i++ && sort__first_dimension == SORT_SYM)
696 continue;
697
698 if (!printed) {
699 ret += callchain__fprintf_left_margin(fp, left_margin);
700 ret += fprintf(fp, "|\n");
701 ret += callchain__fprintf_left_margin(fp, left_margin);
702 ret += fprintf(fp, "---");
703
704 left_margin += 3;
705 printed = true;
706 } else
707 ret += callchain__fprintf_left_margin(fp, left_margin);
708
Arnaldo Carvalho de Melob3c9ac02010-03-24 16:40:18 -0300709 if (chain->ms.sym)
710 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200711 else
712 ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
Arnaldo Carvalho de Melo232a5c92010-05-09 20:28:10 -0300713
714 if (++entries_printed == callchain_param.print_limit)
715 break;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200716 }
717
718 ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
719
720 return ret;
721}
722
723static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
724 u64 total_samples)
725{
726 struct callchain_list *chain;
727 size_t ret = 0;
728
729 if (!self)
730 return 0;
731
732 ret += callchain__fprintf_flat(fp, self->parent, total_samples);
733
734
735 list_for_each_entry(chain, &self->val, list) {
736 if (chain->ip >= PERF_CONTEXT_MAX)
737 continue;
Arnaldo Carvalho de Melob3c9ac02010-03-24 16:40:18 -0300738 if (chain->ms.sym)
739 ret += fprintf(fp, " %s\n", chain->ms.sym->name);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200740 else
741 ret += fprintf(fp, " %p\n",
742 (void *)(long)chain->ip);
743 }
744
745 return ret;
746}
747
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200748static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
749 u64 total_samples, int left_margin,
750 FILE *fp)
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200751{
752 struct rb_node *rb_node;
753 struct callchain_node *chain;
754 size_t ret = 0;
Arnaldo Carvalho de Melo232a5c92010-05-09 20:28:10 -0300755 u32 entries_printed = 0;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200756
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200757 rb_node = rb_first(&he->sorted_chain);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200758 while (rb_node) {
759 double percent;
760
761 chain = rb_entry(rb_node, struct callchain_node, rb_node);
762 percent = chain->hit * 100.0 / total_samples;
763 switch (callchain_param.mode) {
764 case CHAIN_FLAT:
765 ret += percent_color_fprintf(fp, " %6.2f%%\n",
766 percent);
767 ret += callchain__fprintf_flat(fp, chain, total_samples);
768 break;
769 case CHAIN_GRAPH_ABS: /* Falldown */
770 case CHAIN_GRAPH_REL:
771 ret += callchain__fprintf_graph(fp, chain, total_samples,
772 left_margin);
773 case CHAIN_NONE:
774 default:
775 break;
776 }
777 ret += fprintf(fp, "\n");
Arnaldo Carvalho de Melo232a5c92010-05-09 20:28:10 -0300778 if (++entries_printed == callchain_param.print_limit)
779 break;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200780 rb_node = rb_next(rb_node);
781 }
782
783 return ret;
784}
785
Arnaldo Carvalho de Meloab81f3fd2011-10-05 19:16:15 -0300786void hists__output_recalc_col_len(struct hists *hists, int max_rows)
787{
788 struct rb_node *next = rb_first(&hists->entries);
789 struct hist_entry *n;
790 int row = 0;
791
792 hists__reset_col_len(hists);
793
794 while (next && row++ < max_rows) {
795 n = rb_entry(next, struct hist_entry, rb_node);
Arnaldo Carvalho de Melod197fd52011-10-20 07:35:45 -0200796 if (!n->filtered)
797 hists__calc_col_len(hists, n);
Arnaldo Carvalho de Meloab81f3fd2011-10-05 19:16:15 -0300798 next = rb_next(&n->rb_node);
799 }
800}
801
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200802static int hist_entry__pcnt_snprintf(struct hist_entry *he, char *s,
Arnaldo Carvalho de Melof1cf6022011-10-18 14:37:34 -0200803 size_t size, struct hists *pair_hists,
804 bool show_displacement, long displacement,
Arnaldo Carvalho de Melo13d3ee52012-01-04 11:37:15 -0200805 bool color, u64 total_period)
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200806{
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300807 u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us;
Arnaldo Carvalho de Melofec9cbd2011-02-17 10:37:23 -0200808 u64 nr_events;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200809 const char *sep = symbol_conf.field_sep;
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300810 int ret;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200811
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200812 if (symbol_conf.exclude_other && !he->parent)
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200813 return 0;
814
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300815 if (pair_hists) {
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200816 period = he->pair ? he->pair->period : 0;
817 nr_events = he->pair ? he->pair->nr_events : 0;
Arnaldo Carvalho de Melocee75ac2010-05-14 13:16:55 -0300818 total = pair_hists->stats.total_period;
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200819 period_sys = he->pair ? he->pair->period_sys : 0;
820 period_us = he->pair ? he->pair->period_us : 0;
821 period_guest_sys = he->pair ? he->pair->period_guest_sys : 0;
822 period_guest_us = he->pair ? he->pair->period_guest_us : 0;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200823 } else {
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200824 period = he->period;
825 nr_events = he->nr_events;
Arnaldo Carvalho de Melo13d3ee52012-01-04 11:37:15 -0200826 total = total_period;
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200827 period_sys = he->period_sys;
828 period_us = he->period_us;
829 period_guest_sys = he->period_guest_sys;
830 period_guest_us = he->period_guest_us;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200831 }
832
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300833 if (total) {
834 if (color)
835 ret = percent_color_snprintf(s, size,
836 sep ? "%.2f" : " %6.2f%%",
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300837 (period * 100.0) / total);
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300838 else
839 ret = snprintf(s, size, sep ? "%.2f" : " %6.2f%%",
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300840 (period * 100.0) / total);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800841 if (symbol_conf.show_cpu_utilization) {
842 ret += percent_color_snprintf(s + ret, size - ret,
843 sep ? "%.2f" : " %6.2f%%",
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300844 (period_sys * 100.0) / total);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800845 ret += percent_color_snprintf(s + ret, size - ret,
846 sep ? "%.2f" : " %6.2f%%",
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300847 (period_us * 100.0) / total);
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800848 if (perf_guest) {
849 ret += percent_color_snprintf(s + ret,
850 size - ret,
851 sep ? "%.2f" : " %6.2f%%",
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300852 (period_guest_sys * 100.0) /
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800853 total);
854 ret += percent_color_snprintf(s + ret,
855 size - ret,
856 sep ? "%.2f" : " %6.2f%%",
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300857 (period_guest_us * 100.0) /
Zhang, Yanmina1645ce2010-04-19 13:32:50 +0800858 total);
859 }
860 }
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300861 } else
Arnaldo Carvalho de Melo9486aa32011-01-22 20:37:02 -0200862 ret = snprintf(s, size, sep ? "%" PRIu64 : "%12" PRIu64 " ", period);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200863
864 if (symbol_conf.show_nr_samples) {
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200865 if (sep)
Arnaldo Carvalho de Melofec9cbd2011-02-17 10:37:23 -0200866 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, nr_events);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200867 else
Arnaldo Carvalho de Melofec9cbd2011-02-17 10:37:23 -0200868 ret += snprintf(s + ret, size - ret, "%11" PRIu64, nr_events);
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200869 }
870
Arnaldo Carvalho de Melo3f2728b2011-10-05 16:10:06 -0300871 if (symbol_conf.show_total_period) {
872 if (sep)
873 ret += snprintf(s + ret, size - ret, "%c%" PRIu64, *sep, period);
874 else
875 ret += snprintf(s + ret, size - ret, " %12" PRIu64, period);
876 }
877
Arnaldo Carvalho de Melo1c02c4d2010-05-10 13:04:11 -0300878 if (pair_hists) {
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200879 char bf[32];
880 double old_percent = 0, new_percent = 0, diff;
881
882 if (total > 0)
Arnaldo Carvalho de Meloc82ee822010-05-14 14:19:35 -0300883 old_percent = (period * 100.0) / total;
Arnaldo Carvalho de Melo13d3ee52012-01-04 11:37:15 -0200884 if (total_period > 0)
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200885 new_percent = (he->period * 100.0) / total_period;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200886
Arnaldo Carvalho de Melo9b338272009-12-16 14:31:49 -0200887 diff = new_percent - old_percent;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200888
Arnaldo Carvalho de Melo9b338272009-12-16 14:31:49 -0200889 if (fabs(diff) >= 0.01)
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200890 snprintf(bf, sizeof(bf), "%+4.2F%%", diff);
891 else
892 snprintf(bf, sizeof(bf), " ");
893
894 if (sep)
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300895 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200896 else
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300897 ret += snprintf(s + ret, size - ret, "%11.11s", bf);
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200898
899 if (show_displacement) {
900 if (displacement)
901 snprintf(bf, sizeof(bf), "%+4ld", displacement);
902 else
903 snprintf(bf, sizeof(bf), " ");
904
905 if (sep)
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300906 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200907 else
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300908 ret += snprintf(s + ret, size - ret, "%6.6s", bf);
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200909 }
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200910 }
911
Arnaldo Carvalho de Melof1cf6022011-10-18 14:37:34 -0200912 return ret;
913}
914
915int hist_entry__snprintf(struct hist_entry *he, char *s, size_t size,
916 struct hists *hists)
917{
918 const char *sep = symbol_conf.field_sep;
919 struct sort_entry *se;
920 int ret = 0;
921
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200922 list_for_each_entry(se, &hist_entry__sort_list, list) {
923 if (se->elide)
924 continue;
925
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300926 ret += snprintf(s + ret, size - ret, "%s", sep ?: " ");
Arnaldo Carvalho de Melof1cf6022011-10-18 14:37:34 -0200927 ret += se->se_snprintf(he, s + ret, size - ret,
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300928 hists__col_len(hists, se->se_width_idx));
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200929 }
930
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300931 return ret;
932}
933
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200934static int hist_entry__fprintf(struct hist_entry *he, size_t size,
935 struct hists *hists, struct hists *pair_hists,
936 bool show_displacement, long displacement,
937 u64 total_period, FILE *fp)
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300938{
939 char bf[512];
Arnaldo Carvalho de Melof1cf6022011-10-18 14:37:34 -0200940 int ret;
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -0300941
942 if (size == 0 || size > sizeof(bf))
943 size = sizeof(bf);
944
Arnaldo Carvalho de Melof1cf6022011-10-18 14:37:34 -0200945 ret = hist_entry__pcnt_snprintf(he, bf, size, pair_hists,
946 show_displacement, displacement,
Arnaldo Carvalho de Melo13d3ee52012-01-04 11:37:15 -0200947 true, total_period);
Arnaldo Carvalho de Melof1cf6022011-10-18 14:37:34 -0200948 hist_entry__snprintf(he, bf + ret, size - ret, hists);
Arnaldo Carvalho de Meloa4e3b952010-03-31 11:33:40 -0300949 return fprintf(fp, "%s\n", bf);
Arnaldo Carvalho de Melo3997d372010-03-12 12:46:48 -0300950}
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200951
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200952static size_t hist_entry__fprintf_callchain(struct hist_entry *he,
953 struct hists *hists,
954 u64 total_period, FILE *fp)
Arnaldo Carvalho de Melo3997d372010-03-12 12:46:48 -0300955{
956 int left_margin = 0;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200957
Arnaldo Carvalho de Melo3997d372010-03-12 12:46:48 -0300958 if (sort__first_dimension == SORT_COMM) {
959 struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
960 typeof(*se), list);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -0300961 left_margin = hists__col_len(hists, se->se_width_idx);
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200962 left_margin -= thread__comm_len(he->thread);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200963 }
964
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200965 return hist_entry_callchain__fprintf(he, total_period, left_margin, fp);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200966}
967
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -0300968size_t hists__fprintf(struct hists *hists, struct hists *pair,
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -0300969 bool show_displacement, bool show_header, int max_rows,
970 int max_cols, FILE *fp)
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200971{
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200972 struct sort_entry *se;
973 struct rb_node *nd;
974 size_t ret = 0;
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -0200975 u64 total_period;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200976 unsigned long position = 1;
977 long displacement = 0;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200978 unsigned int width;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200979 const char *sep = symbol_conf.field_sep;
Arnaldo Carvalho de Meloedb7c602010-05-17 16:22:41 -0300980 const char *col_width = symbol_conf.col_width_list_str;
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -0300981 int nr_rows = 0;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -0200982
983 init_rem_hits();
984
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -0300985 if (!show_header)
986 goto print_entries;
987
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -0200988 fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
989
Namhyung Kim0ed35abc2012-01-08 02:25:32 +0900990 if (symbol_conf.show_cpu_utilization) {
991 if (sep) {
992 ret += fprintf(fp, "%csys", *sep);
993 ret += fprintf(fp, "%cus", *sep);
994 if (perf_guest) {
995 ret += fprintf(fp, "%cguest sys", *sep);
996 ret += fprintf(fp, "%cguest us", *sep);
997 }
998 } else {
999 ret += fprintf(fp, " sys ");
1000 ret += fprintf(fp, " us ");
1001 if (perf_guest) {
1002 ret += fprintf(fp, " guest sys ");
1003 ret += fprintf(fp, " guest us ");
1004 }
1005 }
1006 }
1007
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001008 if (symbol_conf.show_nr_samples) {
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -02001009 if (sep)
1010 fprintf(fp, "%cSamples", *sep);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001011 else
1012 fputs(" Samples ", fp);
1013 }
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -02001014
Arnaldo Carvalho de Melo3f2728b2011-10-05 16:10:06 -03001015 if (symbol_conf.show_total_period) {
1016 if (sep)
1017 ret += fprintf(fp, "%cPeriod", *sep);
1018 else
1019 ret += fprintf(fp, " Period ");
1020 }
1021
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -02001022 if (pair) {
1023 if (sep)
1024 ret += fprintf(fp, "%cDelta", *sep);
1025 else
1026 ret += fprintf(fp, " Delta ");
1027
1028 if (show_displacement) {
1029 if (sep)
1030 ret += fprintf(fp, "%cDisplacement", *sep);
1031 else
1032 ret += fprintf(fp, " Displ");
1033 }
1034 }
1035
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001036 list_for_each_entry(se, &hist_entry__sort_list, list) {
1037 if (se->elide)
1038 continue;
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -02001039 if (sep) {
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +02001040 fprintf(fp, "%c%s", *sep, se->se_header);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001041 continue;
1042 }
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +02001043 width = strlen(se->se_header);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -03001044 if (symbol_conf.col_width_list_str) {
1045 if (col_width) {
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001046 hists__set_col_len(hists, se->se_width_idx,
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -03001047 atoi(col_width));
1048 col_width = strchr(col_width, ',');
1049 if (col_width)
1050 ++col_width;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001051 }
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001052 }
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001053 if (!hists__new_col_len(hists, se->se_width_idx, width))
1054 width = hists__col_len(hists, se->se_width_idx);
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +02001055 fprintf(fp, " %*s", width, se->se_header);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001056 }
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -03001057
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001058 fprintf(fp, "\n");
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -03001059 if (max_rows && ++nr_rows >= max_rows)
1060 goto out;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001061
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -02001062 if (sep)
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001063 goto print_entries;
1064
1065 fprintf(fp, "# ........");
Namhyung Kim0ed35abc2012-01-08 02:25:32 +09001066 if (symbol_conf.show_cpu_utilization)
1067 fprintf(fp, " ....... .......");
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001068 if (symbol_conf.show_nr_samples)
1069 fprintf(fp, " ..........");
Arnaldo Carvalho de Melo3f2728b2011-10-05 16:10:06 -03001070 if (symbol_conf.show_total_period)
1071 fprintf(fp, " ............");
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -02001072 if (pair) {
1073 fprintf(fp, " ..........");
1074 if (show_displacement)
1075 fprintf(fp, " .....");
1076 }
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001077 list_for_each_entry(se, &hist_entry__sort_list, list) {
1078 unsigned int i;
1079
1080 if (se->elide)
1081 continue;
1082
1083 fprintf(fp, " ");
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001084 width = hists__col_len(hists, se->se_width_idx);
Arnaldo Carvalho de Melo8a6c5b22010-07-20 14:42:52 -03001085 if (width == 0)
Frederic Weisbeckerfcd14982010-04-14 19:11:29 +02001086 width = strlen(se->se_header);
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001087 for (i = 0; i < width; i++)
1088 fprintf(fp, ".");
1089 }
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001090
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -03001091 fprintf(fp, "\n");
1092 if (max_rows && ++nr_rows >= max_rows)
1093 goto out;
1094
1095 fprintf(fp, "#\n");
1096 if (max_rows && ++nr_rows >= max_rows)
1097 goto out;
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001098
1099print_entries:
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -02001100 total_period = hists->stats.total_period;
1101
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001102 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -02001103 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1104
Frederic Weisbeckere84d2122011-06-29 22:23:03 +02001105 if (h->filtered)
1106 continue;
1107
Arnaldo Carvalho de Meloc351c282009-12-16 13:49:27 -02001108 if (show_displacement) {
1109 if (h->pair != NULL)
1110 displacement = ((long)h->pair->position -
1111 (long)position);
1112 else
1113 displacement = 0;
1114 ++position;
1115 }
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -03001116 ret += hist_entry__fprintf(h, max_cols, hists, pair, show_displacement,
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -02001117 displacement, total_period, fp);
Arnaldo Carvalho de Melo3997d372010-03-12 12:46:48 -03001118
1119 if (symbol_conf.use_callchain)
Arnaldo Carvalho de Melo12c14272012-01-04 12:27:03 -02001120 ret += hist_entry__fprintf_callchain(h, hists, total_period, fp);
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -03001121 if (max_rows && ++nr_rows >= max_rows)
1122 goto out;
1123
Arnaldo Carvalho de Melo59fd5302010-03-24 16:40:17 -03001124 if (h->ms.map == NULL && verbose > 1) {
Arnaldo Carvalho de Melo65f2ed22010-03-09 15:58:17 -03001125 __map_groups__fprintf_maps(&h->thread->mg,
Arnaldo Carvalho de Meloc6e718f2010-03-26 12:11:06 -03001126 MAP__FUNCTION, verbose, fp);
Arnaldo Carvalho de Melo65f2ed22010-03-09 15:58:17 -03001127 fprintf(fp, "%.10s end\n", graph_dotted_line);
1128 }
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001129 }
Arnaldo Carvalho de Meloef9dfe62011-09-26 12:46:11 -03001130out:
Arnaldo Carvalho de Melo4ecf84d02009-12-16 12:27:09 -02001131 free(rem_sq_bracket);
1132
1133 return ret;
1134}
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001135
Arnaldo Carvalho de Melo06daaab2010-07-21 17:58:25 -03001136/*
1137 * See hists__fprintf to match the column widths
1138 */
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001139unsigned int hists__sort_list_width(struct hists *hists)
Arnaldo Carvalho de Melo06daaab2010-07-21 17:58:25 -03001140{
1141 struct sort_entry *se;
1142 int ret = 9; /* total % */
1143
1144 if (symbol_conf.show_cpu_utilization) {
1145 ret += 7; /* count_sys % */
1146 ret += 6; /* count_us % */
1147 if (perf_guest) {
1148 ret += 13; /* count_guest_sys % */
1149 ret += 12; /* count_guest_us % */
1150 }
1151 }
1152
1153 if (symbol_conf.show_nr_samples)
1154 ret += 11;
1155
Arnaldo Carvalho de Melo3f2728b2011-10-05 16:10:06 -03001156 if (symbol_conf.show_total_period)
1157 ret += 13;
1158
Arnaldo Carvalho de Melo06daaab2010-07-21 17:58:25 -03001159 list_for_each_entry(se, &hist_entry__sort_list, list)
1160 if (!se->elide)
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001161 ret += 2 + hists__col_len(hists, se->se_width_idx);
Arnaldo Carvalho de Melo06daaab2010-07-21 17:58:25 -03001162
Arnaldo Carvalho de Melo903cce62010-08-05 19:15:48 -03001163 if (verbose) /* Addr + origin */
1164 ret += 3 + BITS_PER_LONG / 4;
1165
Arnaldo Carvalho de Melo06daaab2010-07-21 17:58:25 -03001166 return ret;
1167}
1168
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001169static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h,
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -03001170 enum hist_filter filter)
1171{
1172 h->filtered &= ~(1 << filter);
1173 if (h->filtered)
1174 return;
1175
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001176 ++hists->nr_entries;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -03001177 if (h->ms.unfolded)
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001178 hists->nr_entries += h->nr_rows;
Arnaldo Carvalho de Melo0f0cbf72010-07-26 17:13:40 -03001179 h->row_offset = 0;
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001180 hists->stats.total_period += h->period;
1181 hists->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events;
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -03001182
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001183 hists__calc_col_len(hists, h);
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -03001184}
1185
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -02001186
1187static bool hists__filter_entry_by_dso(struct hists *hists,
1188 struct hist_entry *he)
1189{
1190 if (hists->dso_filter != NULL &&
1191 (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) {
1192 he->filtered |= (1 << HIST_FILTER__DSO);
1193 return true;
1194 }
1195
1196 return false;
1197}
1198
Arnaldo Carvalho de Melod7b76f02011-10-18 19:07:34 -02001199void hists__filter_by_dso(struct hists *hists)
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001200{
1201 struct rb_node *nd;
1202
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001203 hists->nr_entries = hists->stats.total_period = 0;
1204 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
1205 hists__reset_col_len(hists);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001206
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001207 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001208 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1209
1210 if (symbol_conf.exclude_other && !h->parent)
1211 continue;
1212
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -02001213 if (hists__filter_entry_by_dso(hists, h))
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001214 continue;
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001215
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001216 hists__remove_entry_filter(hists, h, HIST_FILTER__DSO);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001217 }
1218}
1219
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -02001220static bool hists__filter_entry_by_thread(struct hists *hists,
1221 struct hist_entry *he)
1222{
1223 if (hists->thread_filter != NULL &&
1224 he->thread != hists->thread_filter) {
1225 he->filtered |= (1 << HIST_FILTER__THREAD);
1226 return true;
1227 }
1228
1229 return false;
1230}
1231
Arnaldo Carvalho de Melod7b76f02011-10-18 19:07:34 -02001232void hists__filter_by_thread(struct hists *hists)
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001233{
1234 struct rb_node *nd;
1235
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001236 hists->nr_entries = hists->stats.total_period = 0;
1237 hists->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
1238 hists__reset_col_len(hists);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001239
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001240 for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001241 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
1242
Arnaldo Carvalho de Melo90cf1fb2011-10-19 13:09:10 -02001243 if (hists__filter_entry_by_thread(hists, h))
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001244 continue;
Arnaldo Carvalho de Melocc5edb02010-07-16 12:35:07 -03001245
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001246 hists__remove_entry_filter(hists, h, HIST_FILTER__THREAD);
Arnaldo Carvalho de Melob09e0192010-05-11 11:10:15 -03001247 }
1248}
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -03001249
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -02001250int hist_entry__inc_addr_samples(struct hist_entry *he, int evidx, u64 ip)
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -03001251{
Arnaldo Carvalho de Melo2f525d02011-02-04 13:43:24 -02001252 return symbol__inc_addr_samples(he->ms.sym, he->ms.map, evidx, ip);
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -03001253}
1254
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -02001255int hist_entry__annotate(struct hist_entry *he, size_t privsize)
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -03001256{
Arnaldo Carvalho de Meloce6f4fa2011-02-08 13:27:39 -02001257 return symbol__annotate(he->ms.sym, he->ms.map, privsize);
Arnaldo Carvalho de Meloef7b93a2010-05-11 23:18:06 -03001258}
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -03001259
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001260void hists__inc_nr_events(struct hists *hists, u32 type)
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -03001261{
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001262 ++hists->stats.nr_events[0];
1263 ++hists->stats.nr_events[type];
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -03001264}
1265
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001266size_t hists__fprintf_nr_events(struct hists *hists, FILE *fp)
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -03001267{
1268 int i;
1269 size_t ret = 0;
1270
1271 for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -03001272 const char *name;
Thomas Gleixner3835bc02010-12-07 12:48:42 +00001273
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001274 if (hists->stats.nr_events[i] == 0)
Arnaldo Carvalho de Meloe248de32011-03-05 21:40:06 -03001275 continue;
1276
1277 name = perf_event__name(i);
Thomas Gleixner3835bc02010-12-07 12:48:42 +00001278 if (!strcmp(name, "UNKNOWN"))
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -03001279 continue;
Thomas Gleixner3835bc02010-12-07 12:48:42 +00001280
1281 ret += fprintf(fp, "%16s events: %10d\n", name,
Arnaldo Carvalho de Melo42b28ac2011-09-26 12:33:28 -03001282 hists->stats.nr_events[i]);
Arnaldo Carvalho de Meloc8446b92010-05-14 10:36:42 -03001283 }
1284
1285 return ret;
1286}