^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include "util/debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include "util/dso.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include "util/event.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include "util/map.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "util/symbol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "util/sort.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "util/evsel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "util/evlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "util/machine.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "util/thread.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "util/parse-events.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "tests/tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "tests/hists_common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct sample {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) u32 cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) u32 pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) u64 ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct thread *thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct symbol *sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* For the numbers, see hists_common.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static struct sample fake_samples[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* perf [kernel] schedule() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) { .cpu = 0, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* perf [perf] main() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) { .cpu = 1, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* perf [perf] cmd_record() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) { .cpu = 1, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_CMD_RECORD, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* perf [libc] malloc() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) { .cpu = 1, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /* perf [libc] free() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) { .cpu = 2, .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_FREE, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /* perf [perf] main() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) { .cpu = 2, .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* perf [kernel] page_fault() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) { .cpu = 2, .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* bash [bash] main() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) { .cpu = 3, .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_MAIN, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /* bash [bash] xmalloc() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) { .cpu = 0, .pid = FAKE_PID_BASH, .ip = FAKE_IP_BASH_XMALLOC, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* bash [kernel] page_fault() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) { .cpu = 1, .pid = FAKE_PID_BASH, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int add_hist_entries(struct hists *hists, struct machine *machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct addr_location al;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct evsel *evsel = hists_to_evsel(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct perf_sample sample = { .period = 100, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct hist_entry_iter iter = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .evsel = evsel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .sample = &sample,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .ops = &hist_iter_normal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .hide_unresolved = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) sample.cpumode = PERF_RECORD_MISC_USER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) sample.cpu = fake_samples[i].cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) sample.pid = fake_samples[i].pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) sample.tid = fake_samples[i].pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) sample.ip = fake_samples[i].ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (machine__resolve(machine, &al, &sample) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (hist_entry_iter__add(&iter, &al, sysctl_perf_event_max_stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) NULL) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) addr_location__put(&al);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) fake_samples[i].thread = al.thread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) fake_samples[i].map = al.map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) fake_samples[i].sym = al.sym;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return TEST_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) pr_debug("Not enough memory for adding a hist entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return TEST_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void del_hist_entries(struct hists *hists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct rb_root_cached *root_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct rb_root_cached *root_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (hists__has(hists, need_collapse))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) root_in = &hists->entries_collapsed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) root_in = hists->entries_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) root_out = &hists->entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) while (!RB_EMPTY_ROOT(&root_out->rb_root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) node = rb_first_cached(root_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) rb_erase_cached(node, root_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) rb_erase_cached(&he->rb_node_in, root_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) hist_entry__delete(he);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) typedef int (*test_fn_t)(struct evsel *, struct machine *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define COMM(he) (thread__comm_str(he->thread))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #define DSO(he) (he->ms.map->dso->short_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) #define SYM(he) (he->ms.sym->name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #define CPU(he) (he->cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define PID(he) (he->thread->tid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /* default sort keys (no field) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static int test1(struct evsel *evsel, struct machine *machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct hists *hists = evsel__hists(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct rb_root_cached *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) field_order = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) sort_order = NULL; /* equivalent to sort_order = "comm,dso,sym" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) setup_sorting(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * expected output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * Overhead Command Shared Object Symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * ======== ======= ============= ==============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * 20.00% perf perf [.] main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * 10.00% bash [kernel] [k] page_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * 10.00% bash bash [.] main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * 10.00% bash bash [.] xmalloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * 10.00% perf [kernel] [k] page_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * 10.00% perf [kernel] [k] schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * 10.00% perf libc [.] free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * 10.00% perf libc [.] malloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * 10.00% perf perf [.] cmd_record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) err = add_hist_entries(hists, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) hists__collapse_resort(hists, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) evsel__output_resort(evsel, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) if (verbose > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) print_hists_out(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) root = &hists->entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) node = rb_first_cached(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) !strcmp(SYM(he), "main") && he->stat.period == 200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "[kernel]") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) !strcmp(SYM(he), "main") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) !strcmp(SYM(he), "xmalloc") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) !strcmp(SYM(he), "schedule") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) !strcmp(SYM(he), "free") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) !strcmp(SYM(he), "malloc") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) !strcmp(SYM(he), "cmd_record") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) del_hist_entries(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) reset_output_field();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* mixed fields and sort keys */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static int test2(struct evsel *evsel, struct machine *machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) struct hists *hists = evsel__hists(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct rb_root_cached *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) field_order = "overhead,cpu";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) sort_order = "pid";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) setup_sorting(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * expected output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * Overhead CPU Command: Pid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * ======== === =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * 30.00% 1 perf : 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * 10.00% 0 perf : 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) * 10.00% 2 perf : 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * 20.00% 2 perf : 200
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * 10.00% 0 bash : 300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * 10.00% 1 bash : 300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * 10.00% 3 bash : 300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) err = add_hist_entries(hists, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) hists__collapse_resort(hists, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) evsel__output_resort(evsel, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (verbose > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) print_hists_out(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) root = &hists->entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) node = rb_first_cached(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) CPU(he) == 1 && PID(he) == 100 && he->stat.period == 300);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) CPU(he) == 0 && PID(he) == 100 && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) del_hist_entries(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) reset_output_field();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* fields only (no sort key) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int test3(struct evsel *evsel, struct machine *machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct hists *hists = evsel__hists(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct rb_root_cached *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) field_order = "comm,overhead,dso";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) sort_order = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) setup_sorting(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * expected output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) * Command Overhead Shared Object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * ======= ======== =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * bash 20.00% bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * bash 10.00% [kernel]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * perf 30.00% perf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * perf 20.00% [kernel]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * perf 20.00% libc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) err = add_hist_entries(hists, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) hists__collapse_resort(hists, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) evsel__output_resort(evsel, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (verbose > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) print_hists_out(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) root = &hists->entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) node = rb_first_cached(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) he->stat.period == 200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "[kernel]") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) he->stat.period == 300);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) he->stat.period == 200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) he->stat.period == 200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) del_hist_entries(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) reset_output_field();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /* handle duplicate 'dso' field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static int test4(struct evsel *evsel, struct machine *machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) struct hists *hists = evsel__hists(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct rb_root_cached *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) field_order = "dso,sym,comm,overhead,dso";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) sort_order = "sym";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) setup_sorting(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * expected output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) * Shared Object Symbol Command Overhead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * ============= ============== ======= ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) * perf [.] cmd_record perf 10.00%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * libc [.] free perf 10.00%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * bash [.] main bash 10.00%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * perf [.] main perf 20.00%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * libc [.] malloc perf 10.00%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * [kernel] [k] page_fault bash 10.00%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * [kernel] [k] page_fault perf 10.00%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * [kernel] [k] schedule perf 10.00%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * bash [.] xmalloc bash 10.00%
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) err = add_hist_entries(hists, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) hists__collapse_resort(hists, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) evsel__output_resort(evsel, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (verbose > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) print_hists_out(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) root = &hists->entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) node = rb_first_cached(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) !strcmp(DSO(he), "perf") && !strcmp(SYM(he), "cmd_record") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) !strcmp(COMM(he), "perf") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) !strcmp(DSO(he), "libc") && !strcmp(SYM(he), "free") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) !strcmp(COMM(he), "perf") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) !strcmp(DSO(he), "bash") && !strcmp(SYM(he), "main") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) !strcmp(COMM(he), "bash") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) !strcmp(DSO(he), "perf") && !strcmp(SYM(he), "main") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) !strcmp(COMM(he), "perf") && he->stat.period == 200);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) !strcmp(DSO(he), "libc") && !strcmp(SYM(he), "malloc") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) !strcmp(COMM(he), "perf") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) !strcmp(DSO(he), "[kernel]") && !strcmp(SYM(he), "page_fault") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) !strcmp(COMM(he), "bash") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) !strcmp(DSO(he), "[kernel]") && !strcmp(SYM(he), "page_fault") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) !strcmp(COMM(he), "perf") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) !strcmp(DSO(he), "[kernel]") && !strcmp(SYM(he), "schedule") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) !strcmp(COMM(he), "perf") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) !strcmp(DSO(he), "bash") && !strcmp(SYM(he), "xmalloc") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) !strcmp(COMM(he), "bash") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) del_hist_entries(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) reset_output_field();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) /* full sort keys w/o overhead field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static int test5(struct evsel *evsel, struct machine *machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct hists *hists = evsel__hists(evsel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct hist_entry *he;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct rb_root_cached *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) struct rb_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) field_order = "cpu,pid,comm,dso,sym";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) sort_order = "dso,pid";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) setup_sorting(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * expected output:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * CPU Command: Pid Command Shared Object Symbol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * === ============= ======= ============= ==============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) * 0 perf: 100 perf [kernel] [k] schedule
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) * 2 perf: 200 perf [kernel] [k] page_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) * 1 bash: 300 bash [kernel] [k] page_fault
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) * 0 bash: 300 bash bash [.] xmalloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * 3 bash: 300 bash bash [.] main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * 1 perf: 100 perf libc [.] malloc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * 2 perf: 100 perf libc [.] free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * 1 perf: 100 perf perf [.] cmd_record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * 1 perf: 100 perf perf [.] main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * 2 perf: 200 perf perf [.] main
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) err = add_hist_entries(hists, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) hists__collapse_resort(hists, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) evsel__output_resort(evsel, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (verbose > 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) pr_info("[fields = %s, sort = %s]\n", field_order, sort_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) print_hists_out(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) root = &hists->entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) node = rb_first_cached(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) CPU(he) == 0 && PID(he) == 100 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) !strcmp(SYM(he), "schedule") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) CPU(he) == 2 && PID(he) == 200 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "[kernel]") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) CPU(he) == 1 && PID(he) == 300 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "[kernel]") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) !strcmp(SYM(he), "page_fault") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) CPU(he) == 0 && PID(he) == 300 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) !strcmp(SYM(he), "xmalloc") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) CPU(he) == 3 && PID(he) == 300 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) !strcmp(COMM(he), "bash") && !strcmp(DSO(he), "bash") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) !strcmp(SYM(he), "main") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) CPU(he) == 1 && PID(he) == 100 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) !strcmp(SYM(he), "malloc") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) CPU(he) == 2 && PID(he) == 100 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "libc") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) !strcmp(SYM(he), "free") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) CPU(he) == 1 && PID(he) == 100 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) !strcmp(SYM(he), "cmd_record") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) CPU(he) == 1 && PID(he) == 100 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) !strcmp(SYM(he), "main") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) node = rb_next(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) he = rb_entry(node, struct hist_entry, rb_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) TEST_ASSERT_VAL("Invalid hist entry",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) CPU(he) == 2 && PID(he) == 200 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) !strcmp(COMM(he), "perf") && !strcmp(DSO(he), "perf") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) !strcmp(SYM(he), "main") && he->stat.period == 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) del_hist_entries(hists);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) reset_output_field();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) int test__hists_output(struct test *test __maybe_unused, int subtest __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) int err = TEST_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct machines machines;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct machine *machine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct evsel *evsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct evlist *evlist = evlist__new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) size_t i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) test_fn_t testcases[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) test1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) test2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) test3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) test4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) test5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) TEST_ASSERT_VAL("No memory", evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) err = parse_events(evlist, "cpu-clock", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) err = TEST_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) machines__init(&machines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /* setup threads/dso/map/symbols also */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) machine = setup_fake_machine(&machines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (!machine)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (verbose > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) machine__fprintf(machine, stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) evsel = evlist__first(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) for (i = 0; i < ARRAY_SIZE(testcases); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) err = testcases[i](evsel, machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /* tear down everything */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) evlist__delete(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) machines__exit(&machines);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }