14 #include <linux/kernel.h> 86 for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
90 .hide_unresolved =
false,
98 sample.
cpumode = PERF_RECORD_MISC_USER;
99 sample.
pid = fake_samples[i].
pid;
100 sample.
tid = fake_samples[i].
pid;
101 sample.
ip = fake_samples[i].
ip;
114 fake_samples[i].
map = al.
map;
115 fake_samples[i].
sym = al.
sym;
121 pr_debug(
"Not enough memory for adding a hist entry\n");
128 struct rb_root *root_in;
129 struct rb_root *root_out;
130 struct rb_node *
node;
139 while (!RB_EMPTY_ROOT(root_out)) {
140 node = rb_first(root_out);
142 he = rb_entry(node,
struct hist_entry, rb_node);
143 rb_erase(node, root_out);
151 #define COMM(he) (thread__comm_str(he->thread)) 152 #define DSO(he) (he->ms.map->dso->short_name) 153 #define SYM(he) (he->ms.sym->name) 154 #define CPU(he) (he->cpu) 155 #define PID(he) (he->thread->tid) 156 #define DEPTH(he) (he->callchain->max_depth) 157 #define CDSO(cl) (cl->ms.map->dso->short_name) 158 #define CSYM(cl) (cl->ms.sym->name) 182 struct rb_root *
root;
183 struct rb_node *
node;
195 pr_info(
"use callchain: %d, cumulate callchain: %d\n",
202 for (node = rb_first(root), i = 0;
203 node && (he = rb_entry(node,
struct hist_entry, rb_node));
204 node = rb_next(node), i++) {
205 scnprintf(buf,
sizeof(buf),
"Invalid hist entry #%zd", i);
210 !strcmp(
COMM(he), expected[i].
comm) &&
211 !strcmp(
DSO(he), expected[i].
dso) &&
212 !strcmp(
SYM(he), expected[i].
sym));
221 root = &he->callchain->
node.rb_root;
227 list_for_each_entry(clist, &cnode->
val,
list) {
228 scnprintf(buf,
sizeof(buf),
"Invalid callchain entry #%zd/%zd", i, c);
231 c < expected_callchain[i].nr);
233 !strcmp(
CDSO(clist), expected_callchain[i].node[c].dso) &&
234 !strcmp(
CSYM(clist), expected_callchain[i].node[c].sym));
239 c <= expected_callchain[i].nr);
268 struct result expected[] = {
269 { 0, 2000,
"perf",
"perf",
"main" },
270 { 0, 1000,
"bash",
"[kernel]",
"page_fault" },
271 { 0, 1000,
"bash",
"bash",
"main" },
272 { 0, 1000,
"bash",
"bash",
"xmalloc" },
273 { 0, 1000,
"perf",
"[kernel]",
"page_fault" },
274 { 0, 1000,
"perf",
"[kernel]",
"schedule" },
275 { 0, 1000,
"perf",
"libc",
"free" },
276 { 0, 1000,
"perf",
"libc",
"malloc" },
277 { 0, 1000,
"perf",
"perf",
"cmd_record" },
291 err =
do_test(hists, expected, ARRAY_SIZE(expected), NULL, 0);
366 struct result expected[] = {
367 { 0, 2000,
"perf",
"perf",
"main" },
368 { 0, 1000,
"bash",
"[kernel]",
"page_fault" },
369 { 0, 1000,
"bash",
"bash",
"main" },
370 { 0, 1000,
"bash",
"bash",
"xmalloc" },
371 { 0, 1000,
"perf",
"[kernel]",
"page_fault" },
372 { 0, 1000,
"perf",
"[kernel]",
"schedule" },
373 { 0, 1000,
"perf",
"libc",
"free" },
374 { 0, 1000,
"perf",
"libc",
"malloc" },
375 { 0, 1000,
"perf",
"perf",
"cmd_record" },
379 1, { {
"perf",
"main" }, },
382 3, { {
"[kernel]",
"page_fault" },
383 {
"libc",
"malloc" },
384 {
"bash",
"main" }, },
387 1, { {
"bash",
"main" }, },
390 6, { {
"bash",
"xmalloc" },
391 {
"libc",
"malloc" },
392 {
"bash",
"xmalloc" },
393 {
"libc",
"malloc" },
394 {
"bash",
"xmalloc" },
395 {
"bash",
"main" }, },
398 4, { {
"[kernel]",
"page_fault" },
399 {
"[kernel]",
"sys_perf_event_open" },
400 {
"perf",
"run_command" },
401 {
"perf",
"main" }, },
404 3, { {
"[kernel]",
"schedule" },
405 {
"perf",
"run_command" },
406 {
"perf",
"main" }, },
409 4, { {
"libc",
"free" },
410 {
"perf",
"cmd_record" },
411 {
"perf",
"run_command" },
412 {
"perf",
"main" }, },
415 4, { {
"libc",
"malloc" },
416 {
"perf",
"cmd_record" },
417 {
"perf",
"run_command" },
418 {
"perf",
"main" }, },
421 3, { {
"perf",
"cmd_record" },
422 {
"perf",
"run_command" },
423 {
"perf",
"main" }, },
438 err =
do_test(hists, expected, ARRAY_SIZE(expected),
439 expected_callchain, ARRAY_SIZE(expected_callchain));
470 struct result expected[] = {
471 { 7000, 2000,
"perf",
"perf",
"main" },
472 { 5000, 0,
"perf",
"perf",
"run_command" },
473 { 3000, 1000,
"bash",
"bash",
"main" },
474 { 3000, 1000,
"perf",
"perf",
"cmd_record" },
475 { 2000, 0,
"bash",
"libc",
"malloc" },
476 { 1000, 1000,
"bash",
"[kernel]",
"page_fault" },
477 { 1000, 1000,
"bash",
"bash",
"xmalloc" },
478 { 1000, 1000,
"perf",
"[kernel]",
"page_fault" },
479 { 1000, 1000,
"perf",
"[kernel]",
"schedule" },
480 { 1000, 1000,
"perf",
"libc",
"free" },
481 { 1000, 1000,
"perf",
"libc",
"malloc" },
482 { 1000, 0,
"perf",
"[kernel]",
"sys_perf_event_open" },
496 err =
do_test(hists, expected, ARRAY_SIZE(expected), NULL, 0);
590 struct result expected[] = {
591 { 7000, 2000,
"perf",
"perf",
"main" },
592 { 5000, 0,
"perf",
"perf",
"run_command" },
593 { 3000, 1000,
"bash",
"bash",
"main" },
594 { 3000, 1000,
"perf",
"perf",
"cmd_record" },
595 { 2000, 0,
"bash",
"libc",
"malloc" },
596 { 1000, 1000,
"bash",
"[kernel]",
"page_fault" },
597 { 1000, 1000,
"bash",
"bash",
"xmalloc" },
598 { 1000, 0,
"perf",
"[kernel]",
"sys_perf_event_open" },
599 { 1000, 1000,
"perf",
"[kernel]",
"page_fault" },
600 { 1000, 1000,
"perf",
"[kernel]",
"schedule" },
601 { 1000, 1000,
"perf",
"libc",
"free" },
602 { 1000, 1000,
"perf",
"libc",
"malloc" },
606 1, { {
"perf",
"main" }, },
609 2, { {
"perf",
"run_command" },
610 {
"perf",
"main" }, },
613 1, { {
"bash",
"main" }, },
616 3, { {
"perf",
"cmd_record" },
617 {
"perf",
"run_command" },
618 {
"perf",
"main" }, },
621 4, { {
"libc",
"malloc" },
622 {
"bash",
"xmalloc" },
624 {
"bash",
"main" }, },
627 3, { {
"[kernel]",
"page_fault" },
628 {
"libc",
"malloc" },
629 {
"bash",
"main" }, },
632 6, { {
"bash",
"xmalloc" },
633 {
"libc",
"malloc" },
634 {
"bash",
"xmalloc" },
635 {
"libc",
"malloc" },
636 {
"bash",
"xmalloc" },
637 {
"bash",
"main" }, },
640 3, { {
"[kernel]",
"sys_perf_event_open" },
641 {
"perf",
"run_command" },
642 {
"perf",
"main" }, },
645 4, { {
"[kernel]",
"page_fault" },
646 {
"[kernel]",
"sys_perf_event_open" },
647 {
"perf",
"run_command" },
648 {
"perf",
"main" }, },
651 3, { {
"[kernel]",
"schedule" },
652 {
"perf",
"run_command" },
653 {
"perf",
"main" }, },
656 4, { {
"libc",
"free" },
657 {
"perf",
"cmd_record" },
658 {
"perf",
"run_command" },
659 {
"perf",
"main" }, },
662 4, { {
"libc",
"malloc" },
663 {
"perf",
"cmd_record" },
664 {
"perf",
"run_command" },
665 {
"perf",
"main" }, },
682 err =
do_test(hists, expected, ARRAY_SIZE(expected),
683 expected_callchain, ARRAY_SIZE(expected_callchain));
725 for (i = 0; i < ARRAY_SIZE(testcases); i++) {
726 err = testcases[i](evsel, machine);
#define FAKE_IP_BASH_XMALLOC
static void setup_sorting(struct perf_sched *sched, const struct option *options, const char *const usage_msg[])
struct rb_root * entries_in
struct perf_sample * sample
void machines__exit(struct machines *machines)
#define FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN
int machine__resolve(struct machine *machine, struct addr_location *al, struct perf_sample *sample)
void reset_output_field(void)
struct ip_callchain * callchain
int hists__collapse_resort(struct hists *hists, struct ui_progress *prog)
#define FAKE_IP_LIBC_MALLOC
#define TEST_ASSERT_VAL(text, cond)
static int add_hist_entries(struct hists *hists, struct machine *machine)
void perf_evlist__delete(struct perf_evlist *evlist)
#define perf_evsel__set_sample_bit(evsel, bit)
static struct hists * evsel__hists(struct perf_evsel *evsel)
struct callchain_param callchain_param_default
int parse_events(struct perf_evlist *evlist, const char *str, struct parse_events_error *err)
static int test2(struct perf_evsel *evsel, struct machine *machine)
void addr_location__put(struct addr_location *al)
static int do_test(struct hists *hists, struct result *expected, size_t nr_expected, struct callchain_result *expected_callchain, size_t nr_callchain)
static struct perf_evsel * hists_to_evsel(struct hists *hists)
#define pr_debug(fmt,...)
#define FAKE_IP_PERF_MAIN
#define FAKE_IP_KERNEL_SCHEDULE
int test__hists_cumulate(struct test *test __maybe_unused, int subtest __maybe_unused)
static int test1(struct perf_evsel *evsel, struct machine *machine)
#define hists__has(__h, __f)
static void del_hist_entries(struct hists *hists)
static u64 fake_callchains[][10]
void hist_entry__delete(struct hist_entry *he)
#define FAKE_IP_PERF_CMD_RECORD
struct rb_node rb_node_in
static int test4(struct perf_evsel *evsel, struct machine *machine)
const struct hist_iter_ops hist_iter_normal
static struct sample fake_samples[]
static struct perf_evsel * perf_evlist__first(struct perf_evlist *evlist)
void machines__init(struct machines *machines)
int(* test_fn_t)(struct perf_evsel *, struct machine *)
void print_hists_out(struct hists *hists)
#define FAKE_IP_BASH_MAIN
struct perf_evsel * evsel
#define FAKE_IP_PERF_RUN_COMMAND
const struct hist_iter_ops hist_iter_cumulative
#define FAKE_IP_KERNEL_PAGE_FAULT
#define perf_evsel__reset_sample_bit(evsel, bit)
void perf_evsel__output_resort(struct perf_evsel *evsel, struct ui_progress *prog)
const struct hist_iter_ops * ops
static int test3(struct perf_evsel *evsel, struct machine *machine)
struct machine * setup_fake_machine(struct machines *machines)
struct rb_root entries_collapsed
int sysctl_perf_event_max_stack
#define FAKE_IP_LIBC_FREE
int callchain_register_param(struct callchain_param *param)
size_t machine__fprintf(struct machine *machine, FILE *fp)
struct perf_evlist * perf_evlist__new(void)
int hist_entry_iter__add(struct hist_entry_iter *iter, struct addr_location *al, int max_stack_depth, void *arg)