hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/tools/perf/util/hist.c
....@@ -1,22 +1,34 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-#include "util.h"
2
+#include "callchain.h"
3
+#include "debug.h"
4
+#include "dso.h"
35 #include "build-id.h"
46 #include "hist.h"
57 #include "map.h"
8
+#include "map_symbol.h"
9
+#include "branch.h"
10
+#include "mem-events.h"
611 #include "session.h"
712 #include "namespaces.h"
13
+#include "cgroup.h"
814 #include "sort.h"
915 #include "units.h"
1016 #include "evlist.h"
1117 #include "evsel.h"
1218 #include "annotate.h"
1319 #include "srcline.h"
20
+#include "symbol.h"
1421 #include "thread.h"
22
+#include "block-info.h"
1523 #include "ui/progress.h"
1624 #include <errno.h>
1725 #include <math.h>
1826 #include <inttypes.h>
1927 #include <sys/param.h>
28
+#include <linux/rbtree.h>
29
+#include <linux/string.h>
30
+#include <linux/time64.h>
31
+#include <linux/zalloc.h>
2032
2133 static bool hists__filter_entry_by_dso(struct hists *hists,
2234 struct hist_entry *he);
....@@ -70,6 +82,8 @@
7082 int symlen;
7183 u16 len;
7284
85
+ if (h->block_info)
86
+ return;
7387 /*
7488 * +4 accounts for '[x] ' priv level info
7589 * +2 accounts for 0x prefix on raw addresses
....@@ -99,13 +113,13 @@
99113 hists__new_col_len(hists, HISTC_PARENT, h->parent->namelen);
100114
101115 if (h->branch_info) {
102
- if (h->branch_info->from.sym) {
103
- symlen = (int)h->branch_info->from.sym->namelen + 4;
116
+ if (h->branch_info->from.ms.sym) {
117
+ symlen = (int)h->branch_info->from.ms.sym->namelen + 4;
104118 if (verbose > 0)
105119 symlen += BITS_PER_LONG / 4 + 2 + 3;
106120 hists__new_col_len(hists, HISTC_SYMBOL_FROM, symlen);
107121
108
- symlen = dso__name_len(h->branch_info->from.map->dso);
122
+ symlen = dso__name_len(h->branch_info->from.ms.map->dso);
109123 hists__new_col_len(hists, HISTC_DSO_FROM, symlen);
110124 } else {
111125 symlen = unresolved_col_width + 4 + 2;
....@@ -113,13 +127,13 @@
113127 hists__set_unres_dso_col_len(hists, HISTC_DSO_FROM);
114128 }
115129
116
- if (h->branch_info->to.sym) {
117
- symlen = (int)h->branch_info->to.sym->namelen + 4;
130
+ if (h->branch_info->to.ms.sym) {
131
+ symlen = (int)h->branch_info->to.ms.sym->namelen + 4;
118132 if (verbose > 0)
119133 symlen += BITS_PER_LONG / 4 + 2 + 3;
120134 hists__new_col_len(hists, HISTC_SYMBOL_TO, symlen);
121135
122
- symlen = dso__name_len(h->branch_info->to.map->dso);
136
+ symlen = dso__name_len(h->branch_info->to.ms.map->dso);
123137 hists__new_col_len(hists, HISTC_DSO_TO, symlen);
124138 } else {
125139 symlen = unresolved_col_width + 4 + 2;
....@@ -136,8 +150,8 @@
136150 }
137151
138152 if (h->mem_info) {
139
- if (h->mem_info->daddr.sym) {
140
- symlen = (int)h->mem_info->daddr.sym->namelen + 4
153
+ if (h->mem_info->daddr.ms.sym) {
154
+ symlen = (int)h->mem_info->daddr.ms.sym->namelen + 4
141155 + unresolved_col_width + 2;
142156 hists__new_col_len(hists, HISTC_MEM_DADDR_SYMBOL,
143157 symlen);
....@@ -151,8 +165,8 @@
151165 symlen);
152166 }
153167
154
- if (h->mem_info->iaddr.sym) {
155
- symlen = (int)h->mem_info->iaddr.sym->namelen + 4
168
+ if (h->mem_info->iaddr.ms.sym) {
169
+ symlen = (int)h->mem_info->iaddr.ms.sym->namelen + 4
156170 + unresolved_col_width + 2;
157171 hists__new_col_len(hists, HISTC_MEM_IADDR_SYMBOL,
158172 symlen);
....@@ -162,8 +176,8 @@
162176 symlen);
163177 }
164178
165
- if (h->mem_info->daddr.map) {
166
- symlen = dso__name_len(h->mem_info->daddr.map->dso);
179
+ if (h->mem_info->daddr.ms.map) {
180
+ symlen = dso__name_len(h->mem_info->daddr.ms.map->dso);
167181 hists__new_col_len(hists, HISTC_MEM_DADDR_DSO,
168182 symlen);
169183 } else {
....@@ -181,6 +195,7 @@
181195 hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
182196 }
183197
198
+ hists__new_col_len(hists, HISTC_CGROUP, 6);
184199 hists__new_col_len(hists, HISTC_CGROUP_ID, 20);
185200 hists__new_col_len(hists, HISTC_CPU, 3);
186201 hists__new_col_len(hists, HISTC_SOCKET, 6);
....@@ -190,6 +205,10 @@
190205 hists__new_col_len(hists, HISTC_MEM_LVL, 21 + 3);
191206 hists__new_col_len(hists, HISTC_LOCAL_WEIGHT, 12);
192207 hists__new_col_len(hists, HISTC_GLOBAL_WEIGHT, 12);
208
+ if (symbol_conf.nanosecs)
209
+ hists__new_col_len(hists, HISTC_TIME, 16);
210
+ else
211
+ hists__new_col_len(hists, HISTC_TIME, 12);
193212
194213 if (h->srcline) {
195214 len = MAX(strlen(h->srcline), strlen(sort_srcline.se_header));
....@@ -205,11 +224,21 @@
205224
206225 if (h->trace_output)
207226 hists__new_col_len(hists, HISTC_TRACE, strlen(h->trace_output));
227
+
228
+ if (h->cgroup) {
229
+ const char *cgrp_name = "unknown";
230
+ struct cgroup *cgrp = cgroup__find(h->ms.maps->machine->env,
231
+ h->cgroup);
232
+ if (cgrp != NULL)
233
+ cgrp_name = cgrp->name;
234
+
235
+ hists__new_col_len(hists, HISTC_CGROUP, strlen(cgrp_name));
236
+ }
208237 }
209238
210239 void hists__output_recalc_col_len(struct hists *hists, int max_rows)
211240 {
212
- struct rb_node *next = rb_first(&hists->entries);
241
+ struct rb_node *next = rb_first_cached(&hists->entries);
213242 struct hist_entry *n;
214243 int row = 0;
215244
....@@ -242,6 +271,14 @@
242271 default:
243272 break;
244273 }
274
+}
275
+
276
+static long hist_time(unsigned long htime)
277
+{
278
+ unsigned long time_quantum = symbol_conf.time_quantum;
279
+ if (time_quantum)
280
+ return (htime / time_quantum) * time_quantum;
281
+ return htime;
245282 }
246283
247284 static void he_stat__add_period(struct he_stat *he_stat, u64 period,
....@@ -296,7 +333,7 @@
296333
297334 if (!he->leaf) {
298335 struct hist_entry *child;
299
- struct rb_node *node = rb_first(&he->hroot_out);
336
+ struct rb_node *node = rb_first_cached(&he->hroot_out);
300337 while (node) {
301338 child = rb_entry(node, struct hist_entry, rb_node);
302339 node = rb_next(node);
....@@ -311,8 +348,8 @@
311348
312349 static void hists__delete_entry(struct hists *hists, struct hist_entry *he)
313350 {
314
- struct rb_root *root_in;
315
- struct rb_root *root_out;
351
+ struct rb_root_cached *root_in;
352
+ struct rb_root_cached *root_out;
316353
317354 if (he->parent_he) {
318355 root_in = &he->parent_he->hroot_in;
....@@ -325,8 +362,8 @@
325362 root_out = &hists->entries;
326363 }
327364
328
- rb_erase(&he->rb_node_in, root_in);
329
- rb_erase(&he->rb_node, root_out);
365
+ rb_erase_cached(&he->rb_node_in, root_in);
366
+ rb_erase_cached(&he->rb_node, root_out);
330367
331368 --hists->nr_entries;
332369 if (!he->filtered)
....@@ -337,7 +374,7 @@
337374
338375 void hists__decay_entries(struct hists *hists, bool zap_user, bool zap_kernel)
339376 {
340
- struct rb_node *next = rb_first(&hists->entries);
377
+ struct rb_node *next = rb_first_cached(&hists->entries);
341378 struct hist_entry *n;
342379
343380 while (next) {
....@@ -353,7 +390,7 @@
353390
354391 void hists__delete_entries(struct hists *hists)
355392 {
356
- struct rb_node *next = rb_first(&hists->entries);
393
+ struct rb_node *next = rb_first_cached(&hists->entries);
357394 struct hist_entry *n;
358395
359396 while (next) {
....@@ -362,6 +399,24 @@
362399
363400 hists__delete_entry(hists, n);
364401 }
402
+}
403
+
404
+struct hist_entry *hists__get_entry(struct hists *hists, int idx)
405
+{
406
+ struct rb_node *next = rb_first_cached(&hists->entries);
407
+ struct hist_entry *n;
408
+ int i = 0;
409
+
410
+ while (next) {
411
+ n = rb_entry(next, struct hist_entry, rb_node);
412
+ if (i == idx)
413
+ return n;
414
+
415
+ next = rb_next(&n->rb_node);
416
+ i++;
417
+ }
418
+
419
+ return NULL;
365420 }
366421
367422 /*
....@@ -394,22 +449,19 @@
394449 * adding new entries. So we need to save a copy.
395450 */
396451 he->branch_info = malloc(sizeof(*he->branch_info));
397
- if (he->branch_info == NULL) {
398
- map__zput(he->ms.map);
399
- free(he->stat_acc);
400
- return -ENOMEM;
401
- }
452
+ if (he->branch_info == NULL)
453
+ goto err;
402454
403455 memcpy(he->branch_info, template->branch_info,
404456 sizeof(*he->branch_info));
405457
406
- map__get(he->branch_info->from.map);
407
- map__get(he->branch_info->to.map);
458
+ map__get(he->branch_info->from.ms.map);
459
+ map__get(he->branch_info->to.ms.map);
408460 }
409461
410462 if (he->mem_info) {
411
- map__get(he->mem_info->iaddr.map);
412
- map__get(he->mem_info->daddr.map);
463
+ map__get(he->mem_info->iaddr.ms.map);
464
+ map__get(he->mem_info->daddr.ms.map);
413465 }
414466
415467 if (hist_entry__has_callchains(he) && symbol_conf.use_callchain)
....@@ -417,31 +469,53 @@
417469
418470 if (he->raw_data) {
419471 he->raw_data = memdup(he->raw_data, he->raw_size);
420
-
421
- if (he->raw_data == NULL) {
422
- map__put(he->ms.map);
423
- if (he->branch_info) {
424
- map__put(he->branch_info->from.map);
425
- map__put(he->branch_info->to.map);
426
- free(he->branch_info);
427
- }
428
- if (he->mem_info) {
429
- map__put(he->mem_info->iaddr.map);
430
- map__put(he->mem_info->daddr.map);
431
- }
432
- free(he->stat_acc);
433
- return -ENOMEM;
434
- }
472
+ if (he->raw_data == NULL)
473
+ goto err_infos;
435474 }
475
+
476
+ if (he->srcline) {
477
+ he->srcline = strdup(he->srcline);
478
+ if (he->srcline == NULL)
479
+ goto err_rawdata;
480
+ }
481
+
482
+ if (symbol_conf.res_sample) {
483
+ he->res_samples = calloc(sizeof(struct res_sample),
484
+ symbol_conf.res_sample);
485
+ if (!he->res_samples)
486
+ goto err_srcline;
487
+ }
488
+
436489 INIT_LIST_HEAD(&he->pairs.node);
437490 thread__get(he->thread);
438
- he->hroot_in = RB_ROOT;
439
- he->hroot_out = RB_ROOT;
491
+ he->hroot_in = RB_ROOT_CACHED;
492
+ he->hroot_out = RB_ROOT_CACHED;
440493
441494 if (!symbol_conf.report_hierarchy)
442495 he->leaf = true;
443496
444497 return 0;
498
+
499
+err_srcline:
500
+ zfree(&he->srcline);
501
+
502
+err_rawdata:
503
+ zfree(&he->raw_data);
504
+
505
+err_infos:
506
+ if (he->branch_info) {
507
+ map__put(he->branch_info->from.ms.map);
508
+ map__put(he->branch_info->to.ms.map);
509
+ zfree(&he->branch_info);
510
+ }
511
+ if (he->mem_info) {
512
+ map__put(he->mem_info->iaddr.ms.map);
513
+ map__put(he->mem_info->daddr.ms.map);
514
+ }
515
+err:
516
+ map__zput(he->ms.map);
517
+ zfree(&he->stat_acc);
518
+ return -ENOMEM;
445519 }
446520
447521 static void *hist_entry__zalloc(size_t size)
....@@ -513,8 +587,9 @@
513587 int64_t cmp;
514588 u64 period = entry->stat.period;
515589 u64 weight = entry->stat.weight;
590
+ bool leftmost = true;
516591
517
- p = &hists->entries_in->rb_node;
592
+ p = &hists->entries_in->rb_root.rb_node;
518593
519594 while (*p != NULL) {
520595 parent = *p;
....@@ -542,6 +617,8 @@
542617 */
543618 mem_info__zput(entry->mem_info);
544619
620
+ block_info__zput(entry->block_info);
621
+
545622 /* If the map of an existing hist_entry has
546623 * become out-of-date due to an exec() or
547624 * similar, update it. Otherwise we will
....@@ -557,8 +634,10 @@
557634
558635 if (cmp < 0)
559636 p = &(*p)->rb_left;
560
- else
637
+ else {
561638 p = &(*p)->rb_right;
639
+ leftmost = false;
640
+ }
562641 }
563642
564643 he = hist_entry__new(entry, sample_self);
....@@ -570,7 +649,7 @@
570649 hists->nr_entries++;
571650
572651 rb_link_node(&he->rb_node_in, parent, p);
573
- rb_insert_color(&he->rb_node_in, hists->entries_in);
652
+ rb_insert_color_cached(&he->rb_node_in, hists->entries_in, leftmost);
574653 out:
575654 if (sample_self)
576655 he_stat__add_cpumode_period(&he->stat, al->cpumode, period);
....@@ -579,12 +658,39 @@
579658 return he;
580659 }
581660
661
+static unsigned random_max(unsigned high)
662
+{
663
+ unsigned thresh = -high % high;
664
+ for (;;) {
665
+ unsigned r = random();
666
+ if (r >= thresh)
667
+ return r % high;
668
+ }
669
+}
670
+
671
+static void hists__res_sample(struct hist_entry *he, struct perf_sample *sample)
672
+{
673
+ struct res_sample *r;
674
+ int j;
675
+
676
+ if (he->num_res < symbol_conf.res_sample) {
677
+ j = he->num_res++;
678
+ } else {
679
+ j = random_max(symbol_conf.res_sample);
680
+ }
681
+ r = &he->res_samples[j];
682
+ r->time = sample->time;
683
+ r->cpu = sample->cpu;
684
+ r->tid = sample->tid;
685
+}
686
+
582687 static struct hist_entry*
583688 __hists__add_entry(struct hists *hists,
584689 struct addr_location *al,
585690 struct symbol *sym_parent,
586691 struct branch_info *bi,
587692 struct mem_info *mi,
693
+ struct block_info *block_info,
588694 struct perf_sample *sample,
589695 bool sample_self,
590696 struct hist_entry_ops *ops)
....@@ -597,11 +703,13 @@
597703 .dev = ns ? ns->link_info[CGROUP_NS_INDEX].dev : 0,
598704 .ino = ns ? ns->link_info[CGROUP_NS_INDEX].ino : 0,
599705 },
706
+ .cgroup = sample->cgroup,
600707 .ms = {
708
+ .maps = al->maps,
601709 .map = al->map,
602710 .sym = al->sym,
603711 },
604
- .srcline = al->srcline ? strdup(al->srcline) : NULL,
712
+ .srcline = (char *) al->srcline,
605713 .socket = al->socket,
606714 .cpu = al->cpu,
607715 .cpumode = al->cpumode,
....@@ -617,14 +725,18 @@
617725 .hists = hists,
618726 .branch_info = bi,
619727 .mem_info = mi,
728
+ .block_info = block_info,
620729 .transaction = sample->transaction,
621730 .raw_data = sample->raw_data,
622731 .raw_size = sample->raw_size,
623732 .ops = ops,
733
+ .time = hist_time(sample->time),
624734 }, *he = hists__findnew_entry(hists, &entry, al, sample_self);
625735
626736 if (!hists->has_callchains && he && he->callchain_size != 0)
627737 hists->has_callchains = true;
738
+ if (he && symbol_conf.res_sample)
739
+ hists__res_sample(he, sample);
628740 return he;
629741 }
630742
....@@ -636,7 +748,7 @@
636748 struct perf_sample *sample,
637749 bool sample_self)
638750 {
639
- return __hists__add_entry(hists, al, sym_parent, bi, mi,
751
+ return __hists__add_entry(hists, al, sym_parent, bi, mi, NULL,
640752 sample, sample_self, NULL);
641753 }
642754
....@@ -649,8 +761,25 @@
649761 struct perf_sample *sample,
650762 bool sample_self)
651763 {
652
- return __hists__add_entry(hists, al, sym_parent, bi, mi,
764
+ return __hists__add_entry(hists, al, sym_parent, bi, mi, NULL,
653765 sample, sample_self, ops);
766
+}
767
+
768
+struct hist_entry *hists__add_entry_block(struct hists *hists,
769
+ struct addr_location *al,
770
+ struct block_info *block_info)
771
+{
772
+ struct hist_entry entry = {
773
+ .block_info = block_info,
774
+ .hists = hists,
775
+ .ms = {
776
+ .maps = al->maps,
777
+ .map = al->map,
778
+ .sym = al->sym,
779
+ },
780
+ }, *he = hists__findnew_entry(hists, &entry, al, false);
781
+
782
+ return he;
654783 }
655784
656785 static int
....@@ -719,7 +848,7 @@
719848 iter_finish_mem_entry(struct hist_entry_iter *iter,
720849 struct addr_location *al __maybe_unused)
721850 {
722
- struct perf_evsel *evsel = iter->evsel;
851
+ struct evsel *evsel = iter->evsel;
723852 struct hists *hists = evsel__hists(evsel);
724853 struct hist_entry *he = iter->he;
725854 int err = -EINVAL;
....@@ -779,8 +908,9 @@
779908 if (iter->curr >= iter->total)
780909 return 0;
781910
782
- al->map = bi[i].to.map;
783
- al->sym = bi[i].to.sym;
911
+ al->maps = bi[i].to.ms.maps;
912
+ al->map = bi[i].to.ms.map;
913
+ al->sym = bi[i].to.ms.sym;
784914 al->addr = bi[i].to.addr;
785915 return 1;
786916 }
....@@ -789,7 +919,7 @@
789919 iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *al)
790920 {
791921 struct branch_info *bi;
792
- struct perf_evsel *evsel = iter->evsel;
922
+ struct evsel *evsel = iter->evsel;
793923 struct hists *hists = evsel__hists(evsel);
794924 struct perf_sample *sample = iter->sample;
795925 struct hist_entry *he = NULL;
....@@ -798,7 +928,7 @@
798928
799929 bi = iter->priv;
800930
801
- if (iter->hide_unresolved && !(bi[i].from.sym && bi[i].to.sym))
931
+ if (iter->hide_unresolved && !(bi[i].from.ms.sym && bi[i].to.ms.sym))
802932 goto out;
803933
804934 /*
....@@ -841,7 +971,7 @@
841971 static int
842972 iter_add_single_normal_entry(struct hist_entry_iter *iter, struct addr_location *al)
843973 {
844
- struct perf_evsel *evsel = iter->evsel;
974
+ struct evsel *evsel = iter->evsel;
845975 struct perf_sample *sample = iter->sample;
846976 struct hist_entry *he;
847977
....@@ -859,7 +989,7 @@
859989 struct addr_location *al __maybe_unused)
860990 {
861991 struct hist_entry *he = iter->he;
862
- struct perf_evsel *evsel = iter->evsel;
992
+ struct evsel *evsel = iter->evsel;
863993 struct perf_sample *sample = iter->sample;
864994
865995 if (he == NULL)
....@@ -899,7 +1029,7 @@
8991029 iter_add_single_cumulative_entry(struct hist_entry_iter *iter,
9001030 struct addr_location *al)
9011031 {
902
- struct perf_evsel *evsel = iter->evsel;
1032
+ struct evsel *evsel = iter->evsel;
9031033 struct hists *hists = evsel__hists(evsel);
9041034 struct perf_sample *sample = iter->sample;
9051035 struct hist_entry **he_cache = iter->priv;
....@@ -940,11 +1070,25 @@
9401070 return fill_callchain_info(al, node, iter->hide_unresolved);
9411071 }
9421072
1073
+static bool
1074
+hist_entry__fast__sym_diff(struct hist_entry *left,
1075
+ struct hist_entry *right)
1076
+{
1077
+ struct symbol *sym_l = left->ms.sym;
1078
+ struct symbol *sym_r = right->ms.sym;
1079
+
1080
+ if (!sym_l && !sym_r)
1081
+ return left->ip != right->ip;
1082
+
1083
+ return !!_sort__sym_cmp(sym_l, sym_r);
1084
+}
1085
+
1086
+
9431087 static int
9441088 iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
9451089 struct addr_location *al)
9461090 {
947
- struct perf_evsel *evsel = iter->evsel;
1091
+ struct evsel *evsel = iter->evsel;
9481092 struct perf_sample *sample = iter->sample;
9491093 struct hist_entry **he_cache = iter->priv;
9501094 struct hist_entry *he;
....@@ -955,16 +1099,18 @@
9551099 .comm = thread__comm(al->thread),
9561100 .ip = al->addr,
9571101 .ms = {
1102
+ .maps = al->maps,
9581103 .map = al->map,
9591104 .sym = al->sym,
9601105 },
961
- .srcline = al->srcline ? strdup(al->srcline) : NULL,
1106
+ .srcline = (char *) al->srcline,
9621107 .parent = iter->parent,
9631108 .raw_data = sample->raw_data,
9641109 .raw_size = sample->raw_size,
9651110 };
9661111 int i;
9671112 struct callchain_cursor cursor;
1113
+ bool fast = hists__has(he_tmp.hists, sym);
9681114
9691115 callchain_cursor_snapshot(&cursor, &callchain_cursor);
9701116
....@@ -975,6 +1121,14 @@
9751121 * It's possible that it has cycles or recursive calls.
9761122 */
9771123 for (i = 0; i < iter->curr; i++) {
1124
+ /*
1125
+ * For most cases, there are no duplicate entries in callchain.
1126
+ * The symbols are usually different. Do a quick check for
1127
+ * symbols first.
1128
+ */
1129
+ if (fast && hist_entry__fast__sym_diff(he_cache[i], &he_tmp))
1130
+ continue;
1131
+
9781132 if (hist_entry__cmp(he_cache[i], &he_tmp) == 0) {
9791133 /* to avoid calling callback function */
9801134 iter->he = NULL;
....@@ -1137,32 +1291,36 @@
11371291 map__zput(he->ms.map);
11381292
11391293 if (he->branch_info) {
1140
- map__zput(he->branch_info->from.map);
1141
- map__zput(he->branch_info->to.map);
1294
+ map__zput(he->branch_info->from.ms.map);
1295
+ map__zput(he->branch_info->to.ms.map);
11421296 free_srcline(he->branch_info->srcline_from);
11431297 free_srcline(he->branch_info->srcline_to);
11441298 zfree(&he->branch_info);
11451299 }
11461300
11471301 if (he->mem_info) {
1148
- map__zput(he->mem_info->iaddr.map);
1149
- map__zput(he->mem_info->daddr.map);
1302
+ map__zput(he->mem_info->iaddr.ms.map);
1303
+ map__zput(he->mem_info->daddr.ms.map);
11501304 mem_info__zput(he->mem_info);
11511305 }
11521306
1307
+ if (he->block_info)
1308
+ block_info__zput(he->block_info);
1309
+
1310
+ zfree(&he->res_samples);
11531311 zfree(&he->stat_acc);
11541312 free_srcline(he->srcline);
11551313 if (he->srcfile && he->srcfile[0])
1156
- free(he->srcfile);
1314
+ zfree(&he->srcfile);
11571315 free_callchain(he->callchain);
1158
- free(he->trace_output);
1159
- free(he->raw_data);
1316
+ zfree(&he->trace_output);
1317
+ zfree(&he->raw_data);
11601318 ops->free(he);
11611319 }
11621320
11631321 /*
11641322 * If this is not the last column, then we need to pad it according to the
1165
- * pre-calculated max lenght for this column, otherwise don't bother adding
1323
+ * pre-calculated max length for this column, otherwise don't bother adding
11661324 * spaces because that would break viewing this with, for instance, 'less',
11671325 * that would show tons of trailing spaces when a long C++ demangled method
11681326 * names is sampled.
....@@ -1281,16 +1439,17 @@
12811439 }
12821440
12831441 static struct hist_entry *hierarchy_insert_entry(struct hists *hists,
1284
- struct rb_root *root,
1442
+ struct rb_root_cached *root,
12851443 struct hist_entry *he,
12861444 struct hist_entry *parent_he,
12871445 struct perf_hpp_list *hpp_list)
12881446 {
1289
- struct rb_node **p = &root->rb_node;
1447
+ struct rb_node **p = &root->rb_root.rb_node;
12901448 struct rb_node *parent = NULL;
12911449 struct hist_entry *iter, *new;
12921450 struct perf_hpp_fmt *fmt;
12931451 int64_t cmp;
1452
+ bool leftmost = true;
12941453
12951454 while (*p != NULL) {
12961455 parent = *p;
....@@ -1310,8 +1469,10 @@
13101469
13111470 if (cmp < 0)
13121471 p = &parent->rb_left;
1313
- else
1472
+ else {
13141473 p = &parent->rb_right;
1474
+ leftmost = false;
1475
+ }
13151476 }
13161477
13171478 new = hist_entry__new(he, true);
....@@ -1345,12 +1506,12 @@
13451506 }
13461507
13471508 rb_link_node(&new->rb_node_in, parent, p);
1348
- rb_insert_color(&new->rb_node_in, root);
1509
+ rb_insert_color_cached(&new->rb_node_in, root, leftmost);
13491510 return new;
13501511 }
13511512
13521513 static int hists__hierarchy_insert_entry(struct hists *hists,
1353
- struct rb_root *root,
1514
+ struct rb_root_cached *root,
13541515 struct hist_entry *he)
13551516 {
13561517 struct perf_hpp_list_node *node;
....@@ -1397,13 +1558,14 @@
13971558 }
13981559
13991560 static int hists__collapse_insert_entry(struct hists *hists,
1400
- struct rb_root *root,
1561
+ struct rb_root_cached *root,
14011562 struct hist_entry *he)
14021563 {
1403
- struct rb_node **p = &root->rb_node;
1564
+ struct rb_node **p = &root->rb_root.rb_node;
14041565 struct rb_node *parent = NULL;
14051566 struct hist_entry *iter;
14061567 int64_t cmp;
1568
+ bool leftmost = true;
14071569
14081570 if (symbol_conf.report_hierarchy)
14091571 return hists__hierarchy_insert_entry(hists, root, he);
....@@ -1434,19 +1596,21 @@
14341596
14351597 if (cmp < 0)
14361598 p = &(*p)->rb_left;
1437
- else
1599
+ else {
14381600 p = &(*p)->rb_right;
1601
+ leftmost = false;
1602
+ }
14391603 }
14401604 hists->nr_entries++;
14411605
14421606 rb_link_node(&he->rb_node_in, parent, p);
1443
- rb_insert_color(&he->rb_node_in, root);
1607
+ rb_insert_color_cached(&he->rb_node_in, root, leftmost);
14441608 return 1;
14451609 }
14461610
1447
-struct rb_root *hists__get_rotate_entries_in(struct hists *hists)
1611
+struct rb_root_cached *hists__get_rotate_entries_in(struct hists *hists)
14481612 {
1449
- struct rb_root *root;
1613
+ struct rb_root_cached *root;
14501614
14511615 pthread_mutex_lock(&hists->lock);
14521616
....@@ -1469,7 +1633,7 @@
14691633
14701634 int hists__collapse_resort(struct hists *hists, struct ui_progress *prog)
14711635 {
1472
- struct rb_root *root;
1636
+ struct rb_root_cached *root;
14731637 struct rb_node *next;
14741638 struct hist_entry *n;
14751639 int ret;
....@@ -1481,7 +1645,7 @@
14811645
14821646 root = hists__get_rotate_entries_in(hists);
14831647
1484
- next = rb_first(root);
1648
+ next = rb_first_cached(root);
14851649
14861650 while (next) {
14871651 if (session_done())
....@@ -1489,7 +1653,7 @@
14891653 n = rb_entry(next, struct hist_entry, rb_node_in);
14901654 next = rb_next(&n->rb_node_in);
14911655
1492
- rb_erase(&n->rb_node_in, root);
1656
+ rb_erase_cached(&n->rb_node_in, root);
14931657 ret = hists__collapse_insert_entry(hists, &hists->entries_collapsed, n);
14941658 if (ret < 0)
14951659 return -1;
....@@ -1560,7 +1724,7 @@
15601724 struct rb_node *node;
15611725 struct hist_entry *he;
15621726
1563
- node = rb_first(&hists->entries);
1727
+ node = rb_first_cached(&hists->entries);
15641728
15651729 hists->stats.total_period = 0;
15661730 hists->stats.total_non_filtered_period = 0;
....@@ -1580,13 +1744,14 @@
15801744 }
15811745 }
15821746
1583
-static void hierarchy_insert_output_entry(struct rb_root *root,
1747
+static void hierarchy_insert_output_entry(struct rb_root_cached *root,
15841748 struct hist_entry *he)
15851749 {
1586
- struct rb_node **p = &root->rb_node;
1750
+ struct rb_node **p = &root->rb_root.rb_node;
15871751 struct rb_node *parent = NULL;
15881752 struct hist_entry *iter;
15891753 struct perf_hpp_fmt *fmt;
1754
+ bool leftmost = true;
15901755
15911756 while (*p != NULL) {
15921757 parent = *p;
....@@ -1594,12 +1759,14 @@
15941759
15951760 if (hist_entry__sort(he, iter) > 0)
15961761 p = &parent->rb_left;
1597
- else
1762
+ else {
15981763 p = &parent->rb_right;
1764
+ leftmost = false;
1765
+ }
15991766 }
16001767
16011768 rb_link_node(&he->rb_node, parent, p);
1602
- rb_insert_color(&he->rb_node, root);
1769
+ rb_insert_color_cached(&he->rb_node, root, leftmost);
16031770
16041771 /* update column width of dynamic entry */
16051772 perf_hpp_list__for_each_sort_list(he->hpp_list, fmt) {
....@@ -1610,16 +1777,16 @@
16101777
16111778 static void hists__hierarchy_output_resort(struct hists *hists,
16121779 struct ui_progress *prog,
1613
- struct rb_root *root_in,
1614
- struct rb_root *root_out,
1780
+ struct rb_root_cached *root_in,
1781
+ struct rb_root_cached *root_out,
16151782 u64 min_callchain_hits,
16161783 bool use_callchain)
16171784 {
16181785 struct rb_node *node;
16191786 struct hist_entry *he;
16201787
1621
- *root_out = RB_ROOT;
1622
- node = rb_first(root_in);
1788
+ *root_out = RB_ROOT_CACHED;
1789
+ node = rb_first_cached(root_in);
16231790
16241791 while (node) {
16251792 he = rb_entry(node, struct hist_entry, rb_node_in);
....@@ -1662,15 +1829,16 @@
16621829 }
16631830 }
16641831
1665
-static void __hists__insert_output_entry(struct rb_root *entries,
1832
+static void __hists__insert_output_entry(struct rb_root_cached *entries,
16661833 struct hist_entry *he,
16671834 u64 min_callchain_hits,
16681835 bool use_callchain)
16691836 {
1670
- struct rb_node **p = &entries->rb_node;
1837
+ struct rb_node **p = &entries->rb_root.rb_node;
16711838 struct rb_node *parent = NULL;
16721839 struct hist_entry *iter;
16731840 struct perf_hpp_fmt *fmt;
1841
+ bool leftmost = true;
16741842
16751843 if (use_callchain) {
16761844 if (callchain_param.mode == CHAIN_GRAPH_REL) {
....@@ -1691,12 +1859,14 @@
16911859
16921860 if (hist_entry__sort(he, iter) > 0)
16931861 p = &(*p)->rb_left;
1694
- else
1862
+ else {
16951863 p = &(*p)->rb_right;
1864
+ leftmost = false;
1865
+ }
16961866 }
16971867
16981868 rb_link_node(&he->rb_node, parent, p);
1699
- rb_insert_color(&he->rb_node, entries);
1869
+ rb_insert_color_cached(&he->rb_node, entries, leftmost);
17001870
17011871 perf_hpp_list__for_each_sort_list(&perf_hpp_list, fmt) {
17021872 if (perf_hpp__is_dynamic_entry(fmt) &&
....@@ -1706,9 +1876,10 @@
17061876 }
17071877
17081878 static void output_resort(struct hists *hists, struct ui_progress *prog,
1709
- bool use_callchain, hists__resort_cb_t cb)
1879
+ bool use_callchain, hists__resort_cb_t cb,
1880
+ void *cb_arg)
17101881 {
1711
- struct rb_root *root;
1882
+ struct rb_root_cached *root;
17121883 struct rb_node *next;
17131884 struct hist_entry *n;
17141885 u64 callchain_total;
....@@ -1738,14 +1909,14 @@
17381909 else
17391910 root = hists->entries_in;
17401911
1741
- next = rb_first(root);
1742
- hists->entries = RB_ROOT;
1912
+ next = rb_first_cached(root);
1913
+ hists->entries = RB_ROOT_CACHED;
17431914
17441915 while (next) {
17451916 n = rb_entry(next, struct hist_entry, rb_node_in);
17461917 next = rb_next(&n->rb_node_in);
17471918
1748
- if (cb && cb(n))
1919
+ if (cb && cb(n, cb_arg))
17491920 continue;
17501921
17511922 __hists__insert_output_entry(&hists->entries, n, min_callchain_hits, use_callchain);
....@@ -1759,7 +1930,8 @@
17591930 }
17601931 }
17611932
1762
-void perf_evsel__output_resort(struct perf_evsel *evsel, struct ui_progress *prog)
1933
+void evsel__output_resort_cb(struct evsel *evsel, struct ui_progress *prog,
1934
+ hists__resort_cb_t cb, void *cb_arg)
17631935 {
17641936 bool use_callchain;
17651937
....@@ -1770,18 +1942,23 @@
17701942
17711943 use_callchain |= symbol_conf.show_branchflag_count;
17721944
1773
- output_resort(evsel__hists(evsel), prog, use_callchain, NULL);
1945
+ output_resort(evsel__hists(evsel), prog, use_callchain, cb, cb_arg);
1946
+}
1947
+
1948
+void evsel__output_resort(struct evsel *evsel, struct ui_progress *prog)
1949
+{
1950
+ return evsel__output_resort_cb(evsel, prog, NULL, NULL);
17741951 }
17751952
17761953 void hists__output_resort(struct hists *hists, struct ui_progress *prog)
17771954 {
1778
- output_resort(hists, prog, symbol_conf.use_callchain, NULL);
1955
+ output_resort(hists, prog, symbol_conf.use_callchain, NULL, NULL);
17791956 }
17801957
17811958 void hists__output_resort_cb(struct hists *hists, struct ui_progress *prog,
17821959 hists__resort_cb_t cb)
17831960 {
1784
- output_resort(hists, prog, symbol_conf.use_callchain, cb);
1961
+ output_resort(hists, prog, symbol_conf.use_callchain, cb, NULL);
17851962 }
17861963
17871964 static bool can_goto_child(struct hist_entry *he, enum hierarchy_move_dir hmd)
....@@ -1800,7 +1977,7 @@
18001977 struct hist_entry *he = rb_entry(node, struct hist_entry, rb_node);
18011978
18021979 while (can_goto_child(he, HMD_NORMAL)) {
1803
- node = rb_last(&he->hroot_out);
1980
+ node = rb_last(&he->hroot_out.rb_root);
18041981 he = rb_entry(node, struct hist_entry, rb_node);
18051982 }
18061983 return node;
....@@ -1811,7 +1988,7 @@
18111988 struct hist_entry *he = rb_entry(node, struct hist_entry, rb_node);
18121989
18131990 if (can_goto_child(he, hmd))
1814
- node = rb_first(&he->hroot_out);
1991
+ node = rb_first_cached(&he->hroot_out);
18151992 else
18161993 node = rb_next(node);
18171994
....@@ -1849,7 +2026,7 @@
18492026 if (he->leaf)
18502027 return false;
18512028
1852
- node = rb_first(&he->hroot_out);
2029
+ node = rb_first_cached(&he->hroot_out);
18532030 child = rb_entry(node, struct hist_entry, rb_node);
18542031
18552032 while (node && child->filtered) {
....@@ -1967,7 +2144,7 @@
19672144 hists__reset_filter_stats(hists);
19682145 hists__reset_col_len(hists);
19692146
1970
- for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
2147
+ for (nd = rb_first_cached(&hists->entries); nd; nd = rb_next(nd)) {
19712148 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
19722149
19732150 if (filter(hists, h))
....@@ -1977,13 +2154,15 @@
19772154 }
19782155 }
19792156
1980
-static void resort_filtered_entry(struct rb_root *root, struct hist_entry *he)
2157
+static void resort_filtered_entry(struct rb_root_cached *root,
2158
+ struct hist_entry *he)
19812159 {
1982
- struct rb_node **p = &root->rb_node;
2160
+ struct rb_node **p = &root->rb_root.rb_node;
19832161 struct rb_node *parent = NULL;
19842162 struct hist_entry *iter;
1985
- struct rb_root new_root = RB_ROOT;
2163
+ struct rb_root_cached new_root = RB_ROOT_CACHED;
19862164 struct rb_node *nd;
2165
+ bool leftmost = true;
19872166
19882167 while (*p != NULL) {
19892168 parent = *p;
....@@ -1991,22 +2170,24 @@
19912170
19922171 if (hist_entry__sort(he, iter) > 0)
19932172 p = &(*p)->rb_left;
1994
- else
2173
+ else {
19952174 p = &(*p)->rb_right;
2175
+ leftmost = false;
2176
+ }
19962177 }
19972178
19982179 rb_link_node(&he->rb_node, parent, p);
1999
- rb_insert_color(&he->rb_node, root);
2180
+ rb_insert_color_cached(&he->rb_node, root, leftmost);
20002181
20012182 if (he->leaf || he->filtered)
20022183 return;
20032184
2004
- nd = rb_first(&he->hroot_out);
2185
+ nd = rb_first_cached(&he->hroot_out);
20052186 while (nd) {
20062187 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
20072188
20082189 nd = rb_next(nd);
2009
- rb_erase(&h->rb_node, &he->hroot_out);
2190
+ rb_erase_cached(&h->rb_node, &he->hroot_out);
20102191
20112192 resort_filtered_entry(&new_root, h);
20122193 }
....@@ -2017,14 +2198,14 @@
20172198 static void hists__filter_hierarchy(struct hists *hists, int type, const void *arg)
20182199 {
20192200 struct rb_node *nd;
2020
- struct rb_root new_root = RB_ROOT;
2201
+ struct rb_root_cached new_root = RB_ROOT_CACHED;
20212202
20222203 hists->stats.nr_non_filtered_samples = 0;
20232204
20242205 hists__reset_filter_stats(hists);
20252206 hists__reset_col_len(hists);
20262207
2027
- nd = rb_first(&hists->entries);
2208
+ nd = rb_first_cached(&hists->entries);
20282209 while (nd) {
20292210 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
20302211 int ret;
....@@ -2068,12 +2249,12 @@
20682249 * resort output after applying a new filter since filter in a lower
20692250 * hierarchy can change periods in a upper hierarchy.
20702251 */
2071
- nd = rb_first(&hists->entries);
2252
+ nd = rb_first_cached(&hists->entries);
20722253 while (nd) {
20732254 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
20742255
20752256 nd = rb_next(nd);
2076
- rb_erase(&h->rb_node, &hists->entries);
2257
+ rb_erase_cached(&h->rb_node, &hists->entries);
20772258
20782259 resort_filtered_entry(&new_root, h);
20792260 }
....@@ -2142,18 +2323,19 @@
21422323 static struct hist_entry *hists__add_dummy_entry(struct hists *hists,
21432324 struct hist_entry *pair)
21442325 {
2145
- struct rb_root *root;
2326
+ struct rb_root_cached *root;
21462327 struct rb_node **p;
21472328 struct rb_node *parent = NULL;
21482329 struct hist_entry *he;
21492330 int64_t cmp;
2331
+ bool leftmost = true;
21502332
21512333 if (hists__has(hists, need_collapse))
21522334 root = &hists->entries_collapsed;
21532335 else
21542336 root = hists->entries_in;
21552337
2156
- p = &root->rb_node;
2338
+ p = &root->rb_root.rb_node;
21572339
21582340 while (*p != NULL) {
21592341 parent = *p;
....@@ -2166,8 +2348,10 @@
21662348
21672349 if (cmp < 0)
21682350 p = &(*p)->rb_left;
2169
- else
2351
+ else {
21702352 p = &(*p)->rb_right;
2353
+ leftmost = false;
2354
+ }
21712355 }
21722356
21732357 he = hist_entry__new(pair, true);
....@@ -2177,7 +2361,7 @@
21772361 if (symbol_conf.cumulate_callchain)
21782362 memset(he->stat_acc, 0, sizeof(he->stat));
21792363 rb_link_node(&he->rb_node_in, parent, p);
2180
- rb_insert_color(&he->rb_node_in, root);
2364
+ rb_insert_color_cached(&he->rb_node_in, root, leftmost);
21812365 hists__inc_stats(hists, he);
21822366 he->dummy = true;
21832367 }
....@@ -2186,15 +2370,16 @@
21862370 }
21872371
21882372 static struct hist_entry *add_dummy_hierarchy_entry(struct hists *hists,
2189
- struct rb_root *root,
2373
+ struct rb_root_cached *root,
21902374 struct hist_entry *pair)
21912375 {
21922376 struct rb_node **p;
21932377 struct rb_node *parent = NULL;
21942378 struct hist_entry *he;
21952379 struct perf_hpp_fmt *fmt;
2380
+ bool leftmost = true;
21962381
2197
- p = &root->rb_node;
2382
+ p = &root->rb_root.rb_node;
21982383 while (*p != NULL) {
21992384 int64_t cmp = 0;
22002385
....@@ -2211,14 +2396,16 @@
22112396
22122397 if (cmp < 0)
22132398 p = &parent->rb_left;
2214
- else
2399
+ else {
22152400 p = &parent->rb_right;
2401
+ leftmost = false;
2402
+ }
22162403 }
22172404
22182405 he = hist_entry__new(pair, true);
22192406 if (he) {
22202407 rb_link_node(&he->rb_node_in, parent, p);
2221
- rb_insert_color(&he->rb_node_in, root);
2408
+ rb_insert_color_cached(&he->rb_node_in, root, leftmost);
22222409
22232410 he->dummy = true;
22242411 he->hists = hists;
....@@ -2235,9 +2422,9 @@
22352422 struct rb_node *n;
22362423
22372424 if (hists__has(hists, need_collapse))
2238
- n = hists->entries_collapsed.rb_node;
2425
+ n = hists->entries_collapsed.rb_root.rb_node;
22392426 else
2240
- n = hists->entries_in->rb_node;
2427
+ n = hists->entries_in->rb_root.rb_node;
22412428
22422429 while (n) {
22432430 struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node_in);
....@@ -2254,10 +2441,10 @@
22542441 return NULL;
22552442 }
22562443
2257
-static struct hist_entry *hists__find_hierarchy_entry(struct rb_root *root,
2444
+static struct hist_entry *hists__find_hierarchy_entry(struct rb_root_cached *root,
22582445 struct hist_entry *he)
22592446 {
2260
- struct rb_node *n = root->rb_node;
2447
+ struct rb_node *n = root->rb_root.rb_node;
22612448
22622449 while (n) {
22632450 struct hist_entry *iter;
....@@ -2282,13 +2469,13 @@
22822469 return NULL;
22832470 }
22842471
2285
-static void hists__match_hierarchy(struct rb_root *leader_root,
2286
- struct rb_root *other_root)
2472
+static void hists__match_hierarchy(struct rb_root_cached *leader_root,
2473
+ struct rb_root_cached *other_root)
22872474 {
22882475 struct rb_node *nd;
22892476 struct hist_entry *pos, *pair;
22902477
2291
- for (nd = rb_first(leader_root); nd; nd = rb_next(nd)) {
2478
+ for (nd = rb_first_cached(leader_root); nd; nd = rb_next(nd)) {
22922479 pos = rb_entry(nd, struct hist_entry, rb_node_in);
22932480 pair = hists__find_hierarchy_entry(other_root, pos);
22942481
....@@ -2304,7 +2491,7 @@
23042491 */
23052492 void hists__match(struct hists *leader, struct hists *other)
23062493 {
2307
- struct rb_root *root;
2494
+ struct rb_root_cached *root;
23082495 struct rb_node *nd;
23092496 struct hist_entry *pos, *pair;
23102497
....@@ -2319,7 +2506,7 @@
23192506 else
23202507 root = leader->entries_in;
23212508
2322
- for (nd = rb_first(root); nd; nd = rb_next(nd)) {
2509
+ for (nd = rb_first_cached(root); nd; nd = rb_next(nd)) {
23232510 pos = rb_entry(nd, struct hist_entry, rb_node_in);
23242511 pair = hists__find_entry(other, pos);
23252512
....@@ -2330,13 +2517,13 @@
23302517
23312518 static int hists__link_hierarchy(struct hists *leader_hists,
23322519 struct hist_entry *parent,
2333
- struct rb_root *leader_root,
2334
- struct rb_root *other_root)
2520
+ struct rb_root_cached *leader_root,
2521
+ struct rb_root_cached *other_root)
23352522 {
23362523 struct rb_node *nd;
23372524 struct hist_entry *pos, *leader;
23382525
2339
- for (nd = rb_first(other_root); nd; nd = rb_next(nd)) {
2526
+ for (nd = rb_first_cached(other_root); nd; nd = rb_next(nd)) {
23402527 pos = rb_entry(nd, struct hist_entry, rb_node_in);
23412528
23422529 if (hist_entry__has_pairs(pos)) {
....@@ -2379,7 +2566,7 @@
23792566 */
23802567 int hists__link(struct hists *leader, struct hists *other)
23812568 {
2382
- struct rb_root *root;
2569
+ struct rb_root_cached *root;
23832570 struct rb_node *nd;
23842571 struct hist_entry *pos, *pair;
23852572
....@@ -2395,7 +2582,7 @@
23952582 else
23962583 root = other->entries_in;
23972584
2398
- for (nd = rb_first(root); nd; nd = rb_next(nd)) {
2585
+ for (nd = rb_first_cached(root); nd; nd = rb_next(nd)) {
23992586 pos = rb_entry(nd, struct hist_entry, rb_node_in);
24002587
24012588 if (!hist_entry__has_pairs(pos)) {
....@@ -2409,13 +2596,34 @@
24092596 return 0;
24102597 }
24112598
2599
+int hists__unlink(struct hists *hists)
2600
+{
2601
+ struct rb_root_cached *root;
2602
+ struct rb_node *nd;
2603
+ struct hist_entry *pos;
2604
+
2605
+ if (hists__has(hists, need_collapse))
2606
+ root = &hists->entries_collapsed;
2607
+ else
2608
+ root = hists->entries_in;
2609
+
2610
+ for (nd = rb_first_cached(root); nd; nd = rb_next(nd)) {
2611
+ pos = rb_entry(nd, struct hist_entry, rb_node_in);
2612
+ list_del_init(&pos->pairs.node);
2613
+ }
2614
+
2615
+ return 0;
2616
+}
2617
+
24122618 void hist__account_cycles(struct branch_stack *bs, struct addr_location *al,
2413
- struct perf_sample *sample, bool nonany_branch_mode)
2619
+ struct perf_sample *sample, bool nonany_branch_mode,
2620
+ u64 *total_cycles)
24142621 {
24152622 struct branch_info *bi;
2623
+ struct branch_entry *entries = perf_sample__branch_entries(sample);
24162624
24172625 /* If we have branch cycles always annotate them. */
2418
- if (bs && bs->nr && bs->entries[0].flags.cycles) {
2626
+ if (bs && bs->nr && entries[0].flags.cycles) {
24192627 int i;
24202628
24212629 bi = sample__resolve_bstack(sample, al);
....@@ -2437,19 +2645,22 @@
24372645 nonany_branch_mode ? NULL : prev,
24382646 bi[i].flags.cycles);
24392647 prev = &bi[i].to;
2648
+
2649
+ if (total_cycles)
2650
+ *total_cycles += bi[i].flags.cycles;
24402651 }
24412652 free(bi);
24422653 }
24432654 }
24442655 }
24452656
2446
-size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp)
2657
+size_t perf_evlist__fprintf_nr_events(struct evlist *evlist, FILE *fp)
24472658 {
2448
- struct perf_evsel *pos;
2659
+ struct evsel *pos;
24492660 size_t ret = 0;
24502661
24512662 evlist__for_each_entry(evlist, pos) {
2452
- ret += fprintf(fp, "%s stats:\n", perf_evsel__name(pos));
2663
+ ret += fprintf(fp, "%s stats:\n", evsel__name(pos));
24532664 ret += events_stats__fprintf(&evsel__hists(pos)->stats, fp);
24542665 }
24552666
....@@ -2468,12 +2679,12 @@
24682679 char unit;
24692680 int printed;
24702681 const struct dso *dso = hists->dso_filter;
2471
- const struct thread *thread = hists->thread_filter;
2682
+ struct thread *thread = hists->thread_filter;
24722683 int socket_id = hists->socket_filter;
24732684 unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
24742685 u64 nr_events = hists->stats.total_period;
2475
- struct perf_evsel *evsel = hists_to_evsel(hists);
2476
- const char *ev_name = perf_evsel__name(evsel);
2686
+ struct evsel *evsel = hists_to_evsel(hists);
2687
+ const char *ev_name = evsel__name(evsel);
24772688 char buf[512], sample_freq_str[64] = "";
24782689 size_t buflen = sizeof(buf);
24792690 char ref[30] = " show reference callgraph, ";
....@@ -2484,10 +2695,10 @@
24842695 nr_events = hists->stats.total_non_filtered_period;
24852696 }
24862697
2487
- if (perf_evsel__is_group_event(evsel)) {
2488
- struct perf_evsel *pos;
2698
+ if (evsel__is_group_event(evsel)) {
2699
+ struct evsel *pos;
24892700
2490
- perf_evsel__group_desc(evsel, buf, buflen);
2701
+ evsel__group_desc(evsel, buf, buflen);
24912702 ev_name = buf;
24922703
24932704 for_each_group_member(pos, evsel) {
....@@ -2508,12 +2719,12 @@
25082719 enable_ref = true;
25092720
25102721 if (show_freq)
2511
- scnprintf(sample_freq_str, sizeof(sample_freq_str), " %d Hz,", evsel->attr.sample_freq);
2722
+ scnprintf(sample_freq_str, sizeof(sample_freq_str), " %d Hz,", evsel->core.attr.sample_freq);
25122723
25132724 nr_samples = convert_unit(nr_samples, &unit);
25142725 printed = scnprintf(bf, size,
25152726 "Samples: %lu%c of event%s '%s',%s%sEvent count (approx.): %" PRIu64,
2516
- nr_samples, unit, evsel->nr_members > 1 ? "s" : "",
2727
+ nr_samples, unit, evsel->core.nr_members > 1 ? "s" : "",
25172728 ev_name, sample_freq_str, enable_ref ? ref : " ", nr_events);
25182729
25192730
....@@ -2568,10 +2779,10 @@
25682779 int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list)
25692780 {
25702781 memset(hists, 0, sizeof(*hists));
2571
- hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT;
2782
+ hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT_CACHED;
25722783 hists->entries_in = &hists->entries_in_array[0];
2573
- hists->entries_collapsed = RB_ROOT;
2574
- hists->entries = RB_ROOT;
2784
+ hists->entries_collapsed = RB_ROOT_CACHED;
2785
+ hists->entries = RB_ROOT_CACHED;
25752786 pthread_mutex_init(&hists->lock, NULL);
25762787 hists->socket_filter = -1;
25772788 hists->hpp_list = hpp_list;
....@@ -2579,14 +2790,14 @@
25792790 return 0;
25802791 }
25812792
2582
-static void hists__delete_remaining_entries(struct rb_root *root)
2793
+static void hists__delete_remaining_entries(struct rb_root_cached *root)
25832794 {
25842795 struct rb_node *node;
25852796 struct hist_entry *he;
25862797
2587
- while (!RB_EMPTY_ROOT(root)) {
2588
- node = rb_first(root);
2589
- rb_erase(node, root);
2798
+ while (!RB_EMPTY_ROOT(&root->rb_root)) {
2799
+ node = rb_first_cached(root);
2800
+ rb_erase_cached(node, root);
25902801
25912802 he = rb_entry(node, struct hist_entry, rb_node_in);
25922803 hist_entry__delete(he);
....@@ -2601,7 +2812,7 @@
26012812 hists__delete_remaining_entries(&hists->entries_collapsed);
26022813 }
26032814
2604
-static void hists_evsel__exit(struct perf_evsel *evsel)
2815
+static void hists_evsel__exit(struct evsel *evsel)
26052816 {
26062817 struct hists *hists = evsel__hists(evsel);
26072818 struct perf_hpp_fmt *fmt, *pos;
....@@ -2611,15 +2822,15 @@
26112822
26122823 list_for_each_entry_safe(node, tmp, &hists->hpp_formats, list) {
26132824 perf_hpp_list__for_each_format_safe(&node->hpp, fmt, pos) {
2614
- list_del(&fmt->list);
2825
+ list_del_init(&fmt->list);
26152826 free(fmt);
26162827 }
2617
- list_del(&node->list);
2828
+ list_del_init(&node->list);
26182829 free(node);
26192830 }
26202831 }
26212832
2622
-static int hists_evsel__init(struct perf_evsel *evsel)
2833
+static int hists_evsel__init(struct evsel *evsel)
26232834 {
26242835 struct hists *hists = evsel__hists(evsel);
26252836
....@@ -2634,9 +2845,8 @@
26342845
26352846 int hists__init(void)
26362847 {
2637
- int err = perf_evsel__object_config(sizeof(struct hists_evsel),
2638
- hists_evsel__init,
2639
- hists_evsel__exit);
2848
+ int err = evsel__object_config(sizeof(struct hists_evsel),
2849
+ hists_evsel__init, hists_evsel__exit);
26402850 if (err)
26412851 fputs("FATAL ERROR: Couldn't setup hists class\n", stderr);
26422852