Commit | Line | Data |
---|---|---|
8a0ecfb8 | 1 | #include "util.h" |
598357eb | 2 | #include "build-id.h" |
3d1d07ec | 3 | #include "hist.h" |
4e4f06e4 ACM |
4 | #include "session.h" |
5 | #include "sort.h" | |
2a1731fb | 6 | #include "evlist.h" |
29d720ed | 7 | #include "evsel.h" |
69bcb019 | 8 | #include "annotate.h" |
740b97f9 | 9 | #include "ui/progress.h" |
9b33827d | 10 | #include <math.h> |
3d1d07ec | 11 | |
90cf1fb5 ACM |
12 | static bool hists__filter_entry_by_dso(struct hists *hists, |
13 | struct hist_entry *he); | |
14 | static bool hists__filter_entry_by_thread(struct hists *hists, | |
15 | struct hist_entry *he); | |
e94d53eb NK |
16 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
17 | struct hist_entry *he); | |
21394d94 KL |
18 | static bool hists__filter_entry_by_socket(struct hists *hists, |
19 | struct hist_entry *he); | |
90cf1fb5 | 20 | |
42b28ac0 | 21 | u16 hists__col_len(struct hists *hists, enum hist_column col) |
8a6c5b26 | 22 | { |
42b28ac0 | 23 | return hists->col_len[col]; |
8a6c5b26 ACM |
24 | } |
25 | ||
42b28ac0 | 26 | void hists__set_col_len(struct hists *hists, enum hist_column col, u16 len) |
8a6c5b26 | 27 | { |
42b28ac0 | 28 | hists->col_len[col] = len; |
8a6c5b26 ACM |
29 | } |
30 | ||
42b28ac0 | 31 | bool hists__new_col_len(struct hists *hists, enum hist_column col, u16 len) |
8a6c5b26 | 32 | { |
42b28ac0 ACM |
33 | if (len > hists__col_len(hists, col)) { |
34 | hists__set_col_len(hists, col, len); | |
8a6c5b26 ACM |
35 | return true; |
36 | } | |
37 | return false; | |
38 | } | |
39 | ||
7ccf4f90 | 40 | void hists__reset_col_len(struct hists *hists) |
8a6c5b26 ACM |
41 | { |
42 | enum hist_column col; | |
43 | ||
44 | for (col = 0; col < HISTC_NR_COLS; ++col) | |
42b28ac0 | 45 | hists__set_col_len(hists, col, 0); |
8a6c5b26 ACM |
46 | } |
47 | ||
b5387528 RAV |
48 | static void hists__set_unres_dso_col_len(struct hists *hists, int dso) |
49 | { | |
50 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; | |
51 | ||
52 | if (hists__col_len(hists, dso) < unresolved_col_width && | |
53 | !symbol_conf.col_width_list_str && !symbol_conf.field_sep && | |
54 | !symbol_conf.dso_list) | |
55 | hists__set_col_len(hists, dso, unresolved_col_width); | |
56 | } | |
57 | ||
7ccf4f90 | 58 | void hists__calc_col_len(struct hists *hists, struct hist_entry *h) |
8a6c5b26 | 59 | { |
b5387528 | 60 | const unsigned int unresolved_col_width = BITS_PER_LONG / 4; |
98a3b32c | 61 | int symlen; |
8a6c5b26 ACM |
62 | u16 len; |
63 | ||
ded19d57 NK |
64 | /* |
65 | * +4 accounts for '[x] ' priv level info | |
66 | * +2 accounts for 0x prefix on raw addresses | |
67 | * +3 accounts for ' y ' symtab origin info | |
68 | */ | |
69 | if (h->ms.sym) { | |
70 | symlen = h->ms.sym->namelen + 4; | |
71 | if (verbose) | |
72 | symlen += BITS_PER_LONG / 4 + 2 + 3; | |
73 | hists__new_col_len(hists, HISTC_SYMBOL, symlen); | |
74 | } else { | |
98a3b32c SE |
75 | symlen = unresolved_col_width + 4 + 2; |
76 | hists__new_col_len(hists, HISTC_SYMBOL, symlen); | |
b5387528 | 77 | hists__set_unres_dso_col_len(hists, HISTC_DSO); |
98a3b32c | 78 | } |
8a6c5b26 ACM |
79 | |
80 | len = thread__comm_len(h->thread); | |
42b28ac0 ACM |
81 | if (hists__new_col_len(hists, HISTC_COMM, len)) |
82 | hists__set_col_len(hists, HISTC_THREAD, len + 6); | |
8a6c5b26 ACM |
83 | |
84 | if (h->ms.map) { | |
85 | len = dso__name_len(h->ms.map->dso); | |
42b28ac0 | 86 | hists__new_col_len(hists, HISTC_DSO, len); |
8a6c5b26 | 87 | } |
b5387528 | 88 | |
cb993744 NK |
89 | if (h->parent) |
90 | hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen); | |
91 | ||
b5387528 | 92 | if (h->branch_info) { |
b5387528 RAV |
93 | if (h->branch_info->from.sym) { |
94 | symlen = (int)h->branch_info->from.sym->namelen + 4; | |
ded19d57 NK |
95 | if (verbose) |
96 | symlen += BITS_PER_LONG / 4 + 2 + 3; | |
b5387528 RAV |
97 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); |
98 | ||
99 | symlen = dso__name_len(h->branch_info->from.map->dso); | |
100 | hists__new_col_len(hists, HISTC_DSO_FROM, symlen); | |
101 | } else { | |
102 | symlen = unresolved_col_width + 4 + 2; | |
103 | hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen); | |
104 | hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM); | |
105 | } | |
106 | ||
107 | if (h->branch_info->to.sym) { | |
108 | symlen = (int)h->branch_info->to.sym->namelen + 4; | |
ded19d57 NK |
109 | if (verbose) |
110 | symlen += BITS_PER_LONG / 4 + 2 + 3; | |
b5387528 RAV |
111 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); |
112 | ||
113 | symlen = dso__name_len(h->branch_info->to.map->dso); | |
114 | hists__new_col_len(hists, HISTC_DSO_TO, symlen); | |
115 | } else { | |
116 | symlen = unresolved_col_width + 4 + 2; | |
117 | hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen); | |
118 | hists__set_unres_dso_col_len(hists, HISTC_DSO_TO); | |
119 | } | |
120 | } | |
98a3b32c SE |
121 | |
122 | if (h->mem_info) { | |
98a3b32c SE |
123 | if (h->mem_info->daddr.sym) { |
124 | symlen = (int)h->mem_info->daddr.sym->namelen + 4 | |
125 | + unresolved_col_width + 2; | |
126 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, | |
127 | symlen); | |
9b32ba71 DZ |
128 | hists__new_col_len(hists, HISTC_MEM_DCACHELINE, |
129 | symlen + 1); | |
98a3b32c SE |
130 | } else { |
131 | symlen = unresolved_col_width + 4 + 2; | |
132 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, | |
133 | symlen); | |
0805909f JO |
134 | hists__new_col_len(hists, HISTC_MEM_DCACHELINE, |
135 | symlen); | |
98a3b32c | 136 | } |
b34b3bf0 JO |
137 | |
138 | if (h->mem_info->iaddr.sym) { | |
139 | symlen = (int)h->mem_info->iaddr.sym->namelen + 4 | |
140 | + unresolved_col_width + 2; | |
141 | hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, | |
142 | symlen); | |
143 | } else { | |
144 | symlen = unresolved_col_width + 4 + 2; | |
145 | hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, | |
146 | symlen); | |
147 | } | |
148 | ||
98a3b32c SE |
149 | if (h->mem_info->daddr.map) { |
150 | symlen = dso__name_len(h->mem_info->daddr.map->dso); | |
151 | hists__new_col_len(hists, HISTC_MEM_DADDR_DSO, | |
152 | symlen); | |
153 | } else { | |
154 | symlen = unresolved_col_width + 4 + 2; | |
155 | hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); | |
156 | } | |
157 | } else { | |
158 | symlen = unresolved_col_width + 4 + 2; | |
159 | hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL, symlen); | |
b34b3bf0 | 160 | hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL, symlen); |
98a3b32c SE |
161 | hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO); |
162 | } | |
163 | ||
a4978eca | 164 | hists__new_col_len(hists, HISTC_CPU, 3); |
2e7ea3ab | 165 | hists__new_col_len(hists, HISTC_SOCKET, 6); |
98a3b32c SE |
166 | hists__new_col_len(hists, HISTC_MEM_LOCKED, 6); |
167 | hists__new_col_len(hists, HISTC_MEM_TLB, 22); | |
168 | hists__new_col_len(hists, HISTC_MEM_SNOOP, 12); | |
169 | hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3); | |
170 | hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12); | |
171 | hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12); | |
475eeab9 | 172 | |
e8e6d37e ACM |
173 | if (h->srcline) |
174 | hists__new_col_len(hists, HISTC_SRCLINE, strlen(h->srcline)); | |
175 | ||
31191a85 AK |
176 | if (h->srcfile) |
177 | hists__new_col_len(hists, HISTC_SRCFILE, strlen(h->srcfile)); | |
178 | ||
475eeab9 AK |
179 | if (h->transaction) |
180 | hists__new_col_len(hists, HISTC_TRANSACTION, | |
181 | hist_entry__transaction_len()); | |
8a6c5b26 ACM |
182 | } |
183 | ||
7ccf4f90 NK |
184 | void hists__output_recalc_col_len(struct hists *hists, int max_rows) |
185 | { | |
186 | struct rb_node *next = rb_first(&hists->entries); | |
187 | struct hist_entry *n; | |
188 | int row = 0; | |
189 | ||
190 | hists__reset_col_len(hists); | |
191 | ||
192 | while (next && row++ < max_rows) { | |
193 | n = rb_entry(next, struct hist_entry, rb_node); | |
194 | if (!n->filtered) | |
195 | hists__calc_col_len(hists, n); | |
196 | next = rb_next(&n->rb_node); | |
197 | } | |
198 | } | |
199 | ||
f39056f9 NK |
200 | static void he_stat__add_cpumode_period(struct he_stat *he_stat, |
201 | unsigned int cpumode, u64 period) | |
a1645ce1 | 202 | { |
28e2a106 | 203 | switch (cpumode) { |
a1645ce1 | 204 | case PERF_RECORD_MISC_KERNEL: |
f39056f9 | 205 | he_stat->period_sys += period; |
a1645ce1 ZY |
206 | break; |
207 | case PERF_RECORD_MISC_USER: | |
f39056f9 | 208 | he_stat->period_us += period; |
a1645ce1 ZY |
209 | break; |
210 | case PERF_RECORD_MISC_GUEST_KERNEL: | |
f39056f9 | 211 | he_stat->period_guest_sys += period; |
a1645ce1 ZY |
212 | break; |
213 | case PERF_RECORD_MISC_GUEST_USER: | |
f39056f9 | 214 | he_stat->period_guest_us += period; |
a1645ce1 ZY |
215 | break; |
216 | default: | |
217 | break; | |
218 | } | |
219 | } | |
220 | ||
05484298 AK |
221 | static void he_stat__add_period(struct he_stat *he_stat, u64 period, |
222 | u64 weight) | |
139c0815 | 223 | { |
98a3b32c | 224 | |
139c0815 | 225 | he_stat->period += period; |
05484298 | 226 | he_stat->weight += weight; |
139c0815 NK |
227 | he_stat->nr_events += 1; |
228 | } | |
229 | ||
230 | static void he_stat__add_stat(struct he_stat *dest, struct he_stat *src) | |
231 | { | |
232 | dest->period += src->period; | |
233 | dest->period_sys += src->period_sys; | |
234 | dest->period_us += src->period_us; | |
235 | dest->period_guest_sys += src->period_guest_sys; | |
236 | dest->period_guest_us += src->period_guest_us; | |
237 | dest->nr_events += src->nr_events; | |
05484298 | 238 | dest->weight += src->weight; |
139c0815 NK |
239 | } |
240 | ||
f39056f9 | 241 | static void he_stat__decay(struct he_stat *he_stat) |
ab81f3fd | 242 | { |
f39056f9 NK |
243 | he_stat->period = (he_stat->period * 7) / 8; |
244 | he_stat->nr_events = (he_stat->nr_events * 7) / 8; | |
05484298 | 245 | /* XXX need decay for weight too? */ |
ab81f3fd ACM |
246 | } |
247 | ||
248 | static bool hists__decay_entry(struct hists *hists, struct hist_entry *he) | |
249 | { | |
b24c28f7 | 250 | u64 prev_period = he->stat.period; |
3186b681 | 251 | u64 diff; |
c64550cf ACM |
252 | |
253 | if (prev_period == 0) | |
df71d95f | 254 | return true; |
c64550cf | 255 | |
f39056f9 | 256 | he_stat__decay(&he->stat); |
f8be1c8c NK |
257 | if (symbol_conf.cumulate_callchain) |
258 | he_stat__decay(he->stat_acc); | |
42b276a2 | 259 | decay_callchain(he->callchain); |
c64550cf | 260 | |
3186b681 NK |
261 | diff = prev_period - he->stat.period; |
262 | ||
263 | hists->stats.total_period -= diff; | |
c64550cf | 264 | if (!he->filtered) |
3186b681 | 265 | hists->stats.total_non_filtered_period -= diff; |
c64550cf | 266 | |
b24c28f7 | 267 | return he->stat.period == 0; |
ab81f3fd ACM |
268 | } |
269 | ||
956b65e1 ACM |
270 | static void hists__delete_entry(struct hists *hists, struct hist_entry *he) |
271 | { | |
272 | rb_erase(&he->rb_node, &hists->entries); | |
273 | ||
274 | if (sort__need_collapse) | |
275 | rb_erase(&he->rb_node_in, &hists->entries_collapsed); | |
61fa0e94 NK |
276 | else |
277 | rb_erase(&he->rb_node_in, hists->entries_in); | |
956b65e1 ACM |
278 | |
279 | --hists->nr_entries; | |
280 | if (!he->filtered) | |
281 | --hists->nr_non_filtered_entries; | |
282 | ||
283 | hist_entry__delete(he); | |
284 | } | |
285 | ||
3a5714f8 | 286 | void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel) |
ab81f3fd ACM |
287 | { |
288 | struct rb_node *next = rb_first(&hists->entries); | |
289 | struct hist_entry *n; | |
290 | ||
291 | while (next) { | |
292 | n = rb_entry(next, struct hist_entry, rb_node); | |
293 | next = rb_next(&n->rb_node); | |
b079d4e9 ACM |
294 | if (((zap_user && n->level == '.') || |
295 | (zap_kernel && n->level != '.') || | |
4c47f4fc | 296 | hists__decay_entry(hists, n))) { |
956b65e1 | 297 | hists__delete_entry(hists, n); |
ab81f3fd ACM |
298 | } |
299 | } | |
300 | } | |
301 | ||
701937bd NK |
302 | void hists__delete_entries(struct hists *hists) |
303 | { | |
304 | struct rb_node *next = rb_first(&hists->entries); | |
305 | struct hist_entry *n; | |
306 | ||
307 | while (next) { | |
308 | n = rb_entry(next, struct hist_entry, rb_node); | |
309 | next = rb_next(&n->rb_node); | |
310 | ||
956b65e1 | 311 | hists__delete_entry(hists, n); |
701937bd NK |
312 | } |
313 | } | |
314 | ||
3d1d07ec | 315 | /* |
c82ee828 | 316 | * histogram, sorted on item, collects periods |
3d1d07ec JK |
317 | */ |
318 | ||
a0b51af3 NK |
319 | static struct hist_entry *hist_entry__new(struct hist_entry *template, |
320 | bool sample_self) | |
28e2a106 | 321 | { |
f8be1c8c NK |
322 | size_t callchain_size = 0; |
323 | struct hist_entry *he; | |
324 | ||
82aa019e | 325 | if (symbol_conf.use_callchain) |
f8be1c8c NK |
326 | callchain_size = sizeof(struct callchain_root); |
327 | ||
328 | he = zalloc(sizeof(*he) + callchain_size); | |
28e2a106 | 329 | |
12c14278 ACM |
330 | if (he != NULL) { |
331 | *he = *template; | |
c4b35351 | 332 | |
f8be1c8c NK |
333 | if (symbol_conf.cumulate_callchain) { |
334 | he->stat_acc = malloc(sizeof(he->stat)); | |
335 | if (he->stat_acc == NULL) { | |
336 | free(he); | |
337 | return NULL; | |
338 | } | |
339 | memcpy(he->stat_acc, &he->stat, sizeof(he->stat)); | |
a0b51af3 NK |
340 | if (!sample_self) |
341 | memset(&he->stat, 0, sizeof(he->stat)); | |
f8be1c8c NK |
342 | } |
343 | ||
5c24b67a | 344 | map__get(he->ms.map); |
3cf0cb1f SE |
345 | |
346 | if (he->branch_info) { | |
26353a61 NK |
347 | /* |
348 | * This branch info is (a part of) allocated from | |
644f2df2 | 349 | * sample__resolve_bstack() and will be freed after |
26353a61 NK |
350 | * adding new entries. So we need to save a copy. |
351 | */ | |
352 | he->branch_info = malloc(sizeof(*he->branch_info)); | |
353 | if (he->branch_info == NULL) { | |
5c24b67a | 354 | map__zput(he->ms.map); |
f8be1c8c | 355 | free(he->stat_acc); |
26353a61 NK |
356 | free(he); |
357 | return NULL; | |
358 | } | |
359 | ||
360 | memcpy(he->branch_info, template->branch_info, | |
361 | sizeof(*he->branch_info)); | |
362 | ||
5c24b67a ACM |
363 | map__get(he->branch_info->from.map); |
364 | map__get(he->branch_info->to.map); | |
3cf0cb1f SE |
365 | } |
366 | ||
98a3b32c | 367 | if (he->mem_info) { |
5c24b67a ACM |
368 | map__get(he->mem_info->iaddr.map); |
369 | map__get(he->mem_info->daddr.map); | |
98a3b32c SE |
370 | } |
371 | ||
28e2a106 | 372 | if (symbol_conf.use_callchain) |
12c14278 | 373 | callchain_init(he->callchain); |
b821c732 | 374 | |
72392834 NK |
375 | if (he->raw_data) { |
376 | he->raw_data = memdup(he->raw_data, he->raw_size); | |
377 | ||
378 | if (he->raw_data == NULL) { | |
379 | map__put(he->ms.map); | |
380 | if (he->branch_info) { | |
381 | map__put(he->branch_info->from.map); | |
382 | map__put(he->branch_info->to.map); | |
383 | free(he->branch_info); | |
384 | } | |
385 | if (he->mem_info) { | |
386 | map__put(he->mem_info->iaddr.map); | |
387 | map__put(he->mem_info->daddr.map); | |
388 | } | |
389 | free(he->stat_acc); | |
390 | free(he); | |
391 | return NULL; | |
392 | } | |
393 | } | |
b821c732 | 394 | INIT_LIST_HEAD(&he->pairs.node); |
f3b623b8 | 395 | thread__get(he->thread); |
28e2a106 ACM |
396 | } |
397 | ||
12c14278 | 398 | return he; |
28e2a106 ACM |
399 | } |
400 | ||
7a007ca9 ACM |
401 | static u8 symbol__parent_filter(const struct symbol *parent) |
402 | { | |
403 | if (symbol_conf.exclude_other && parent == NULL) | |
404 | return 1 << HIST_FILTER__PARENT; | |
405 | return 0; | |
406 | } | |
407 | ||
e7e0efcd ACM |
408 | static struct hist_entry *hists__findnew_entry(struct hists *hists, |
409 | struct hist_entry *entry, | |
410 | struct addr_location *al, | |
411 | bool sample_self) | |
9735abf1 | 412 | { |
1980c2eb | 413 | struct rb_node **p; |
9735abf1 ACM |
414 | struct rb_node *parent = NULL; |
415 | struct hist_entry *he; | |
354cc40e | 416 | int64_t cmp; |
f1cbf78d NK |
417 | u64 period = entry->stat.period; |
418 | u64 weight = entry->stat.weight; | |
9735abf1 | 419 | |
1980c2eb ACM |
420 | p = &hists->entries_in->rb_node; |
421 | ||
9735abf1 ACM |
422 | while (*p != NULL) { |
423 | parent = *p; | |
1980c2eb | 424 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
9735abf1 | 425 | |
9afcf930 NK |
426 | /* |
427 | * Make sure that it receives arguments in a same order as | |
428 | * hist_entry__collapse() so that we can use an appropriate | |
429 | * function when searching an entry regardless which sort | |
430 | * keys were used. | |
431 | */ | |
432 | cmp = hist_entry__cmp(he, entry); | |
9735abf1 ACM |
433 | |
434 | if (!cmp) { | |
0f58474e | 435 | if (sample_self) { |
a0b51af3 | 436 | he_stat__add_period(&he->stat, period, weight); |
0f58474e NK |
437 | hists->stats.total_period += period; |
438 | if (!he->filtered) | |
439 | hists->stats.total_non_filtered_period += period; | |
440 | } | |
f8be1c8c NK |
441 | if (symbol_conf.cumulate_callchain) |
442 | he_stat__add_period(he->stat_acc, period, weight); | |
63fa471d | 443 | |
ceb2acbc | 444 | /* |
e80faac0 | 445 | * This mem info was allocated from sample__resolve_mem |
ceb2acbc NK |
446 | * and will not be used anymore. |
447 | */ | |
74cf249d | 448 | zfree(&entry->mem_info); |
ceb2acbc | 449 | |
63fa471d DM |
450 | /* If the map of an existing hist_entry has |
451 | * become out-of-date due to an exec() or | |
452 | * similar, update it. Otherwise we will | |
453 | * mis-adjust symbol addresses when computing | |
454 | * the history counter to increment. | |
455 | */ | |
456 | if (he->ms.map != entry->ms.map) { | |
5c24b67a ACM |
457 | map__put(he->ms.map); |
458 | he->ms.map = map__get(entry->ms.map); | |
63fa471d | 459 | } |
28e2a106 | 460 | goto out; |
9735abf1 ACM |
461 | } |
462 | ||
463 | if (cmp < 0) | |
464 | p = &(*p)->rb_left; | |
465 | else | |
466 | p = &(*p)->rb_right; | |
467 | } | |
468 | ||
a0b51af3 | 469 | he = hist_entry__new(entry, sample_self); |
9735abf1 | 470 | if (!he) |
27a0dcb7 | 471 | return NULL; |
1980c2eb | 472 | |
0f58474e NK |
473 | if (sample_self) |
474 | hists__inc_stats(hists, he); | |
475 | else | |
476 | hists->nr_entries++; | |
590cd344 | 477 | |
1980c2eb ACM |
478 | rb_link_node(&he->rb_node_in, parent, p); |
479 | rb_insert_color(&he->rb_node_in, hists->entries_in); | |
28e2a106 | 480 | out: |
a0b51af3 NK |
481 | if (sample_self) |
482 | he_stat__add_cpumode_period(&he->stat, al->cpumode, period); | |
f8be1c8c NK |
483 | if (symbol_conf.cumulate_callchain) |
484 | he_stat__add_cpumode_period(he->stat_acc, al->cpumode, period); | |
9735abf1 ACM |
485 | return he; |
486 | } | |
487 | ||
c824c433 | 488 | struct hist_entry *__hists__add_entry(struct hists *hists, |
b5387528 | 489 | struct addr_location *al, |
41a4e6e2 NK |
490 | struct symbol *sym_parent, |
491 | struct branch_info *bi, | |
492 | struct mem_info *mi, | |
fd36f3dd | 493 | struct perf_sample *sample, |
a0b51af3 | 494 | bool sample_self) |
b5387528 RAV |
495 | { |
496 | struct hist_entry entry = { | |
497 | .thread = al->thread, | |
4dfced35 | 498 | .comm = thread__comm(al->thread), |
b5387528 RAV |
499 | .ms = { |
500 | .map = al->map, | |
501 | .sym = al->sym, | |
502 | }, | |
0c4c4deb | 503 | .socket = al->socket, |
7365be55 DZ |
504 | .cpu = al->cpu, |
505 | .cpumode = al->cpumode, | |
506 | .ip = al->addr, | |
507 | .level = al->level, | |
b24c28f7 | 508 | .stat = { |
c4b35351 | 509 | .nr_events = 1, |
fd36f3dd NK |
510 | .period = sample->period, |
511 | .weight = sample->weight, | |
b24c28f7 | 512 | }, |
b5387528 | 513 | .parent = sym_parent, |
2c86c7ca | 514 | .filtered = symbol__parent_filter(sym_parent) | al->filtered, |
c824c433 | 515 | .hists = hists, |
41a4e6e2 NK |
516 | .branch_info = bi, |
517 | .mem_info = mi, | |
fd36f3dd | 518 | .transaction = sample->transaction, |
72392834 NK |
519 | .raw_data = sample->raw_data, |
520 | .raw_size = sample->raw_size, | |
b5387528 RAV |
521 | }; |
522 | ||
e7e0efcd | 523 | return hists__findnew_entry(hists, &entry, al, sample_self); |
b5387528 RAV |
524 | } |
525 | ||
69bcb019 NK |
526 | static int |
527 | iter_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, | |
528 | struct addr_location *al __maybe_unused) | |
529 | { | |
530 | return 0; | |
531 | } | |
532 | ||
533 | static int | |
534 | iter_add_next_nop_entry(struct hist_entry_iter *iter __maybe_unused, | |
535 | struct addr_location *al __maybe_unused) | |
536 | { | |
537 | return 0; | |
538 | } | |
539 | ||
540 | static int | |
541 | iter_prepare_mem_entry(struct hist_entry_iter *iter, struct addr_location *al) | |
542 | { | |
543 | struct perf_sample *sample = iter->sample; | |
544 | struct mem_info *mi; | |
545 | ||
546 | mi = sample__resolve_mem(sample, al); | |
547 | if (mi == NULL) | |
548 | return -ENOMEM; | |
549 | ||
550 | iter->priv = mi; | |
551 | return 0; | |
552 | } | |
553 | ||
554 | static int | |
555 | iter_add_single_mem_entry(struct hist_entry_iter *iter, struct addr_location *al) | |
556 | { | |
557 | u64 cost; | |
558 | struct mem_info *mi = iter->priv; | |
4ea062ed | 559 | struct hists *hists = evsel__hists(iter->evsel); |
fd36f3dd | 560 | struct perf_sample *sample = iter->sample; |
69bcb019 NK |
561 | struct hist_entry *he; |
562 | ||
563 | if (mi == NULL) | |
564 | return -EINVAL; | |
565 | ||
fd36f3dd | 566 | cost = sample->weight; |
69bcb019 NK |
567 | if (!cost) |
568 | cost = 1; | |
569 | ||
570 | /* | |
571 | * must pass period=weight in order to get the correct | |
572 | * sorting from hists__collapse_resort() which is solely | |
573 | * based on periods. We want sorting be done on nr_events * weight | |
574 | * and this is indirectly achieved by passing period=weight here | |
575 | * and the he_stat__add_period() function. | |
576 | */ | |
fd36f3dd NK |
577 | sample->period = cost; |
578 | ||
4ea062ed | 579 | he = __hists__add_entry(hists, al, iter->parent, NULL, mi, |
fd36f3dd | 580 | sample, true); |
69bcb019 NK |
581 | if (!he) |
582 | return -ENOMEM; | |
583 | ||
584 | iter->he = he; | |
585 | return 0; | |
586 | } | |
587 | ||
588 | static int | |
9d3c02d7 NK |
589 | iter_finish_mem_entry(struct hist_entry_iter *iter, |
590 | struct addr_location *al __maybe_unused) | |
69bcb019 NK |
591 | { |
592 | struct perf_evsel *evsel = iter->evsel; | |
4ea062ed | 593 | struct hists *hists = evsel__hists(evsel); |
69bcb019 | 594 | struct hist_entry *he = iter->he; |
69bcb019 NK |
595 | int err = -EINVAL; |
596 | ||
597 | if (he == NULL) | |
598 | goto out; | |
599 | ||
4ea062ed | 600 | hists__inc_nr_samples(hists, he->filtered); |
69bcb019 NK |
601 | |
602 | err = hist_entry__append_callchain(he, iter->sample); | |
603 | ||
604 | out: | |
605 | /* | |
e7e0efcd ACM |
606 | * We don't need to free iter->priv (mem_info) here since the mem info |
607 | * was either already freed in hists__findnew_entry() or passed to a | |
608 | * new hist entry by hist_entry__new(). | |
69bcb019 NK |
609 | */ |
610 | iter->priv = NULL; | |
611 | ||
612 | iter->he = NULL; | |
613 | return err; | |
614 | } | |
615 | ||
616 | static int | |
617 | iter_prepare_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) | |
618 | { | |
619 | struct branch_info *bi; | |
620 | struct perf_sample *sample = iter->sample; | |
621 | ||
622 | bi = sample__resolve_bstack(sample, al); | |
623 | if (!bi) | |
624 | return -ENOMEM; | |
625 | ||
626 | iter->curr = 0; | |
627 | iter->total = sample->branch_stack->nr; | |
628 | ||
629 | iter->priv = bi; | |
630 | return 0; | |
631 | } | |
632 | ||
633 | static int | |
634 | iter_add_single_branch_entry(struct hist_entry_iter *iter __maybe_unused, | |
635 | struct addr_location *al __maybe_unused) | |
636 | { | |
9d3c02d7 NK |
637 | /* to avoid calling callback function */ |
638 | iter->he = NULL; | |
639 | ||
69bcb019 NK |
640 | return 0; |
641 | } | |
642 | ||
643 | static int | |
644 | iter_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) | |
645 | { | |
646 | struct branch_info *bi = iter->priv; | |
647 | int i = iter->curr; | |
648 | ||
649 | if (bi == NULL) | |
650 | return 0; | |
651 | ||
652 | if (iter->curr >= iter->total) | |
653 | return 0; | |
654 | ||
655 | al->map = bi[i].to.map; | |
656 | al->sym = bi[i].to.sym; | |
657 | al->addr = bi[i].to.addr; | |
658 | return 1; | |
659 | } | |
660 | ||
661 | static int | |
662 | iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al) | |
663 | { | |
9d3c02d7 | 664 | struct branch_info *bi; |
69bcb019 | 665 | struct perf_evsel *evsel = iter->evsel; |
4ea062ed | 666 | struct hists *hists = evsel__hists(evsel); |
fd36f3dd | 667 | struct perf_sample *sample = iter->sample; |
69bcb019 NK |
668 | struct hist_entry *he = NULL; |
669 | int i = iter->curr; | |
670 | int err = 0; | |
671 | ||
672 | bi = iter->priv; | |
673 | ||
674 | if (iter->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym)) | |
675 | goto out; | |
676 | ||
677 | /* | |
678 | * The report shows the percentage of total branches captured | |
679 | * and not events sampled. Thus we use a pseudo period of 1. | |
680 | */ | |
fd36f3dd NK |
681 | sample->period = 1; |
682 | sample->weight = bi->flags.cycles ? bi->flags.cycles : 1; | |
683 | ||
4ea062ed | 684 | he = __hists__add_entry(hists, al, iter->parent, &bi[i], NULL, |
fd36f3dd | 685 | sample, true); |
69bcb019 NK |
686 | if (he == NULL) |
687 | return -ENOMEM; | |
688 | ||
4ea062ed | 689 | hists__inc_nr_samples(hists, he->filtered); |
69bcb019 NK |
690 | |
691 | out: | |
692 | iter->he = he; | |
693 | iter->curr++; | |
694 | return err; | |
695 | } | |
696 | ||
697 | static int | |
698 | iter_finish_branch_entry(struct hist_entry_iter *iter, | |
699 | struct addr_location *al __maybe_unused) | |
700 | { | |
701 | zfree(&iter->priv); | |
702 | iter->he = NULL; | |
703 | ||
704 | return iter->curr >= iter->total ? 0 : -1; | |
705 | } | |
706 | ||
707 | static int | |
708 | iter_prepare_normal_entry(struct hist_entry_iter *iter __maybe_unused, | |
709 | struct addr_location *al __maybe_unused) | |
710 | { | |
711 | return 0; | |
712 | } | |
713 | ||
714 | static int | |
715 | iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location *al) | |
716 | { | |
717 | struct perf_evsel *evsel = iter->evsel; | |
718 | struct perf_sample *sample = iter->sample; | |
719 | struct hist_entry *he; | |
720 | ||
4ea062ed | 721 | he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, |
fd36f3dd | 722 | sample, true); |
69bcb019 NK |
723 | if (he == NULL) |
724 | return -ENOMEM; | |
725 | ||
726 | iter->he = he; | |
727 | return 0; | |
728 | } | |
729 | ||
730 | static int | |
9d3c02d7 NK |
731 | iter_finish_normal_entry(struct hist_entry_iter *iter, |
732 | struct addr_location *al __maybe_unused) | |
69bcb019 | 733 | { |
69bcb019 NK |
734 | struct hist_entry *he = iter->he; |
735 | struct perf_evsel *evsel = iter->evsel; | |
736 | struct perf_sample *sample = iter->sample; | |
737 | ||
738 | if (he == NULL) | |
739 | return 0; | |
740 | ||
741 | iter->he = NULL; | |
742 | ||
4ea062ed | 743 | hists__inc_nr_samples(evsel__hists(evsel), he->filtered); |
69bcb019 NK |
744 | |
745 | return hist_entry__append_callchain(he, sample); | |
746 | } | |
747 | ||
7a13aa28 | 748 | static int |
96b40f3c | 749 | iter_prepare_cumulative_entry(struct hist_entry_iter *iter, |
7a13aa28 NK |
750 | struct addr_location *al __maybe_unused) |
751 | { | |
b4d3c8bd NK |
752 | struct hist_entry **he_cache; |
753 | ||
7a13aa28 | 754 | callchain_cursor_commit(&callchain_cursor); |
b4d3c8bd NK |
755 | |
756 | /* | |
757 | * This is for detecting cycles or recursions so that they're | |
758 | * cumulated only one time to prevent entries more than 100% | |
759 | * overhead. | |
760 | */ | |
96b40f3c | 761 | he_cache = malloc(sizeof(*he_cache) * (iter->max_stack + 1)); |
b4d3c8bd NK |
762 | if (he_cache == NULL) |
763 | return -ENOMEM; | |
764 | ||
765 | iter->priv = he_cache; | |
766 | iter->curr = 0; | |
767 | ||
7a13aa28 NK |
768 | return 0; |
769 | } | |
770 | ||
771 | static int | |
772 | iter_add_single_cumulative_entry(struct hist_entry_iter *iter, | |
773 | struct addr_location *al) | |
774 | { | |
775 | struct perf_evsel *evsel = iter->evsel; | |
4ea062ed | 776 | struct hists *hists = evsel__hists(evsel); |
7a13aa28 | 777 | struct perf_sample *sample = iter->sample; |
b4d3c8bd | 778 | struct hist_entry **he_cache = iter->priv; |
7a13aa28 NK |
779 | struct hist_entry *he; |
780 | int err = 0; | |
781 | ||
4ea062ed | 782 | he = __hists__add_entry(hists, al, iter->parent, NULL, NULL, |
fd36f3dd | 783 | sample, true); |
7a13aa28 NK |
784 | if (he == NULL) |
785 | return -ENOMEM; | |
786 | ||
787 | iter->he = he; | |
b4d3c8bd | 788 | he_cache[iter->curr++] = he; |
7a13aa28 | 789 | |
82aa019e | 790 | hist_entry__append_callchain(he, sample); |
be7f855a NK |
791 | |
792 | /* | |
793 | * We need to re-initialize the cursor since callchain_append() | |
794 | * advanced the cursor to the end. | |
795 | */ | |
796 | callchain_cursor_commit(&callchain_cursor); | |
797 | ||
4ea062ed | 798 | hists__inc_nr_samples(hists, he->filtered); |
7a13aa28 NK |
799 | |
800 | return err; | |
801 | } | |
802 | ||
803 | static int | |
804 | iter_next_cumulative_entry(struct hist_entry_iter *iter, | |
805 | struct addr_location *al) | |
806 | { | |
807 | struct callchain_cursor_node *node; | |
808 | ||
809 | node = callchain_cursor_current(&callchain_cursor); | |
810 | if (node == NULL) | |
811 | return 0; | |
812 | ||
c7405d85 | 813 | return fill_callchain_info(al, node, iter->hide_unresolved); |
7a13aa28 NK |
814 | } |
815 | ||
816 | static int | |
817 | iter_add_next_cumulative_entry(struct hist_entry_iter *iter, | |
818 | struct addr_location *al) | |
819 | { | |
820 | struct perf_evsel *evsel = iter->evsel; | |
821 | struct perf_sample *sample = iter->sample; | |
b4d3c8bd | 822 | struct hist_entry **he_cache = iter->priv; |
7a13aa28 | 823 | struct hist_entry *he; |
b4d3c8bd | 824 | struct hist_entry he_tmp = { |
5cef8976 | 825 | .hists = evsel__hists(evsel), |
b4d3c8bd NK |
826 | .cpu = al->cpu, |
827 | .thread = al->thread, | |
828 | .comm = thread__comm(al->thread), | |
829 | .ip = al->addr, | |
830 | .ms = { | |
831 | .map = al->map, | |
832 | .sym = al->sym, | |
833 | }, | |
834 | .parent = iter->parent, | |
72392834 NK |
835 | .raw_data = sample->raw_data, |
836 | .raw_size = sample->raw_size, | |
b4d3c8bd NK |
837 | }; |
838 | int i; | |
be7f855a NK |
839 | struct callchain_cursor cursor; |
840 | ||
841 | callchain_cursor_snapshot(&cursor, &callchain_cursor); | |
842 | ||
843 | callchain_cursor_advance(&callchain_cursor); | |
b4d3c8bd NK |
844 | |
845 | /* | |
846 | * Check if there's duplicate entries in the callchain. | |
847 | * It's possible that it has cycles or recursive calls. | |
848 | */ | |
849 | for (i = 0; i < iter->curr; i++) { | |
9d3c02d7 NK |
850 | if (hist_entry__cmp(he_cache[i], &he_tmp) == 0) { |
851 | /* to avoid calling callback function */ | |
852 | iter->he = NULL; | |
b4d3c8bd | 853 | return 0; |
9d3c02d7 | 854 | } |
b4d3c8bd | 855 | } |
7a13aa28 | 856 | |
4ea062ed | 857 | he = __hists__add_entry(evsel__hists(evsel), al, iter->parent, NULL, NULL, |
fd36f3dd | 858 | sample, false); |
7a13aa28 NK |
859 | if (he == NULL) |
860 | return -ENOMEM; | |
861 | ||
862 | iter->he = he; | |
b4d3c8bd | 863 | he_cache[iter->curr++] = he; |
7a13aa28 | 864 | |
82aa019e NK |
865 | if (symbol_conf.use_callchain) |
866 | callchain_append(he->callchain, &cursor, sample->period); | |
7a13aa28 NK |
867 | return 0; |
868 | } | |
869 | ||
870 | static int | |
871 | iter_finish_cumulative_entry(struct hist_entry_iter *iter, | |
872 | struct addr_location *al __maybe_unused) | |
873 | { | |
b4d3c8bd | 874 | zfree(&iter->priv); |
7a13aa28 | 875 | iter->he = NULL; |
b4d3c8bd | 876 | |
7a13aa28 NK |
877 | return 0; |
878 | } | |
879 | ||
69bcb019 NK |
880 | const struct hist_iter_ops hist_iter_mem = { |
881 | .prepare_entry = iter_prepare_mem_entry, | |
882 | .add_single_entry = iter_add_single_mem_entry, | |
883 | .next_entry = iter_next_nop_entry, | |
884 | .add_next_entry = iter_add_next_nop_entry, | |
885 | .finish_entry = iter_finish_mem_entry, | |
886 | }; | |
887 | ||
888 | const struct hist_iter_ops hist_iter_branch = { | |
889 | .prepare_entry = iter_prepare_branch_entry, | |
890 | .add_single_entry = iter_add_single_branch_entry, | |
891 | .next_entry = iter_next_branch_entry, | |
892 | .add_next_entry = iter_add_next_branch_entry, | |
893 | .finish_entry = iter_finish_branch_entry, | |
894 | }; | |
895 | ||
896 | const struct hist_iter_ops hist_iter_normal = { | |
897 | .prepare_entry = iter_prepare_normal_entry, | |
898 | .add_single_entry = iter_add_single_normal_entry, | |
899 | .next_entry = iter_next_nop_entry, | |
900 | .add_next_entry = iter_add_next_nop_entry, | |
901 | .finish_entry = iter_finish_normal_entry, | |
902 | }; | |
903 | ||
7a13aa28 NK |
904 | const struct hist_iter_ops hist_iter_cumulative = { |
905 | .prepare_entry = iter_prepare_cumulative_entry, | |
906 | .add_single_entry = iter_add_single_cumulative_entry, | |
907 | .next_entry = iter_next_cumulative_entry, | |
908 | .add_next_entry = iter_add_next_cumulative_entry, | |
909 | .finish_entry = iter_finish_cumulative_entry, | |
910 | }; | |
911 | ||
69bcb019 | 912 | int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, |
9d3c02d7 | 913 | int max_stack_depth, void *arg) |
69bcb019 NK |
914 | { |
915 | int err, err2; | |
916 | ||
063bd936 NK |
917 | err = sample__resolve_callchain(iter->sample, &iter->parent, |
918 | iter->evsel, al, max_stack_depth); | |
69bcb019 NK |
919 | if (err) |
920 | return err; | |
921 | ||
96b40f3c AH |
922 | iter->max_stack = max_stack_depth; |
923 | ||
69bcb019 NK |
924 | err = iter->ops->prepare_entry(iter, al); |
925 | if (err) | |
926 | goto out; | |
927 | ||
928 | err = iter->ops->add_single_entry(iter, al); | |
929 | if (err) | |
930 | goto out; | |
931 | ||
9d3c02d7 NK |
932 | if (iter->he && iter->add_entry_cb) { |
933 | err = iter->add_entry_cb(iter, al, true, arg); | |
934 | if (err) | |
935 | goto out; | |
936 | } | |
937 | ||
69bcb019 NK |
938 | while (iter->ops->next_entry(iter, al)) { |
939 | err = iter->ops->add_next_entry(iter, al); | |
940 | if (err) | |
941 | break; | |
9d3c02d7 NK |
942 | |
943 | if (iter->he && iter->add_entry_cb) { | |
944 | err = iter->add_entry_cb(iter, al, false, arg); | |
945 | if (err) | |
946 | goto out; | |
947 | } | |
69bcb019 NK |
948 | } |
949 | ||
950 | out: | |
951 | err2 = iter->ops->finish_entry(iter, al); | |
952 | if (!err) | |
953 | err = err2; | |
954 | ||
955 | return err; | |
956 | } | |
957 | ||
3d1d07ec JK |
958 | int64_t |
959 | hist_entry__cmp(struct hist_entry *left, struct hist_entry *right) | |
960 | { | |
093f0ef3 | 961 | struct perf_hpp_fmt *fmt; |
3d1d07ec JK |
962 | int64_t cmp = 0; |
963 | ||
093f0ef3 | 964 | perf_hpp__for_each_sort_list(fmt) { |
87bbdf76 | 965 | cmp = fmt->cmp(fmt, left, right); |
3d1d07ec JK |
966 | if (cmp) |
967 | break; | |
968 | } | |
969 | ||
970 | return cmp; | |
971 | } | |
972 | ||
973 | int64_t | |
974 | hist_entry__collapse(struct hist_entry *left, struct hist_entry *right) | |
975 | { | |
093f0ef3 | 976 | struct perf_hpp_fmt *fmt; |
3d1d07ec JK |
977 | int64_t cmp = 0; |
978 | ||
093f0ef3 | 979 | perf_hpp__for_each_sort_list(fmt) { |
87bbdf76 | 980 | cmp = fmt->collapse(fmt, left, right); |
3d1d07ec JK |
981 | if (cmp) |
982 | break; | |
983 | } | |
984 | ||
985 | return cmp; | |
986 | } | |
987 | ||
6733d1bf | 988 | void hist_entry__delete(struct hist_entry *he) |
3d1d07ec | 989 | { |
f3b623b8 | 990 | thread__zput(he->thread); |
5c24b67a ACM |
991 | map__zput(he->ms.map); |
992 | ||
993 | if (he->branch_info) { | |
994 | map__zput(he->branch_info->from.map); | |
995 | map__zput(he->branch_info->to.map); | |
996 | zfree(&he->branch_info); | |
997 | } | |
998 | ||
999 | if (he->mem_info) { | |
1000 | map__zput(he->mem_info->iaddr.map); | |
1001 | map__zput(he->mem_info->daddr.map); | |
1002 | zfree(&he->mem_info); | |
1003 | } | |
1004 | ||
f8be1c8c | 1005 | zfree(&he->stat_acc); |
f048d548 | 1006 | free_srcline(he->srcline); |
31191a85 AK |
1007 | if (he->srcfile && he->srcfile[0]) |
1008 | free(he->srcfile); | |
d114960c | 1009 | free_callchain(he->callchain); |
60517d28 | 1010 | free(he->trace_output); |
72392834 | 1011 | free(he->raw_data); |
3d1d07ec JK |
1012 | free(he); |
1013 | } | |
1014 | ||
1015 | /* | |
1016 | * collapse the histogram | |
1017 | */ | |
1018 | ||
fc284be9 NK |
1019 | bool hists__collapse_insert_entry(struct hists *hists __maybe_unused, |
1020 | struct rb_root *root, struct hist_entry *he) | |
3d1d07ec | 1021 | { |
b9bf0892 | 1022 | struct rb_node **p = &root->rb_node; |
3d1d07ec JK |
1023 | struct rb_node *parent = NULL; |
1024 | struct hist_entry *iter; | |
1025 | int64_t cmp; | |
1026 | ||
1027 | while (*p != NULL) { | |
1028 | parent = *p; | |
1980c2eb | 1029 | iter = rb_entry(parent, struct hist_entry, rb_node_in); |
3d1d07ec JK |
1030 | |
1031 | cmp = hist_entry__collapse(iter, he); | |
1032 | ||
1033 | if (!cmp) { | |
139c0815 | 1034 | he_stat__add_stat(&iter->stat, &he->stat); |
f8be1c8c NK |
1035 | if (symbol_conf.cumulate_callchain) |
1036 | he_stat__add_stat(iter->stat_acc, he->stat_acc); | |
9ec60972 | 1037 | |
1b3a0e95 | 1038 | if (symbol_conf.use_callchain) { |
47260645 NK |
1039 | callchain_cursor_reset(&callchain_cursor); |
1040 | callchain_merge(&callchain_cursor, | |
1041 | iter->callchain, | |
1b3a0e95 FW |
1042 | he->callchain); |
1043 | } | |
6733d1bf | 1044 | hist_entry__delete(he); |
fefb0b94 | 1045 | return false; |
3d1d07ec JK |
1046 | } |
1047 | ||
1048 | if (cmp < 0) | |
1049 | p = &(*p)->rb_left; | |
1050 | else | |
1051 | p = &(*p)->rb_right; | |
1052 | } | |
740b97f9 | 1053 | hists->nr_entries++; |
3d1d07ec | 1054 | |
1980c2eb ACM |
1055 | rb_link_node(&he->rb_node_in, parent, p); |
1056 | rb_insert_color(&he->rb_node_in, root); | |
fefb0b94 | 1057 | return true; |
3d1d07ec JK |
1058 | } |
1059 | ||
fc284be9 | 1060 | struct rb_root *hists__get_rotate_entries_in(struct hists *hists) |
3d1d07ec | 1061 | { |
1980c2eb ACM |
1062 | struct rb_root *root; |
1063 | ||
1064 | pthread_mutex_lock(&hists->lock); | |
1065 | ||
1066 | root = hists->entries_in; | |
1067 | if (++hists->entries_in > &hists->entries_in_array[1]) | |
1068 | hists->entries_in = &hists->entries_in_array[0]; | |
1069 | ||
1070 | pthread_mutex_unlock(&hists->lock); | |
1071 | ||
1072 | return root; | |
1073 | } | |
1074 | ||
90cf1fb5 ACM |
1075 | static void hists__apply_filters(struct hists *hists, struct hist_entry *he) |
1076 | { | |
1077 | hists__filter_entry_by_dso(hists, he); | |
1078 | hists__filter_entry_by_thread(hists, he); | |
e94d53eb | 1079 | hists__filter_entry_by_symbol(hists, he); |
21394d94 | 1080 | hists__filter_entry_by_socket(hists, he); |
90cf1fb5 ACM |
1081 | } |
1082 | ||
c1fb5651 | 1083 | void hists__collapse_resort(struct hists *hists, struct ui_progress *prog) |
1980c2eb ACM |
1084 | { |
1085 | struct rb_root *root; | |
3d1d07ec JK |
1086 | struct rb_node *next; |
1087 | struct hist_entry *n; | |
1088 | ||
3a5714f8 | 1089 | if (!sort__need_collapse) |
3d1d07ec JK |
1090 | return; |
1091 | ||
740b97f9 NK |
1092 | hists->nr_entries = 0; |
1093 | ||
1980c2eb | 1094 | root = hists__get_rotate_entries_in(hists); |
740b97f9 | 1095 | |
1980c2eb | 1096 | next = rb_first(root); |
b9bf0892 | 1097 | |
3d1d07ec | 1098 | while (next) { |
33e940a2 ACM |
1099 | if (session_done()) |
1100 | break; | |
1980c2eb ACM |
1101 | n = rb_entry(next, struct hist_entry, rb_node_in); |
1102 | next = rb_next(&n->rb_node_in); | |
3d1d07ec | 1103 | |
1980c2eb | 1104 | rb_erase(&n->rb_node_in, root); |
90cf1fb5 ACM |
1105 | if (hists__collapse_insert_entry(hists, &hists->entries_collapsed, n)) { |
1106 | /* | |
1107 | * If it wasn't combined with one of the entries already | |
1108 | * collapsed, we need to apply the filters that may have | |
1109 | * been set by, say, the hist_browser. | |
1110 | */ | |
1111 | hists__apply_filters(hists, n); | |
90cf1fb5 | 1112 | } |
c1fb5651 NK |
1113 | if (prog) |
1114 | ui_progress__update(prog, 1); | |
3d1d07ec | 1115 | } |
1980c2eb | 1116 | } |
b9bf0892 | 1117 | |
043ca389 | 1118 | static int hist_entry__sort(struct hist_entry *a, struct hist_entry *b) |
29d720ed | 1119 | { |
043ca389 NK |
1120 | struct perf_hpp_fmt *fmt; |
1121 | int64_t cmp = 0; | |
29d720ed | 1122 | |
26d8b338 | 1123 | perf_hpp__for_each_sort_list(fmt) { |
361459f1 | 1124 | if (perf_hpp__should_skip(fmt, a->hists)) |
e67d49a7 NK |
1125 | continue; |
1126 | ||
87bbdf76 | 1127 | cmp = fmt->sort(fmt, a, b); |
043ca389 | 1128 | if (cmp) |
29d720ed NK |
1129 | break; |
1130 | } | |
1131 | ||
043ca389 | 1132 | return cmp; |
29d720ed NK |
1133 | } |
1134 | ||
9283ba9b NK |
1135 | static void hists__reset_filter_stats(struct hists *hists) |
1136 | { | |
1137 | hists->nr_non_filtered_entries = 0; | |
1138 | hists->stats.total_non_filtered_period = 0; | |
1139 | } | |
1140 | ||
1141 | void hists__reset_stats(struct hists *hists) | |
1142 | { | |
1143 | hists->nr_entries = 0; | |
1144 | hists->stats.total_period = 0; | |
1145 | ||
1146 | hists__reset_filter_stats(hists); | |
1147 | } | |
1148 | ||
1149 | static void hists__inc_filter_stats(struct hists *hists, struct hist_entry *h) | |
1150 | { | |
1151 | hists->nr_non_filtered_entries++; | |
1152 | hists->stats.total_non_filtered_period += h->stat.period; | |
1153 | } | |
1154 | ||
1155 | void hists__inc_stats(struct hists *hists, struct hist_entry *h) | |
1156 | { | |
1157 | if (!h->filtered) | |
1158 | hists__inc_filter_stats(hists, h); | |
1159 | ||
1160 | hists->nr_entries++; | |
1161 | hists->stats.total_period += h->stat.period; | |
1162 | } | |
1163 | ||
1c02c4d2 ACM |
1164 | static void __hists__insert_output_entry(struct rb_root *entries, |
1165 | struct hist_entry *he, | |
f9db0d0f KL |
1166 | u64 min_callchain_hits, |
1167 | bool use_callchain) | |
3d1d07ec | 1168 | { |
1c02c4d2 | 1169 | struct rb_node **p = &entries->rb_node; |
3d1d07ec JK |
1170 | struct rb_node *parent = NULL; |
1171 | struct hist_entry *iter; | |
1172 | ||
744070e0 NK |
1173 | if (use_callchain) { |
1174 | if (callchain_param.mode == CHAIN_GRAPH_REL) { | |
1175 | u64 total = he->stat.period; | |
1176 | ||
1177 | if (symbol_conf.cumulate_callchain) | |
1178 | total = he->stat_acc->period; | |
1179 | ||
1180 | min_callchain_hits = total * (callchain_param.min_percent / 100); | |
1181 | } | |
b9fb9304 | 1182 | callchain_param.sort(&he->sorted_chain, he->callchain, |
3d1d07ec | 1183 | min_callchain_hits, &callchain_param); |
744070e0 | 1184 | } |
3d1d07ec JK |
1185 | |
1186 | while (*p != NULL) { | |
1187 | parent = *p; | |
1188 | iter = rb_entry(parent, struct hist_entry, rb_node); | |
1189 | ||
043ca389 | 1190 | if (hist_entry__sort(he, iter) > 0) |
3d1d07ec JK |
1191 | p = &(*p)->rb_left; |
1192 | else | |
1193 | p = &(*p)->rb_right; | |
1194 | } | |
1195 | ||
1196 | rb_link_node(&he->rb_node, parent, p); | |
1c02c4d2 | 1197 | rb_insert_color(&he->rb_node, entries); |
3d1d07ec JK |
1198 | } |
1199 | ||
740b97f9 | 1200 | void hists__output_resort(struct hists *hists, struct ui_progress *prog) |
3d1d07ec | 1201 | { |
1980c2eb | 1202 | struct rb_root *root; |
3d1d07ec JK |
1203 | struct rb_node *next; |
1204 | struct hist_entry *n; | |
3d1d07ec | 1205 | u64 min_callchain_hits; |
f9db0d0f | 1206 | struct perf_evsel *evsel = hists_to_evsel(hists); |
9e207ddf KL |
1207 | bool use_callchain; |
1208 | ||
208e7607 | 1209 | if (evsel && symbol_conf.use_callchain && !symbol_conf.show_ref_callgraph) |
9e207ddf KL |
1210 | use_callchain = evsel->attr.sample_type & PERF_SAMPLE_CALLCHAIN; |
1211 | else | |
1212 | use_callchain = symbol_conf.use_callchain; | |
3d1d07ec | 1213 | |
744070e0 | 1214 | min_callchain_hits = hists__total_period(hists) * (callchain_param.min_percent / 100); |
3d1d07ec | 1215 | |
3a5714f8 | 1216 | if (sort__need_collapse) |
1980c2eb ACM |
1217 | root = &hists->entries_collapsed; |
1218 | else | |
1219 | root = hists->entries_in; | |
1220 | ||
1221 | next = rb_first(root); | |
1222 | hists->entries = RB_ROOT; | |
3d1d07ec | 1223 | |
9283ba9b | 1224 | hists__reset_stats(hists); |
42b28ac0 | 1225 | hists__reset_col_len(hists); |
fefb0b94 | 1226 | |
3d1d07ec | 1227 | while (next) { |
1980c2eb ACM |
1228 | n = rb_entry(next, struct hist_entry, rb_node_in); |
1229 | next = rb_next(&n->rb_node_in); | |
3d1d07ec | 1230 | |
f9db0d0f | 1231 | __hists__insert_output_entry(&hists->entries, n, min_callchain_hits, use_callchain); |
6263835a | 1232 | hists__inc_stats(hists, n); |
ae993efc NK |
1233 | |
1234 | if (!n->filtered) | |
1235 | hists__calc_col_len(hists, n); | |
740b97f9 NK |
1236 | |
1237 | if (prog) | |
1238 | ui_progress__update(prog, 1); | |
3d1d07ec | 1239 | } |
1980c2eb | 1240 | } |
b9bf0892 | 1241 | |
42b28ac0 | 1242 | static void hists__remove_entry_filter(struct hists *hists, struct hist_entry *h, |
cc5edb0e ACM |
1243 | enum hist_filter filter) |
1244 | { | |
1245 | h->filtered &= ~(1 << filter); | |
1246 | if (h->filtered) | |
1247 | return; | |
1248 | ||
87e90f43 | 1249 | /* force fold unfiltered entry for simplicity */ |
3698dab1 | 1250 | h->unfolded = false; |
0f0cbf7a | 1251 | h->row_offset = 0; |
a8cd1f43 | 1252 | h->nr_rows = 0; |
9283ba9b | 1253 | |
1ab1fa5d | 1254 | hists->stats.nr_non_filtered_samples += h->stat.nr_events; |
cc5edb0e | 1255 | |
9283ba9b | 1256 | hists__inc_filter_stats(hists, h); |
42b28ac0 | 1257 | hists__calc_col_len(hists, h); |
cc5edb0e ACM |
1258 | } |
1259 | ||
90cf1fb5 ACM |
1260 | |
1261 | static bool hists__filter_entry_by_dso(struct hists *hists, | |
1262 | struct hist_entry *he) | |
1263 | { | |
1264 | if (hists->dso_filter != NULL && | |
1265 | (he->ms.map == NULL || he->ms.map->dso != hists->dso_filter)) { | |
1266 | he->filtered |= (1 << HIST_FILTER__DSO); | |
1267 | return true; | |
1268 | } | |
1269 | ||
1270 | return false; | |
1271 | } | |
1272 | ||
90cf1fb5 ACM |
1273 | static bool hists__filter_entry_by_thread(struct hists *hists, |
1274 | struct hist_entry *he) | |
1275 | { | |
1276 | if (hists->thread_filter != NULL && | |
1277 | he->thread != hists->thread_filter) { | |
1278 | he->filtered |= (1 << HIST_FILTER__THREAD); | |
1279 | return true; | |
1280 | } | |
1281 | ||
1282 | return false; | |
1283 | } | |
1284 | ||
e94d53eb NK |
1285 | static bool hists__filter_entry_by_symbol(struct hists *hists, |
1286 | struct hist_entry *he) | |
1287 | { | |
1288 | if (hists->symbol_filter_str != NULL && | |
1289 | (!he->ms.sym || strstr(he->ms.sym->name, | |
1290 | hists->symbol_filter_str) == NULL)) { | |
1291 | he->filtered |= (1 << HIST_FILTER__SYMBOL); | |
1292 | return true; | |
1293 | } | |
1294 | ||
1295 | return false; | |
1296 | } | |
1297 | ||
21394d94 KL |
1298 | static bool hists__filter_entry_by_socket(struct hists *hists, |
1299 | struct hist_entry *he) | |
1300 | { | |
1301 | if ((hists->socket_filter > -1) && | |
1302 | (he->socket != hists->socket_filter)) { | |
1303 | he->filtered |= (1 << HIST_FILTER__SOCKET); | |
1304 | return true; | |
1305 | } | |
1306 | ||
1307 | return false; | |
1308 | } | |
1309 | ||
1f7c2541 NK |
1310 | typedef bool (*filter_fn_t)(struct hists *hists, struct hist_entry *he); |
1311 | ||
1312 | static void hists__filter_by_type(struct hists *hists, int type, filter_fn_t filter) | |
84734b06 KL |
1313 | { |
1314 | struct rb_node *nd; | |
1315 | ||
1316 | hists->stats.nr_non_filtered_samples = 0; | |
1317 | ||
1318 | hists__reset_filter_stats(hists); | |
1319 | hists__reset_col_len(hists); | |
1320 | ||
1321 | for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) { | |
1322 | struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node); | |
1323 | ||
1f7c2541 | 1324 | if (filter(hists, h)) |
84734b06 KL |
1325 | continue; |
1326 | ||
1f7c2541 | 1327 | hists__remove_entry_filter(hists, h, type); |
84734b06 KL |
1328 | } |
1329 | } | |
1330 | ||
1f7c2541 NK |
1331 | void hists__filter_by_thread(struct hists *hists) |
1332 | { | |
1333 | hists__filter_by_type(hists, HIST_FILTER__THREAD, | |
1334 | hists__filter_entry_by_thread); | |
1335 | } | |
1336 | ||
1337 | void hists__filter_by_dso(struct hists *hists) | |
1338 | { | |
1339 | hists__filter_by_type(hists, HIST_FILTER__DSO, | |
1340 | hists__filter_entry_by_dso); | |
1341 | } | |
1342 | ||
1343 | void hists__filter_by_symbol(struct hists *hists) | |
1344 | { | |
1345 | hists__filter_by_type(hists, HIST_FILTER__SYMBOL, | |
1346 | hists__filter_entry_by_symbol); | |
1347 | } | |
1348 | ||
1349 | void hists__filter_by_socket(struct hists *hists) | |
1350 | { | |
1351 | hists__filter_by_type(hists, HIST_FILTER__SOCKET, | |
1352 | hists__filter_entry_by_socket); | |
1353 | } | |
1354 | ||
28a6b6aa ACM |
1355 | void events_stats__inc(struct events_stats *stats, u32 type) |
1356 | { | |
1357 | ++stats->nr_events[0]; | |
1358 | ++stats->nr_events[type]; | |
1359 | } | |
1360 | ||
42b28ac0 | 1361 | void hists__inc_nr_events(struct hists *hists, u32 type) |
c8446b9b | 1362 | { |
28a6b6aa | 1363 | events_stats__inc(&hists->stats, type); |
c8446b9b | 1364 | } |
95529be4 | 1365 | |
1844dbcb NK |
1366 | void hists__inc_nr_samples(struct hists *hists, bool filtered) |
1367 | { | |
1368 | events_stats__inc(&hists->stats, PERF_RECORD_SAMPLE); | |
1369 | if (!filtered) | |
1370 | hists->stats.nr_non_filtered_samples++; | |
1371 | } | |
1372 | ||
494d70a1 ACM |
1373 | static struct hist_entry *hists__add_dummy_entry(struct hists *hists, |
1374 | struct hist_entry *pair) | |
1375 | { | |
ce74f60e NK |
1376 | struct rb_root *root; |
1377 | struct rb_node **p; | |
494d70a1 ACM |
1378 | struct rb_node *parent = NULL; |
1379 | struct hist_entry *he; | |
354cc40e | 1380 | int64_t cmp; |
494d70a1 | 1381 | |
ce74f60e NK |
1382 | if (sort__need_collapse) |
1383 | root = &hists->entries_collapsed; | |
1384 | else | |
1385 | root = hists->entries_in; | |
1386 | ||
1387 | p = &root->rb_node; | |
1388 | ||
494d70a1 ACM |
1389 | while (*p != NULL) { |
1390 | parent = *p; | |
ce74f60e | 1391 | he = rb_entry(parent, struct hist_entry, rb_node_in); |
494d70a1 | 1392 | |
ce74f60e | 1393 | cmp = hist_entry__collapse(he, pair); |
494d70a1 ACM |
1394 | |
1395 | if (!cmp) | |
1396 | goto out; | |
1397 | ||
1398 | if (cmp < 0) | |
1399 | p = &(*p)->rb_left; | |
1400 | else | |
1401 | p = &(*p)->rb_right; | |
1402 | } | |
1403 | ||
a0b51af3 | 1404 | he = hist_entry__new(pair, true); |
494d70a1 | 1405 | if (he) { |
30193d78 ACM |
1406 | memset(&he->stat, 0, sizeof(he->stat)); |
1407 | he->hists = hists; | |
ce74f60e NK |
1408 | rb_link_node(&he->rb_node_in, parent, p); |
1409 | rb_insert_color(&he->rb_node_in, root); | |
6263835a | 1410 | hists__inc_stats(hists, he); |
e0af43d2 | 1411 | he->dummy = true; |
494d70a1 ACM |
1412 | } |
1413 | out: | |
1414 | return he; | |
1415 | } | |
1416 | ||
95529be4 ACM |
1417 | static struct hist_entry *hists__find_entry(struct hists *hists, |
1418 | struct hist_entry *he) | |
1419 | { | |
ce74f60e NK |
1420 | struct rb_node *n; |
1421 | ||
1422 | if (sort__need_collapse) | |
1423 | n = hists->entries_collapsed.rb_node; | |
1424 | else | |
1425 | n = hists->entries_in->rb_node; | |
95529be4 ACM |
1426 | |
1427 | while (n) { | |
ce74f60e NK |
1428 | struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in); |
1429 | int64_t cmp = hist_entry__collapse(iter, he); | |
95529be4 ACM |
1430 | |
1431 | if (cmp < 0) | |
1432 | n = n->rb_left; | |
1433 | else if (cmp > 0) | |
1434 | n = n->rb_right; | |
1435 | else | |
1436 | return iter; | |
1437 | } | |
1438 | ||
1439 | return NULL; | |
1440 | } | |
1441 | ||
1442 | /* | |
1443 | * Look for pairs to link to the leader buckets (hist_entries): | |
1444 | */ | |
1445 | void hists__match(struct hists *leader, struct hists *other) | |
1446 | { | |
ce74f60e | 1447 | struct rb_root *root; |
95529be4 ACM |
1448 | struct rb_node *nd; |
1449 | struct hist_entry *pos, *pair; | |
1450 | ||
ce74f60e NK |
1451 | if (sort__need_collapse) |
1452 | root = &leader->entries_collapsed; | |
1453 | else | |
1454 | root = leader->entries_in; | |
1455 | ||
1456 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { | |
1457 | pos = rb_entry(nd, struct hist_entry, rb_node_in); | |
95529be4 ACM |
1458 | pair = hists__find_entry(other, pos); |
1459 | ||
1460 | if (pair) | |
5fa9041b | 1461 | hist_entry__add_pair(pair, pos); |
95529be4 ACM |
1462 | } |
1463 | } | |
494d70a1 ACM |
1464 | |
1465 | /* | |
1466 | * Look for entries in the other hists that are not present in the leader, if | |
1467 | * we find them, just add a dummy entry on the leader hists, with period=0, | |
1468 | * nr_events=0, to serve as the list header. | |
1469 | */ | |
1470 | int hists__link(struct hists *leader, struct hists *other) | |
1471 | { | |
ce74f60e | 1472 | struct rb_root *root; |
494d70a1 ACM |
1473 | struct rb_node *nd; |
1474 | struct hist_entry *pos, *pair; | |
1475 | ||
ce74f60e NK |
1476 | if (sort__need_collapse) |
1477 | root = &other->entries_collapsed; | |
1478 | else | |
1479 | root = other->entries_in; | |
1480 | ||
1481 | for (nd = rb_first(root); nd; nd = rb_next(nd)) { | |
1482 | pos = rb_entry(nd, struct hist_entry, rb_node_in); | |
494d70a1 ACM |
1483 | |
1484 | if (!hist_entry__has_pairs(pos)) { | |
1485 | pair = hists__add_dummy_entry(leader, pos); | |
1486 | if (pair == NULL) | |
1487 | return -1; | |
5fa9041b | 1488 | hist_entry__add_pair(pos, pair); |
494d70a1 ACM |
1489 | } |
1490 | } | |
1491 | ||
1492 | return 0; | |
1493 | } | |
f2148330 | 1494 | |
57849998 AK |
1495 | void hist__account_cycles(struct branch_stack *bs, struct addr_location *al, |
1496 | struct perf_sample *sample, bool nonany_branch_mode) | |
1497 | { | |
1498 | struct branch_info *bi; | |
1499 | ||
1500 | /* If we have branch cycles always annotate them. */ | |
1501 | if (bs && bs->nr && bs->entries[0].flags.cycles) { | |
1502 | int i; | |
1503 | ||
1504 | bi = sample__resolve_bstack(sample, al); | |
1505 | if (bi) { | |
1506 | struct addr_map_symbol *prev = NULL; | |
1507 | ||
1508 | /* | |
1509 | * Ignore errors, still want to process the | |
1510 | * other entries. | |
1511 | * | |
1512 | * For non standard branch modes always | |
1513 | * force no IPC (prev == NULL) | |
1514 | * | |
1515 | * Note that perf stores branches reversed from | |
1516 | * program order! | |
1517 | */ | |
1518 | for (i = bs->nr - 1; i >= 0; i--) { | |
1519 | addr_map_symbol__account_cycles(&bi[i].from, | |
1520 | nonany_branch_mode ? NULL : prev, | |
1521 | bi[i].flags.cycles); | |
1522 | prev = &bi[i].to; | |
1523 | } | |
1524 | free(bi); | |
1525 | } | |
1526 | } | |
1527 | } | |
2a1731fb ACM |
1528 | |
1529 | size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp) | |
1530 | { | |
1531 | struct perf_evsel *pos; | |
1532 | size_t ret = 0; | |
1533 | ||
1534 | evlist__for_each(evlist, pos) { | |
1535 | ret += fprintf(fp, "%s stats:\n", perf_evsel__name(pos)); | |
1536 | ret += events_stats__fprintf(&evsel__hists(pos)->stats, fp); | |
1537 | } | |
1538 | ||
1539 | return ret; | |
1540 | } | |
1541 | ||
1542 | ||
f2148330 NK |
1543 | u64 hists__total_period(struct hists *hists) |
1544 | { | |
1545 | return symbol_conf.filter_relative ? hists->stats.total_non_filtered_period : | |
1546 | hists->stats.total_period; | |
1547 | } | |
33db4568 NK |
1548 | |
1549 | int parse_filter_percentage(const struct option *opt __maybe_unused, | |
1550 | const char *arg, int unset __maybe_unused) | |
1551 | { | |
1552 | if (!strcmp(arg, "relative")) | |
1553 | symbol_conf.filter_relative = true; | |
1554 | else if (!strcmp(arg, "absolute")) | |
1555 | symbol_conf.filter_relative = false; | |
1556 | else | |
1557 | return -1; | |
1558 | ||
1559 | return 0; | |
1560 | } | |
0b93da17 NK |
1561 | |
1562 | int perf_hist_config(const char *var, const char *value) | |
1563 | { | |
1564 | if (!strcmp(var, "hist.percentage")) | |
1565 | return parse_filter_percentage(NULL, value, 0); | |
1566 | ||
1567 | return 0; | |
1568 | } | |
a635fc51 | 1569 | |
fc284be9 | 1570 | int __hists__init(struct hists *hists) |
a635fc51 | 1571 | { |
a635fc51 ACM |
1572 | memset(hists, 0, sizeof(*hists)); |
1573 | hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT; | |
1574 | hists->entries_in = &hists->entries_in_array[0]; | |
1575 | hists->entries_collapsed = RB_ROOT; | |
1576 | hists->entries = RB_ROOT; | |
1577 | pthread_mutex_init(&hists->lock, NULL); | |
21394d94 | 1578 | hists->socket_filter = -1; |
a635fc51 ACM |
1579 | return 0; |
1580 | } | |
1581 | ||
61fa0e94 NK |
1582 | static void hists__delete_remaining_entries(struct rb_root *root) |
1583 | { | |
1584 | struct rb_node *node; | |
1585 | struct hist_entry *he; | |
1586 | ||
1587 | while (!RB_EMPTY_ROOT(root)) { | |
1588 | node = rb_first(root); | |
1589 | rb_erase(node, root); | |
1590 | ||
1591 | he = rb_entry(node, struct hist_entry, rb_node_in); | |
1592 | hist_entry__delete(he); | |
1593 | } | |
1594 | } | |
1595 | ||
1596 | static void hists__delete_all_entries(struct hists *hists) | |
1597 | { | |
1598 | hists__delete_entries(hists); | |
1599 | hists__delete_remaining_entries(&hists->entries_in_array[0]); | |
1600 | hists__delete_remaining_entries(&hists->entries_in_array[1]); | |
1601 | hists__delete_remaining_entries(&hists->entries_collapsed); | |
1602 | } | |
1603 | ||
17577dec MH |
1604 | static void hists_evsel__exit(struct perf_evsel *evsel) |
1605 | { | |
1606 | struct hists *hists = evsel__hists(evsel); | |
1607 | ||
61fa0e94 | 1608 | hists__delete_all_entries(hists); |
17577dec MH |
1609 | } |
1610 | ||
fc284be9 NK |
1611 | static int hists_evsel__init(struct perf_evsel *evsel) |
1612 | { | |
1613 | struct hists *hists = evsel__hists(evsel); | |
1614 | ||
1615 | __hists__init(hists); | |
1616 | return 0; | |
1617 | } | |
1618 | ||
a635fc51 ACM |
1619 | /* |
1620 | * XXX We probably need a hists_evsel__exit() to free the hist_entries | |
1621 | * stored in the rbtree... | |
1622 | */ | |
1623 | ||
1624 | int hists__init(void) | |
1625 | { | |
1626 | int err = perf_evsel__object_config(sizeof(struct hists_evsel), | |
17577dec MH |
1627 | hists_evsel__init, |
1628 | hists_evsel__exit); | |
a635fc51 ACM |
1629 | if (err) |
1630 | fputs("FATAL ERROR: Couldn't setup hists class\n", stderr); | |
1631 | ||
1632 | return err; | |
1633 | } |