hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/tools/perf/tests/hists_output.c
....@@ -1,7 +1,8 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-#include "perf.h"
32 #include "util/debug.h"
3
+#include "util/dso.h"
44 #include "util/event.h"
5
+#include "util/map.h"
56 #include "util/symbol.h"
67 #include "util/sort.h"
78 #include "util/evsel.h"
....@@ -49,7 +50,7 @@
4950 static int add_hist_entries(struct hists *hists, struct machine *machine)
5051 {
5152 struct addr_location al;
52
- struct perf_evsel *evsel = hists_to_evsel(hists);
53
+ struct evsel *evsel = hists_to_evsel(hists);
5354 struct perf_sample sample = { .period = 100, };
5455 size_t i;
5556
....@@ -91,8 +92,8 @@
9192 static void del_hist_entries(struct hists *hists)
9293 {
9394 struct hist_entry *he;
94
- struct rb_root *root_in;
95
- struct rb_root *root_out;
95
+ struct rb_root_cached *root_in;
96
+ struct rb_root_cached *root_out;
9697 struct rb_node *node;
9798
9899 if (hists__has(hists, need_collapse))
....@@ -102,17 +103,17 @@
102103
103104 root_out = &hists->entries;
104105
105
- while (!RB_EMPTY_ROOT(root_out)) {
106
- node = rb_first(root_out);
106
+ while (!RB_EMPTY_ROOT(&root_out->rb_root)) {
107
+ node = rb_first_cached(root_out);
107108
108109 he = rb_entry(node, struct hist_entry, rb_node);
109
- rb_erase(node, root_out);
110
- rb_erase(&he->rb_node_in, root_in);
110
+ rb_erase_cached(node, root_out);
111
+ rb_erase_cached(&he->rb_node_in, root_in);
111112 hist_entry__delete(he);
112113 }
113114 }
114115
115
-typedef int (*test_fn_t)(struct perf_evsel *, struct machine *);
116
+typedef int (*test_fn_t)(struct evsel *, struct machine *);
116117
117118 #define COMM(he) (thread__comm_str(he->thread))
118119 #define DSO(he) (he->ms.map->dso->short_name)
....@@ -121,12 +122,12 @@
121122 #define PID(he) (he->thread->tid)
122123
123124 /* default sort keys (no field) */
124
-static int test1(struct perf_evsel *evsel, struct machine *machine)
125
+static int test1(struct evsel *evsel, struct machine *machine)
125126 {
126127 int err;
127128 struct hists *hists = evsel__hists(evsel);
128129 struct hist_entry *he;
129
- struct rb_root *root;
130
+ struct rb_root_cached *root;
130131 struct rb_node *node;
131132
132133 field_order = NULL;
....@@ -154,7 +155,7 @@
154155 goto out;
155156
156157 hists__collapse_resort(hists, NULL);
157
- perf_evsel__output_resort(evsel, NULL);
158
+ evsel__output_resort(evsel, NULL);
158159
159160 if (verbose > 2) {
160161 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
....@@ -162,7 +163,7 @@
162163 }
163164
164165 root = &hists->entries;
165
- node = rb_first(root);
166
+ node = rb_first_cached(root);
166167 he = rb_entry(node, struct hist_entry, rb_node);
167168 TEST_ASSERT_VAL("Invalid hist entry",
168169 !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
....@@ -223,12 +224,12 @@
223224 }
224225
225226 /* mixed fields and sort keys */
226
-static int test2(struct perf_evsel *evsel, struct machine *machine)
227
+static int test2(struct evsel *evsel, struct machine *machine)
227228 {
228229 int err;
229230 struct hists *hists = evsel__hists(evsel);
230231 struct hist_entry *he;
231
- struct rb_root *root;
232
+ struct rb_root_cached *root;
232233 struct rb_node *node;
233234
234235 field_order = "overhead,cpu";
....@@ -254,7 +255,7 @@
254255 goto out;
255256
256257 hists__collapse_resort(hists, NULL);
257
- perf_evsel__output_resort(evsel, NULL);
258
+ evsel__output_resort(evsel, NULL);
258259
259260 if (verbose > 2) {
260261 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
....@@ -262,7 +263,7 @@
262263 }
263264
264265 root = &hists->entries;
265
- node = rb_first(root);
266
+ node = rb_first_cached(root);
266267 he = rb_entry(node, struct hist_entry, rb_node);
267268 TEST_ASSERT_VAL("Invalid hist entry",
268269 CPU(he) == 1 && PID(he) == 100 && he->stat.period == 300);
....@@ -279,12 +280,12 @@
279280 }
280281
281282 /* fields only (no sort key) */
282
-static int test3(struct perf_evsel *evsel, struct machine *machine)
283
+static int test3(struct evsel *evsel, struct machine *machine)
283284 {
284285 int err;
285286 struct hists *hists = evsel__hists(evsel);
286287 struct hist_entry *he;
287
- struct rb_root *root;
288
+ struct rb_root_cached *root;
288289 struct rb_node *node;
289290
290291 field_order = "comm,overhead,dso";
....@@ -308,7 +309,7 @@
308309 goto out;
309310
310311 hists__collapse_resort(hists, NULL);
311
- perf_evsel__output_resort(evsel, NULL);
312
+ evsel__output_resort(evsel, NULL);
312313
313314 if (verbose > 2) {
314315 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
....@@ -316,7 +317,7 @@
316317 }
317318
318319 root = &hists->entries;
319
- node = rb_first(root);
320
+ node = rb_first_cached(root);
320321 he = rb_entry(node, struct hist_entry, rb_node);
321322 TEST_ASSERT_VAL("Invalid hist entry",
322323 !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
....@@ -353,12 +354,12 @@
353354 }
354355
355356 /* handle duplicate 'dso' field */
356
-static int test4(struct perf_evsel *evsel, struct machine *machine)
357
+static int test4(struct evsel *evsel, struct machine *machine)
357358 {
358359 int err;
359360 struct hists *hists = evsel__hists(evsel);
360361 struct hist_entry *he;
361
- struct rb_root *root;
362
+ struct rb_root_cached *root;
362363 struct rb_node *node;
363364
364365 field_order = "dso,sym,comm,overhead,dso";
....@@ -386,7 +387,7 @@
386387 goto out;
387388
388389 hists__collapse_resort(hists, NULL);
389
- perf_evsel__output_resort(evsel, NULL);
390
+ evsel__output_resort(evsel, NULL);
390391
391392 if (verbose > 2) {
392393 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
....@@ -394,7 +395,7 @@
394395 }
395396
396397 root = &hists->entries;
397
- node = rb_first(root);
398
+ node = rb_first_cached(root);
398399 he = rb_entry(node, struct hist_entry, rb_node);
399400 TEST_ASSERT_VAL("Invalid hist entry",
400401 !strcmp(DSO(he), "perf") && !strcmp(SYM(he), "cmd_record") &&
....@@ -455,12 +456,12 @@
455456 }
456457
457458 /* full sort keys w/o overhead field */
458
-static int test5(struct perf_evsel *evsel, struct machine *machine)
459
+static int test5(struct evsel *evsel, struct machine *machine)
459460 {
460461 int err;
461462 struct hists *hists = evsel__hists(evsel);
462463 struct hist_entry *he;
463
- struct rb_root *root;
464
+ struct rb_root_cached *root;
464465 struct rb_node *node;
465466
466467 field_order = "cpu,pid,comm,dso,sym";
....@@ -489,7 +490,7 @@
489490 goto out;
490491
491492 hists__collapse_resort(hists, NULL);
492
- perf_evsel__output_resort(evsel, NULL);
493
+ evsel__output_resort(evsel, NULL);
493494
494495 if (verbose > 2) {
495496 pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
....@@ -497,7 +498,7 @@
497498 }
498499
499500 root = &hists->entries;
500
- node = rb_first(root);
501
+ node = rb_first_cached(root);
501502 he = rb_entry(node, struct hist_entry, rb_node);
502503
503504 TEST_ASSERT_VAL("Invalid hist entry",
....@@ -579,8 +580,8 @@
579580 int err = TEST_FAIL;
580581 struct machines machines;
581582 struct machine *machine;
582
- struct perf_evsel *evsel;
583
- struct perf_evlist *evlist = perf_evlist__new();
583
+ struct evsel *evsel;
584
+ struct evlist *evlist = evlist__new();
584585 size_t i;
585586 test_fn_t testcases[] = {
586587 test1,
....@@ -607,7 +608,7 @@
607608 if (verbose > 1)
608609 machine__fprintf(machine, stderr);
609610
610
- evsel = perf_evlist__first(evlist);
611
+ evsel = evlist__first(evlist);
611612
612613 for (i = 0; i < ARRAY_SIZE(testcases); i++) {
613614 err = testcases[i](evsel, machine);
....@@ -617,7 +618,7 @@
617618
618619 out:
619620 /* tear down everything */
620
- perf_evlist__delete(evlist);
621
+ evlist__delete(evlist);
621622 machines__exit(&machines);
622623
623624 return err;