| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | | -#include "perf.h" |
|---|
| 3 | 2 | #include "util/debug.h" |
|---|
| 3 | +#include "util/dso.h" |
|---|
| 4 | 4 | #include "util/event.h" |
|---|
| 5 | +#include "util/map.h" |
|---|
| 5 | 6 | #include "util/symbol.h" |
|---|
| 6 | 7 | #include "util/sort.h" |
|---|
| 7 | 8 | #include "util/evsel.h" |
|---|
| .. | .. |
|---|
| 49 | 50 | static int add_hist_entries(struct hists *hists, struct machine *machine) |
|---|
| 50 | 51 | { |
|---|
| 51 | 52 | struct addr_location al; |
|---|
| 52 | | - struct perf_evsel *evsel = hists_to_evsel(hists); |
|---|
| 53 | + struct evsel *evsel = hists_to_evsel(hists); |
|---|
| 53 | 54 | struct perf_sample sample = { .period = 100, }; |
|---|
| 54 | 55 | size_t i; |
|---|
| 55 | 56 | |
|---|
| .. | .. |
|---|
| 91 | 92 | static void del_hist_entries(struct hists *hists) |
|---|
| 92 | 93 | { |
|---|
| 93 | 94 | 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; |
|---|
| 96 | 97 | struct rb_node *node; |
|---|
| 97 | 98 | |
|---|
| 98 | 99 | if (hists__has(hists, need_collapse)) |
|---|
| .. | .. |
|---|
| 102 | 103 | |
|---|
| 103 | 104 | root_out = &hists->entries; |
|---|
| 104 | 105 | |
|---|
| 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); |
|---|
| 107 | 108 | |
|---|
| 108 | 109 | 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); |
|---|
| 111 | 112 | hist_entry__delete(he); |
|---|
| 112 | 113 | } |
|---|
| 113 | 114 | } |
|---|
| 114 | 115 | |
|---|
| 115 | | -typedef int (*test_fn_t)(struct perf_evsel *, struct machine *); |
|---|
| 116 | +typedef int (*test_fn_t)(struct evsel *, struct machine *); |
|---|
| 116 | 117 | |
|---|
| 117 | 118 | #define COMM(he) (thread__comm_str(he->thread)) |
|---|
| 118 | 119 | #define DSO(he) (he->ms.map->dso->short_name) |
|---|
| .. | .. |
|---|
| 121 | 122 | #define PID(he) (he->thread->tid) |
|---|
| 122 | 123 | |
|---|
| 123 | 124 | /* 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) |
|---|
| 125 | 126 | { |
|---|
| 126 | 127 | int err; |
|---|
| 127 | 128 | struct hists *hists = evsel__hists(evsel); |
|---|
| 128 | 129 | struct hist_entry *he; |
|---|
| 129 | | - struct rb_root *root; |
|---|
| 130 | + struct rb_root_cached *root; |
|---|
| 130 | 131 | struct rb_node *node; |
|---|
| 131 | 132 | |
|---|
| 132 | 133 | field_order = NULL; |
|---|
| .. | .. |
|---|
| 154 | 155 | goto out; |
|---|
| 155 | 156 | |
|---|
| 156 | 157 | hists__collapse_resort(hists, NULL); |
|---|
| 157 | | - perf_evsel__output_resort(evsel, NULL); |
|---|
| 158 | + evsel__output_resort(evsel, NULL); |
|---|
| 158 | 159 | |
|---|
| 159 | 160 | if (verbose > 2) { |
|---|
| 160 | 161 | pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); |
|---|
| .. | .. |
|---|
| 162 | 163 | } |
|---|
| 163 | 164 | |
|---|
| 164 | 165 | root = &hists->entries; |
|---|
| 165 | | - node = rb_first(root); |
|---|
| 166 | + node = rb_first_cached(root); |
|---|
| 166 | 167 | he = rb_entry(node, struct hist_entry, rb_node); |
|---|
| 167 | 168 | TEST_ASSERT_VAL("Invalid hist entry", |
|---|
| 168 | 169 | !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") && |
|---|
| .. | .. |
|---|
| 223 | 224 | } |
|---|
| 224 | 225 | |
|---|
| 225 | 226 | /* 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) |
|---|
| 227 | 228 | { |
|---|
| 228 | 229 | int err; |
|---|
| 229 | 230 | struct hists *hists = evsel__hists(evsel); |
|---|
| 230 | 231 | struct hist_entry *he; |
|---|
| 231 | | - struct rb_root *root; |
|---|
| 232 | + struct rb_root_cached *root; |
|---|
| 232 | 233 | struct rb_node *node; |
|---|
| 233 | 234 | |
|---|
| 234 | 235 | field_order = "overhead,cpu"; |
|---|
| .. | .. |
|---|
| 254 | 255 | goto out; |
|---|
| 255 | 256 | |
|---|
| 256 | 257 | hists__collapse_resort(hists, NULL); |
|---|
| 257 | | - perf_evsel__output_resort(evsel, NULL); |
|---|
| 258 | + evsel__output_resort(evsel, NULL); |
|---|
| 258 | 259 | |
|---|
| 259 | 260 | if (verbose > 2) { |
|---|
| 260 | 261 | pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); |
|---|
| .. | .. |
|---|
| 262 | 263 | } |
|---|
| 263 | 264 | |
|---|
| 264 | 265 | root = &hists->entries; |
|---|
| 265 | | - node = rb_first(root); |
|---|
| 266 | + node = rb_first_cached(root); |
|---|
| 266 | 267 | he = rb_entry(node, struct hist_entry, rb_node); |
|---|
| 267 | 268 | TEST_ASSERT_VAL("Invalid hist entry", |
|---|
| 268 | 269 | CPU(he) == 1 && PID(he) == 100 && he->stat.period == 300); |
|---|
| .. | .. |
|---|
| 279 | 280 | } |
|---|
| 280 | 281 | |
|---|
| 281 | 282 | /* 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) |
|---|
| 283 | 284 | { |
|---|
| 284 | 285 | int err; |
|---|
| 285 | 286 | struct hists *hists = evsel__hists(evsel); |
|---|
| 286 | 287 | struct hist_entry *he; |
|---|
| 287 | | - struct rb_root *root; |
|---|
| 288 | + struct rb_root_cached *root; |
|---|
| 288 | 289 | struct rb_node *node; |
|---|
| 289 | 290 | |
|---|
| 290 | 291 | field_order = "comm,overhead,dso"; |
|---|
| .. | .. |
|---|
| 308 | 309 | goto out; |
|---|
| 309 | 310 | |
|---|
| 310 | 311 | hists__collapse_resort(hists, NULL); |
|---|
| 311 | | - perf_evsel__output_resort(evsel, NULL); |
|---|
| 312 | + evsel__output_resort(evsel, NULL); |
|---|
| 312 | 313 | |
|---|
| 313 | 314 | if (verbose > 2) { |
|---|
| 314 | 315 | pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); |
|---|
| .. | .. |
|---|
| 316 | 317 | } |
|---|
| 317 | 318 | |
|---|
| 318 | 319 | root = &hists->entries; |
|---|
| 319 | | - node = rb_first(root); |
|---|
| 320 | + node = rb_first_cached(root); |
|---|
| 320 | 321 | he = rb_entry(node, struct hist_entry, rb_node); |
|---|
| 321 | 322 | TEST_ASSERT_VAL("Invalid hist entry", |
|---|
| 322 | 323 | !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") && |
|---|
| .. | .. |
|---|
| 353 | 354 | } |
|---|
| 354 | 355 | |
|---|
| 355 | 356 | /* 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) |
|---|
| 357 | 358 | { |
|---|
| 358 | 359 | int err; |
|---|
| 359 | 360 | struct hists *hists = evsel__hists(evsel); |
|---|
| 360 | 361 | struct hist_entry *he; |
|---|
| 361 | | - struct rb_root *root; |
|---|
| 362 | + struct rb_root_cached *root; |
|---|
| 362 | 363 | struct rb_node *node; |
|---|
| 363 | 364 | |
|---|
| 364 | 365 | field_order = "dso,sym,comm,overhead,dso"; |
|---|
| .. | .. |
|---|
| 386 | 387 | goto out; |
|---|
| 387 | 388 | |
|---|
| 388 | 389 | hists__collapse_resort(hists, NULL); |
|---|
| 389 | | - perf_evsel__output_resort(evsel, NULL); |
|---|
| 390 | + evsel__output_resort(evsel, NULL); |
|---|
| 390 | 391 | |
|---|
| 391 | 392 | if (verbose > 2) { |
|---|
| 392 | 393 | pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); |
|---|
| .. | .. |
|---|
| 394 | 395 | } |
|---|
| 395 | 396 | |
|---|
| 396 | 397 | root = &hists->entries; |
|---|
| 397 | | - node = rb_first(root); |
|---|
| 398 | + node = rb_first_cached(root); |
|---|
| 398 | 399 | he = rb_entry(node, struct hist_entry, rb_node); |
|---|
| 399 | 400 | TEST_ASSERT_VAL("Invalid hist entry", |
|---|
| 400 | 401 | !strcmp(DSO(he), "perf") && !strcmp(SYM(he), "cmd_record") && |
|---|
| .. | .. |
|---|
| 455 | 456 | } |
|---|
| 456 | 457 | |
|---|
| 457 | 458 | /* 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) |
|---|
| 459 | 460 | { |
|---|
| 460 | 461 | int err; |
|---|
| 461 | 462 | struct hists *hists = evsel__hists(evsel); |
|---|
| 462 | 463 | struct hist_entry *he; |
|---|
| 463 | | - struct rb_root *root; |
|---|
| 464 | + struct rb_root_cached *root; |
|---|
| 464 | 465 | struct rb_node *node; |
|---|
| 465 | 466 | |
|---|
| 466 | 467 | field_order = "cpu,pid,comm,dso,sym"; |
|---|
| .. | .. |
|---|
| 489 | 490 | goto out; |
|---|
| 490 | 491 | |
|---|
| 491 | 492 | hists__collapse_resort(hists, NULL); |
|---|
| 492 | | - perf_evsel__output_resort(evsel, NULL); |
|---|
| 493 | + evsel__output_resort(evsel, NULL); |
|---|
| 493 | 494 | |
|---|
| 494 | 495 | if (verbose > 2) { |
|---|
| 495 | 496 | pr_info("[fields = %s, sort = %s]\n", field_order, sort_order); |
|---|
| .. | .. |
|---|
| 497 | 498 | } |
|---|
| 498 | 499 | |
|---|
| 499 | 500 | root = &hists->entries; |
|---|
| 500 | | - node = rb_first(root); |
|---|
| 501 | + node = rb_first_cached(root); |
|---|
| 501 | 502 | he = rb_entry(node, struct hist_entry, rb_node); |
|---|
| 502 | 503 | |
|---|
| 503 | 504 | TEST_ASSERT_VAL("Invalid hist entry", |
|---|
| .. | .. |
|---|
| 579 | 580 | int err = TEST_FAIL; |
|---|
| 580 | 581 | struct machines machines; |
|---|
| 581 | 582 | 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(); |
|---|
| 584 | 585 | size_t i; |
|---|
| 585 | 586 | test_fn_t testcases[] = { |
|---|
| 586 | 587 | test1, |
|---|
| .. | .. |
|---|
| 607 | 608 | if (verbose > 1) |
|---|
| 608 | 609 | machine__fprintf(machine, stderr); |
|---|
| 609 | 610 | |
|---|
| 610 | | - evsel = perf_evlist__first(evlist); |
|---|
| 611 | + evsel = evlist__first(evlist); |
|---|
| 611 | 612 | |
|---|
| 612 | 613 | for (i = 0; i < ARRAY_SIZE(testcases); i++) { |
|---|
| 613 | 614 | err = testcases[i](evsel, machine); |
|---|
| .. | .. |
|---|
| 617 | 618 | |
|---|
| 618 | 619 | out: |
|---|
| 619 | 620 | /* tear down everything */ |
|---|
| 620 | | - perf_evlist__delete(evlist); |
|---|
| 621 | + evlist__delete(evlist); |
|---|
| 621 | 622 | machines__exit(&machines); |
|---|
| 622 | 623 | |
|---|
| 623 | 624 | return err; |
|---|