xref: /linux/tools/perf/tests/hists_cumulate.c (revision 81f17c90f14122123cc52d1609f567834e56b122)
10506aeccSNamhyung Kim #include "perf.h"
20506aeccSNamhyung Kim #include "util/debug.h"
35ab8c689SArnaldo Carvalho de Melo #include "util/event.h"
40506aeccSNamhyung Kim #include "util/symbol.h"
50506aeccSNamhyung Kim #include "util/sort.h"
60506aeccSNamhyung Kim #include "util/evsel.h"
70506aeccSNamhyung Kim #include "util/evlist.h"
80506aeccSNamhyung Kim #include "util/machine.h"
90506aeccSNamhyung Kim #include "util/thread.h"
100506aeccSNamhyung Kim #include "util/parse-events.h"
110506aeccSNamhyung Kim #include "tests/tests.h"
120506aeccSNamhyung Kim #include "tests/hists_common.h"
13877a7a11SArnaldo Carvalho de Melo #include <linux/kernel.h>
140506aeccSNamhyung Kim 
150506aeccSNamhyung Kim struct sample {
160506aeccSNamhyung Kim 	u32 pid;
170506aeccSNamhyung Kim 	u64 ip;
180506aeccSNamhyung Kim 	struct thread *thread;
190506aeccSNamhyung Kim 	struct map *map;
200506aeccSNamhyung Kim 	struct symbol *sym;
210506aeccSNamhyung Kim };
220506aeccSNamhyung Kim 
230506aeccSNamhyung Kim /* For the numbers, see hists_common.c */
240506aeccSNamhyung Kim static struct sample fake_samples[] = {
250506aeccSNamhyung Kim 	/* perf [kernel] schedule() */
260506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, },
270506aeccSNamhyung Kim 	/* perf [perf]   main() */
280506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, },
290506aeccSNamhyung Kim 	/* perf [perf]   cmd_record() */
300506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_CMD_RECORD, },
310506aeccSNamhyung Kim 	/* perf [libc]   malloc() */
320506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, },
330506aeccSNamhyung Kim 	/* perf [libc]   free() */
340506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_FREE, },
350506aeccSNamhyung Kim 	/* perf [perf]   main() */
360506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, },
370506aeccSNamhyung Kim 	/* perf [kernel] page_fault() */
380506aeccSNamhyung Kim 	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
390506aeccSNamhyung Kim 	/* bash [bash]   main() */
400506aeccSNamhyung Kim 	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_MAIN, },
410506aeccSNamhyung Kim 	/* bash [bash]   xmalloc() */
420506aeccSNamhyung Kim 	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XMALLOC, },
430506aeccSNamhyung Kim 	/* bash [kernel] page_fault() */
440506aeccSNamhyung Kim 	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
450506aeccSNamhyung Kim };
460506aeccSNamhyung Kim 
470506aeccSNamhyung Kim /*
480506aeccSNamhyung Kim  * Will be casted to struct ip_callchain which has all 64 bit entries
490506aeccSNamhyung Kim  * of nr and ips[].
500506aeccSNamhyung Kim  */
510506aeccSNamhyung Kim static u64 fake_callchains[][10] = {
520506aeccSNamhyung Kim 	/*   schedule => run_command => main */
530506aeccSNamhyung Kim 	{ 3, FAKE_IP_KERNEL_SCHEDULE, FAKE_IP_PERF_RUN_COMMAND, FAKE_IP_PERF_MAIN, },
540506aeccSNamhyung Kim 	/*   main  */
550506aeccSNamhyung Kim 	{ 1, FAKE_IP_PERF_MAIN, },
560506aeccSNamhyung Kim 	/*   cmd_record => run_command => main */
570506aeccSNamhyung Kim 	{ 3, FAKE_IP_PERF_CMD_RECORD, FAKE_IP_PERF_RUN_COMMAND, FAKE_IP_PERF_MAIN, },
580506aeccSNamhyung Kim 	/*   malloc => cmd_record => run_command => main */
590506aeccSNamhyung Kim 	{ 4, FAKE_IP_LIBC_MALLOC, FAKE_IP_PERF_CMD_RECORD, FAKE_IP_PERF_RUN_COMMAND,
600506aeccSNamhyung Kim 	     FAKE_IP_PERF_MAIN, },
610506aeccSNamhyung Kim 	/*   free => cmd_record => run_command => main */
620506aeccSNamhyung Kim 	{ 4, FAKE_IP_LIBC_FREE, FAKE_IP_PERF_CMD_RECORD, FAKE_IP_PERF_RUN_COMMAND,
630506aeccSNamhyung Kim 	     FAKE_IP_PERF_MAIN, },
640506aeccSNamhyung Kim 	/*   main */
650506aeccSNamhyung Kim 	{ 1, FAKE_IP_PERF_MAIN, },
660506aeccSNamhyung Kim 	/*   page_fault => sys_perf_event_open => run_command => main */
670506aeccSNamhyung Kim 	{ 4, FAKE_IP_KERNEL_PAGE_FAULT, FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN,
680506aeccSNamhyung Kim 	     FAKE_IP_PERF_RUN_COMMAND, FAKE_IP_PERF_MAIN, },
690506aeccSNamhyung Kim 	/*   main */
700506aeccSNamhyung Kim 	{ 1, FAKE_IP_BASH_MAIN, },
710506aeccSNamhyung Kim 	/*   xmalloc => malloc => xmalloc => malloc => xmalloc => main */
720506aeccSNamhyung Kim 	{ 6, FAKE_IP_BASH_XMALLOC, FAKE_IP_LIBC_MALLOC, FAKE_IP_BASH_XMALLOC,
730506aeccSNamhyung Kim 	     FAKE_IP_LIBC_MALLOC, FAKE_IP_BASH_XMALLOC, FAKE_IP_BASH_MAIN, },
740506aeccSNamhyung Kim 	/*   page_fault => malloc => main */
750506aeccSNamhyung Kim 	{ 3, FAKE_IP_KERNEL_PAGE_FAULT, FAKE_IP_LIBC_MALLOC, FAKE_IP_BASH_MAIN, },
760506aeccSNamhyung Kim };
770506aeccSNamhyung Kim 
780506aeccSNamhyung Kim static int add_hist_entries(struct hists *hists, struct machine *machine)
790506aeccSNamhyung Kim {
800506aeccSNamhyung Kim 	struct addr_location al;
810506aeccSNamhyung Kim 	struct perf_evsel *evsel = hists_to_evsel(hists);
820506aeccSNamhyung Kim 	struct perf_sample sample = { .period = 1000, };
830506aeccSNamhyung Kim 	size_t i;
840506aeccSNamhyung Kim 
850506aeccSNamhyung Kim 	for (i = 0; i < ARRAY_SIZE(fake_samples); i++) {
860506aeccSNamhyung Kim 		struct hist_entry_iter iter = {
87063bd936SNamhyung Kim 			.evsel = evsel,
88063bd936SNamhyung Kim 			.sample	= &sample,
890506aeccSNamhyung Kim 			.hide_unresolved = false,
900506aeccSNamhyung Kim 		};
910506aeccSNamhyung Kim 
920506aeccSNamhyung Kim 		if (symbol_conf.cumulate_callchain)
930506aeccSNamhyung Kim 			iter.ops = &hist_iter_cumulative;
940506aeccSNamhyung Kim 		else
950506aeccSNamhyung Kim 			iter.ops = &hist_iter_normal;
960506aeccSNamhyung Kim 
97473398a2SArnaldo Carvalho de Melo 		sample.cpumode = PERF_RECORD_MISC_USER;
980506aeccSNamhyung Kim 		sample.pid = fake_samples[i].pid;
990506aeccSNamhyung Kim 		sample.tid = fake_samples[i].pid;
1000506aeccSNamhyung Kim 		sample.ip = fake_samples[i].ip;
1010506aeccSNamhyung Kim 		sample.callchain = (struct ip_callchain *)fake_callchains[i];
1020506aeccSNamhyung Kim 
103bb3eb566SArnaldo Carvalho de Melo 		if (machine__resolve(machine, &al, &sample) < 0)
1040506aeccSNamhyung Kim 			goto out;
1050506aeccSNamhyung Kim 
1064cb93446SArnaldo Carvalho de Melo 		if (hist_entry_iter__add(&iter, &al, sysctl_perf_event_max_stack,
107063bd936SNamhyung Kim 					 NULL) < 0) {
108b91fc39fSArnaldo Carvalho de Melo 			addr_location__put(&al);
1090506aeccSNamhyung Kim 			goto out;
110b91fc39fSArnaldo Carvalho de Melo 		}
1110506aeccSNamhyung Kim 
1120506aeccSNamhyung Kim 		fake_samples[i].thread = al.thread;
1130506aeccSNamhyung Kim 		fake_samples[i].map = al.map;
1140506aeccSNamhyung Kim 		fake_samples[i].sym = al.sym;
1150506aeccSNamhyung Kim 	}
1160506aeccSNamhyung Kim 
1170506aeccSNamhyung Kim 	return TEST_OK;
1180506aeccSNamhyung Kim 
1190506aeccSNamhyung Kim out:
1200506aeccSNamhyung Kim 	pr_debug("Not enough memory for adding a hist entry\n");
1210506aeccSNamhyung Kim 	return TEST_FAIL;
1220506aeccSNamhyung Kim }
1230506aeccSNamhyung Kim 
1240506aeccSNamhyung Kim static void del_hist_entries(struct hists *hists)
1250506aeccSNamhyung Kim {
1260506aeccSNamhyung Kim 	struct hist_entry *he;
1270506aeccSNamhyung Kim 	struct rb_root *root_in;
1280506aeccSNamhyung Kim 	struct rb_root *root_out;
1290506aeccSNamhyung Kim 	struct rb_node *node;
1300506aeccSNamhyung Kim 
13152225036SJiri Olsa 	if (hists__has(hists, need_collapse))
1320506aeccSNamhyung Kim 		root_in = &hists->entries_collapsed;
1330506aeccSNamhyung Kim 	else
1340506aeccSNamhyung Kim 		root_in = hists->entries_in;
1350506aeccSNamhyung Kim 
1360506aeccSNamhyung Kim 	root_out = &hists->entries;
1370506aeccSNamhyung Kim 
1380506aeccSNamhyung Kim 	while (!RB_EMPTY_ROOT(root_out)) {
1390506aeccSNamhyung Kim 		node = rb_first(root_out);
1400506aeccSNamhyung Kim 
1410506aeccSNamhyung Kim 		he = rb_entry(node, struct hist_entry, rb_node);
1420506aeccSNamhyung Kim 		rb_erase(node, root_out);
1430506aeccSNamhyung Kim 		rb_erase(&he->rb_node_in, root_in);
1446733d1bfSArnaldo Carvalho de Melo 		hist_entry__delete(he);
1450506aeccSNamhyung Kim 	}
1460506aeccSNamhyung Kim }
1470506aeccSNamhyung Kim 
1480506aeccSNamhyung Kim typedef int (*test_fn_t)(struct perf_evsel *, struct machine *);
1490506aeccSNamhyung Kim 
1500506aeccSNamhyung Kim #define COMM(he)  (thread__comm_str(he->thread))
1510506aeccSNamhyung Kim #define DSO(he)   (he->ms.map->dso->short_name)
1520506aeccSNamhyung Kim #define SYM(he)   (he->ms.sym->name)
1530506aeccSNamhyung Kim #define CPU(he)   (he->cpu)
1540506aeccSNamhyung Kim #define PID(he)   (he->thread->tid)
1550506aeccSNamhyung Kim #define DEPTH(he) (he->callchain->max_depth)
1560506aeccSNamhyung Kim #define CDSO(cl)  (cl->ms.map->dso->short_name)
1570506aeccSNamhyung Kim #define CSYM(cl)  (cl->ms.sym->name)
1580506aeccSNamhyung Kim 
1590506aeccSNamhyung Kim struct result {
1600506aeccSNamhyung Kim 	u64 children;
1610506aeccSNamhyung Kim 	u64 self;
1620506aeccSNamhyung Kim 	const char *comm;
1630506aeccSNamhyung Kim 	const char *dso;
1640506aeccSNamhyung Kim 	const char *sym;
1650506aeccSNamhyung Kim };
1660506aeccSNamhyung Kim 
1670506aeccSNamhyung Kim struct callchain_result {
1680506aeccSNamhyung Kim 	u64 nr;
1690506aeccSNamhyung Kim 	struct {
1700506aeccSNamhyung Kim 		const char *dso;
1710506aeccSNamhyung Kim 		const char *sym;
1720506aeccSNamhyung Kim 	} node[10];
1730506aeccSNamhyung Kim };
1740506aeccSNamhyung Kim 
1750506aeccSNamhyung Kim static int do_test(struct hists *hists, struct result *expected, size_t nr_expected,
1760506aeccSNamhyung Kim 		   struct callchain_result *expected_callchain, size_t nr_callchain)
1770506aeccSNamhyung Kim {
1780506aeccSNamhyung Kim 	char buf[32];
1790506aeccSNamhyung Kim 	size_t i, c;
1800506aeccSNamhyung Kim 	struct hist_entry *he;
1810506aeccSNamhyung Kim 	struct rb_root *root;
1820506aeccSNamhyung Kim 	struct rb_node *node;
1830506aeccSNamhyung Kim 	struct callchain_node *cnode;
1840506aeccSNamhyung Kim 	struct callchain_list *clist;
1850506aeccSNamhyung Kim 
1860506aeccSNamhyung Kim 	/*
1870506aeccSNamhyung Kim 	 * adding and deleting hist entries must be done outside of this
1880506aeccSNamhyung Kim 	 * function since TEST_ASSERT_VAL() returns in case of failure.
1890506aeccSNamhyung Kim 	 */
1900506aeccSNamhyung Kim 	hists__collapse_resort(hists, NULL);
191452ce03bSJiri Olsa 	perf_evsel__output_resort(hists_to_evsel(hists), NULL);
1920506aeccSNamhyung Kim 
1930506aeccSNamhyung Kim 	if (verbose > 2) {
1940506aeccSNamhyung Kim 		pr_info("use callchain: %d, cumulate callchain: %d\n",
1950506aeccSNamhyung Kim 			symbol_conf.use_callchain,
1960506aeccSNamhyung Kim 			symbol_conf.cumulate_callchain);
1970506aeccSNamhyung Kim 		print_hists_out(hists);
1980506aeccSNamhyung Kim 	}
1990506aeccSNamhyung Kim 
2000506aeccSNamhyung Kim 	root = &hists->entries;
2010506aeccSNamhyung Kim 	for (node = rb_first(root), i = 0;
2020506aeccSNamhyung Kim 	     node && (he = rb_entry(node, struct hist_entry, rb_node));
2030506aeccSNamhyung Kim 	     node = rb_next(node), i++) {
2040506aeccSNamhyung Kim 		scnprintf(buf, sizeof(buf), "Invalid hist entry #%zd", i);
2050506aeccSNamhyung Kim 
2060506aeccSNamhyung Kim 		TEST_ASSERT_VAL("Incorrect number of hist entry",
2070506aeccSNamhyung Kim 				i < nr_expected);
2080506aeccSNamhyung Kim 		TEST_ASSERT_VAL(buf, he->stat.period == expected[i].self &&
2090506aeccSNamhyung Kim 				!strcmp(COMM(he), expected[i].comm) &&
2100506aeccSNamhyung Kim 				!strcmp(DSO(he), expected[i].dso) &&
2110506aeccSNamhyung Kim 				!strcmp(SYM(he), expected[i].sym));
2120506aeccSNamhyung Kim 
2130506aeccSNamhyung Kim 		if (symbol_conf.cumulate_callchain)
2140506aeccSNamhyung Kim 			TEST_ASSERT_VAL(buf, he->stat_acc->period == expected[i].children);
2150506aeccSNamhyung Kim 
2160506aeccSNamhyung Kim 		if (!symbol_conf.use_callchain)
2170506aeccSNamhyung Kim 			continue;
2180506aeccSNamhyung Kim 
2190506aeccSNamhyung Kim 		/* check callchain entries */
2200506aeccSNamhyung Kim 		root = &he->callchain->node.rb_root;
221347ca878SJiri Olsa 
222347ca878SJiri Olsa 		TEST_ASSERT_VAL("callchains expected", !RB_EMPTY_ROOT(root));
2230506aeccSNamhyung Kim 		cnode = rb_entry(rb_first(root), struct callchain_node, rb_node);
2240506aeccSNamhyung Kim 
2250506aeccSNamhyung Kim 		c = 0;
2260506aeccSNamhyung Kim 		list_for_each_entry(clist, &cnode->val, list) {
2270506aeccSNamhyung Kim 			scnprintf(buf, sizeof(buf), "Invalid callchain entry #%zd/%zd", i, c);
2280506aeccSNamhyung Kim 
2290506aeccSNamhyung Kim 			TEST_ASSERT_VAL("Incorrect number of callchain entry",
2300506aeccSNamhyung Kim 					c < expected_callchain[i].nr);
2310506aeccSNamhyung Kim 			TEST_ASSERT_VAL(buf,
2320506aeccSNamhyung Kim 				!strcmp(CDSO(clist), expected_callchain[i].node[c].dso) &&
2330506aeccSNamhyung Kim 				!strcmp(CSYM(clist), expected_callchain[i].node[c].sym));
2340506aeccSNamhyung Kim 			c++;
2350506aeccSNamhyung Kim 		}
2360506aeccSNamhyung Kim 		/* TODO: handle multiple child nodes properly */
2370506aeccSNamhyung Kim 		TEST_ASSERT_VAL("Incorrect number of callchain entry",
2380506aeccSNamhyung Kim 				c <= expected_callchain[i].nr);
2390506aeccSNamhyung Kim 	}
2400506aeccSNamhyung Kim 	TEST_ASSERT_VAL("Incorrect number of hist entry",
2410506aeccSNamhyung Kim 			i == nr_expected);
2420506aeccSNamhyung Kim 	TEST_ASSERT_VAL("Incorrect number of callchain entry",
2430506aeccSNamhyung Kim 			!symbol_conf.use_callchain || nr_expected == nr_callchain);
2440506aeccSNamhyung Kim 	return 0;
2450506aeccSNamhyung Kim }
2460506aeccSNamhyung Kim 
2470506aeccSNamhyung Kim /* NO callchain + NO children */
2480506aeccSNamhyung Kim static int test1(struct perf_evsel *evsel, struct machine *machine)
2490506aeccSNamhyung Kim {
2500506aeccSNamhyung Kim 	int err;
2514ea062edSArnaldo Carvalho de Melo 	struct hists *hists = evsel__hists(evsel);
2520506aeccSNamhyung Kim 	/*
2530506aeccSNamhyung Kim 	 * expected output:
2540506aeccSNamhyung Kim 	 *
2550506aeccSNamhyung Kim 	 * Overhead  Command  Shared Object          Symbol
2560506aeccSNamhyung Kim 	 * ========  =======  =============  ==============
2570506aeccSNamhyung Kim 	 *   20.00%     perf  perf           [.] main
2580506aeccSNamhyung Kim 	 *   10.00%     bash  [kernel]       [k] page_fault
2590506aeccSNamhyung Kim 	 *   10.00%     bash  bash           [.] main
2600506aeccSNamhyung Kim 	 *   10.00%     bash  bash           [.] xmalloc
2610506aeccSNamhyung Kim 	 *   10.00%     perf  [kernel]       [k] page_fault
2620506aeccSNamhyung Kim 	 *   10.00%     perf  [kernel]       [k] schedule
2630506aeccSNamhyung Kim 	 *   10.00%     perf  libc           [.] free
2640506aeccSNamhyung Kim 	 *   10.00%     perf  libc           [.] malloc
2650506aeccSNamhyung Kim 	 *   10.00%     perf  perf           [.] cmd_record
2660506aeccSNamhyung Kim 	 */
2670506aeccSNamhyung Kim 	struct result expected[] = {
2680506aeccSNamhyung Kim 		{ 0, 2000, "perf", "perf",     "main" },
2690506aeccSNamhyung Kim 		{ 0, 1000, "bash", "[kernel]", "page_fault" },
2700506aeccSNamhyung Kim 		{ 0, 1000, "bash", "bash",     "main" },
2710506aeccSNamhyung Kim 		{ 0, 1000, "bash", "bash",     "xmalloc" },
2720506aeccSNamhyung Kim 		{ 0, 1000, "perf", "[kernel]", "page_fault" },
2730506aeccSNamhyung Kim 		{ 0, 1000, "perf", "[kernel]", "schedule" },
2740506aeccSNamhyung Kim 		{ 0, 1000, "perf", "libc",     "free" },
2750506aeccSNamhyung Kim 		{ 0, 1000, "perf", "libc",     "malloc" },
2760506aeccSNamhyung Kim 		{ 0, 1000, "perf", "perf",     "cmd_record" },
2770506aeccSNamhyung Kim 	};
2780506aeccSNamhyung Kim 
2790506aeccSNamhyung Kim 	symbol_conf.use_callchain = false;
2800506aeccSNamhyung Kim 	symbol_conf.cumulate_callchain = false;
281f9db0d0fSKan Liang 	perf_evsel__reset_sample_bit(evsel, CALLCHAIN);
2820506aeccSNamhyung Kim 
28340184c46SNamhyung Kim 	setup_sorting(NULL);
2840506aeccSNamhyung Kim 	callchain_register_param(&callchain_param);
2850506aeccSNamhyung Kim 
2860506aeccSNamhyung Kim 	err = add_hist_entries(hists, machine);
2870506aeccSNamhyung Kim 	if (err < 0)
2880506aeccSNamhyung Kim 		goto out;
2890506aeccSNamhyung Kim 
2900506aeccSNamhyung Kim 	err = do_test(hists, expected, ARRAY_SIZE(expected), NULL, 0);
2910506aeccSNamhyung Kim 
2920506aeccSNamhyung Kim out:
2930506aeccSNamhyung Kim 	del_hist_entries(hists);
2940506aeccSNamhyung Kim 	reset_output_field();
2950506aeccSNamhyung Kim 	return err;
2960506aeccSNamhyung Kim }
2970506aeccSNamhyung Kim 
2980506aeccSNamhyung Kim /* callcain + NO children */
2990506aeccSNamhyung Kim static int test2(struct perf_evsel *evsel, struct machine *machine)
3000506aeccSNamhyung Kim {
3010506aeccSNamhyung Kim 	int err;
3024ea062edSArnaldo Carvalho de Melo 	struct hists *hists = evsel__hists(evsel);
3030506aeccSNamhyung Kim 	/*
3040506aeccSNamhyung Kim 	 * expected output:
3050506aeccSNamhyung Kim 	 *
3060506aeccSNamhyung Kim 	 * Overhead  Command  Shared Object          Symbol
3070506aeccSNamhyung Kim 	 * ========  =======  =============  ==============
3080506aeccSNamhyung Kim 	 *   20.00%     perf  perf           [.] main
3090506aeccSNamhyung Kim 	 *              |
3100506aeccSNamhyung Kim 	 *              --- main
3110506aeccSNamhyung Kim 	 *
3120506aeccSNamhyung Kim 	 *   10.00%     bash  [kernel]       [k] page_fault
3130506aeccSNamhyung Kim 	 *              |
3140506aeccSNamhyung Kim 	 *              --- page_fault
3150506aeccSNamhyung Kim 	 *                  malloc
3160506aeccSNamhyung Kim 	 *                  main
3170506aeccSNamhyung Kim 	 *
3180506aeccSNamhyung Kim 	 *   10.00%     bash  bash           [.] main
3190506aeccSNamhyung Kim 	 *              |
3200506aeccSNamhyung Kim 	 *              --- main
3210506aeccSNamhyung Kim 	 *
3220506aeccSNamhyung Kim 	 *   10.00%     bash  bash           [.] xmalloc
3230506aeccSNamhyung Kim 	 *              |
3240506aeccSNamhyung Kim 	 *              --- xmalloc
3250506aeccSNamhyung Kim 	 *                  malloc
3260506aeccSNamhyung Kim 	 *                  xmalloc     <--- NOTE: there's a cycle
3270506aeccSNamhyung Kim 	 *                  malloc
3280506aeccSNamhyung Kim 	 *                  xmalloc
3290506aeccSNamhyung Kim 	 *                  main
3300506aeccSNamhyung Kim 	 *
3310506aeccSNamhyung Kim 	 *   10.00%     perf  [kernel]       [k] page_fault
3320506aeccSNamhyung Kim 	 *              |
3330506aeccSNamhyung Kim 	 *              --- page_fault
3340506aeccSNamhyung Kim 	 *                  sys_perf_event_open
3350506aeccSNamhyung Kim 	 *                  run_command
3360506aeccSNamhyung Kim 	 *                  main
3370506aeccSNamhyung Kim 	 *
3380506aeccSNamhyung Kim 	 *   10.00%     perf  [kernel]       [k] schedule
3390506aeccSNamhyung Kim 	 *              |
3400506aeccSNamhyung Kim 	 *              --- schedule
3410506aeccSNamhyung Kim 	 *                  run_command
3420506aeccSNamhyung Kim 	 *                  main
3430506aeccSNamhyung Kim 	 *
3440506aeccSNamhyung Kim 	 *   10.00%     perf  libc           [.] free
3450506aeccSNamhyung Kim 	 *              |
3460506aeccSNamhyung Kim 	 *              --- free
3470506aeccSNamhyung Kim 	 *                  cmd_record
3480506aeccSNamhyung Kim 	 *                  run_command
3490506aeccSNamhyung Kim 	 *                  main
3500506aeccSNamhyung Kim 	 *
3510506aeccSNamhyung Kim 	 *   10.00%     perf  libc           [.] malloc
3520506aeccSNamhyung Kim 	 *              |
3530506aeccSNamhyung Kim 	 *              --- malloc
3540506aeccSNamhyung Kim 	 *                  cmd_record
3550506aeccSNamhyung Kim 	 *                  run_command
3560506aeccSNamhyung Kim 	 *                  main
3570506aeccSNamhyung Kim 	 *
3580506aeccSNamhyung Kim 	 *   10.00%     perf  perf           [.] cmd_record
3590506aeccSNamhyung Kim 	 *              |
3600506aeccSNamhyung Kim 	 *              --- cmd_record
3610506aeccSNamhyung Kim 	 *                  run_command
3620506aeccSNamhyung Kim 	 *                  main
3630506aeccSNamhyung Kim 	 *
3640506aeccSNamhyung Kim 	 */
3650506aeccSNamhyung Kim 	struct result expected[] = {
3660506aeccSNamhyung Kim 		{ 0, 2000, "perf", "perf",     "main" },
3670506aeccSNamhyung Kim 		{ 0, 1000, "bash", "[kernel]", "page_fault" },
3680506aeccSNamhyung Kim 		{ 0, 1000, "bash", "bash",     "main" },
3690506aeccSNamhyung Kim 		{ 0, 1000, "bash", "bash",     "xmalloc" },
3700506aeccSNamhyung Kim 		{ 0, 1000, "perf", "[kernel]", "page_fault" },
3710506aeccSNamhyung Kim 		{ 0, 1000, "perf", "[kernel]", "schedule" },
3720506aeccSNamhyung Kim 		{ 0, 1000, "perf", "libc",     "free" },
3730506aeccSNamhyung Kim 		{ 0, 1000, "perf", "libc",     "malloc" },
3740506aeccSNamhyung Kim 		{ 0, 1000, "perf", "perf",     "cmd_record" },
3750506aeccSNamhyung Kim 	};
3760506aeccSNamhyung Kim 	struct callchain_result expected_callchain[] = {
3770506aeccSNamhyung Kim 		{
3780506aeccSNamhyung Kim 			1, {	{ "perf",     "main" }, },
3790506aeccSNamhyung Kim 		},
3800506aeccSNamhyung Kim 		{
3810506aeccSNamhyung Kim 			3, {	{ "[kernel]", "page_fault" },
3820506aeccSNamhyung Kim 				{ "libc",     "malloc" },
3830506aeccSNamhyung Kim 				{ "bash",     "main" }, },
3840506aeccSNamhyung Kim 		},
3850506aeccSNamhyung Kim 		{
3860506aeccSNamhyung Kim 			1, {	{ "bash",     "main" }, },
3870506aeccSNamhyung Kim 		},
3880506aeccSNamhyung Kim 		{
3890506aeccSNamhyung Kim 			6, {	{ "bash",     "xmalloc" },
3900506aeccSNamhyung Kim 				{ "libc",     "malloc" },
3910506aeccSNamhyung Kim 				{ "bash",     "xmalloc" },
3920506aeccSNamhyung Kim 				{ "libc",     "malloc" },
3930506aeccSNamhyung Kim 				{ "bash",     "xmalloc" },
3940506aeccSNamhyung Kim 				{ "bash",     "main" }, },
3950506aeccSNamhyung Kim 		},
3960506aeccSNamhyung Kim 		{
3970506aeccSNamhyung Kim 			4, {	{ "[kernel]", "page_fault" },
3980506aeccSNamhyung Kim 				{ "[kernel]", "sys_perf_event_open" },
3990506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4000506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4010506aeccSNamhyung Kim 		},
4020506aeccSNamhyung Kim 		{
4030506aeccSNamhyung Kim 			3, {	{ "[kernel]", "schedule" },
4040506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4050506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4060506aeccSNamhyung Kim 		},
4070506aeccSNamhyung Kim 		{
4080506aeccSNamhyung Kim 			4, {	{ "libc",     "free" },
4090506aeccSNamhyung Kim 				{ "perf",     "cmd_record" },
4100506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4110506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4120506aeccSNamhyung Kim 		},
4130506aeccSNamhyung Kim 		{
4140506aeccSNamhyung Kim 			4, {	{ "libc",     "malloc" },
4150506aeccSNamhyung Kim 				{ "perf",     "cmd_record" },
4160506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4170506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4180506aeccSNamhyung Kim 		},
4190506aeccSNamhyung Kim 		{
4200506aeccSNamhyung Kim 			3, {	{ "perf",     "cmd_record" },
4210506aeccSNamhyung Kim 				{ "perf",     "run_command" },
4220506aeccSNamhyung Kim 				{ "perf",     "main" }, },
4230506aeccSNamhyung Kim 		},
4240506aeccSNamhyung Kim 	};
4250506aeccSNamhyung Kim 
4260506aeccSNamhyung Kim 	symbol_conf.use_callchain = true;
4270506aeccSNamhyung Kim 	symbol_conf.cumulate_callchain = false;
428f9db0d0fSKan Liang 	perf_evsel__set_sample_bit(evsel, CALLCHAIN);
4290506aeccSNamhyung Kim 
43040184c46SNamhyung Kim 	setup_sorting(NULL);
4310506aeccSNamhyung Kim 	callchain_register_param(&callchain_param);
4320506aeccSNamhyung Kim 
4330506aeccSNamhyung Kim 	err = add_hist_entries(hists, machine);
4340506aeccSNamhyung Kim 	if (err < 0)
4350506aeccSNamhyung Kim 		goto out;
4360506aeccSNamhyung Kim 
4370506aeccSNamhyung Kim 	err = do_test(hists, expected, ARRAY_SIZE(expected),
4380506aeccSNamhyung Kim 		      expected_callchain, ARRAY_SIZE(expected_callchain));
4390506aeccSNamhyung Kim 
4400506aeccSNamhyung Kim out:
4410506aeccSNamhyung Kim 	del_hist_entries(hists);
4420506aeccSNamhyung Kim 	reset_output_field();
4430506aeccSNamhyung Kim 	return err;
4440506aeccSNamhyung Kim }
4450506aeccSNamhyung Kim 
4460506aeccSNamhyung Kim /* NO callchain + children */
4470506aeccSNamhyung Kim static int test3(struct perf_evsel *evsel, struct machine *machine)
4480506aeccSNamhyung Kim {
4490506aeccSNamhyung Kim 	int err;
4504ea062edSArnaldo Carvalho de Melo 	struct hists *hists = evsel__hists(evsel);
4510506aeccSNamhyung Kim 	/*
4520506aeccSNamhyung Kim 	 * expected output:
4530506aeccSNamhyung Kim 	 *
4540506aeccSNamhyung Kim 	 * Children      Self  Command  Shared Object                   Symbol
4550506aeccSNamhyung Kim 	 * ========  ========  =======  =============  =======================
4560506aeccSNamhyung Kim 	 *   70.00%    20.00%     perf  perf           [.] main
4570506aeccSNamhyung Kim 	 *   50.00%     0.00%     perf  perf           [.] run_command
4580506aeccSNamhyung Kim 	 *   30.00%    10.00%     bash  bash           [.] main
4590506aeccSNamhyung Kim 	 *   30.00%    10.00%     perf  perf           [.] cmd_record
4600506aeccSNamhyung Kim 	 *   20.00%     0.00%     bash  libc           [.] malloc
4610506aeccSNamhyung Kim 	 *   10.00%    10.00%     bash  [kernel]       [k] page_fault
4620506aeccSNamhyung Kim 	 *   10.00%    10.00%     bash  bash           [.] xmalloc
4635ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  [kernel]       [k] page_fault
4645ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  libc           [.] malloc
4655ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  [kernel]       [k] schedule
4665ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  libc           [.] free
4675ca82710SNamhyung Kim 	 *   10.00%     0.00%     perf  [kernel]       [k] sys_perf_event_open
4680506aeccSNamhyung Kim 	 */
4690506aeccSNamhyung Kim 	struct result expected[] = {
4700506aeccSNamhyung Kim 		{ 7000, 2000, "perf", "perf",     "main" },
4710506aeccSNamhyung Kim 		{ 5000,    0, "perf", "perf",     "run_command" },
4720506aeccSNamhyung Kim 		{ 3000, 1000, "bash", "bash",     "main" },
4730506aeccSNamhyung Kim 		{ 3000, 1000, "perf", "perf",     "cmd_record" },
4740506aeccSNamhyung Kim 		{ 2000,    0, "bash", "libc",     "malloc" },
4750506aeccSNamhyung Kim 		{ 1000, 1000, "bash", "[kernel]", "page_fault" },
4765ca82710SNamhyung Kim 		{ 1000, 1000, "bash", "bash",     "xmalloc" },
4770506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "[kernel]", "page_fault" },
4785ca82710SNamhyung Kim 		{ 1000, 1000, "perf", "[kernel]", "schedule" },
4790506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "libc",     "free" },
4800506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "libc",     "malloc" },
4815ca82710SNamhyung Kim 		{ 1000,    0, "perf", "[kernel]", "sys_perf_event_open" },
4820506aeccSNamhyung Kim 	};
4830506aeccSNamhyung Kim 
4840506aeccSNamhyung Kim 	symbol_conf.use_callchain = false;
4850506aeccSNamhyung Kim 	symbol_conf.cumulate_callchain = true;
486f9db0d0fSKan Liang 	perf_evsel__reset_sample_bit(evsel, CALLCHAIN);
4870506aeccSNamhyung Kim 
48840184c46SNamhyung Kim 	setup_sorting(NULL);
4890506aeccSNamhyung Kim 	callchain_register_param(&callchain_param);
4900506aeccSNamhyung Kim 
4910506aeccSNamhyung Kim 	err = add_hist_entries(hists, machine);
4920506aeccSNamhyung Kim 	if (err < 0)
4930506aeccSNamhyung Kim 		goto out;
4940506aeccSNamhyung Kim 
4950506aeccSNamhyung Kim 	err = do_test(hists, expected, ARRAY_SIZE(expected), NULL, 0);
4960506aeccSNamhyung Kim 
4970506aeccSNamhyung Kim out:
4980506aeccSNamhyung Kim 	del_hist_entries(hists);
4990506aeccSNamhyung Kim 	reset_output_field();
5000506aeccSNamhyung Kim 	return err;
5010506aeccSNamhyung Kim }
5020506aeccSNamhyung Kim 
5030506aeccSNamhyung Kim /* callchain + children */
5040506aeccSNamhyung Kim static int test4(struct perf_evsel *evsel, struct machine *machine)
5050506aeccSNamhyung Kim {
5060506aeccSNamhyung Kim 	int err;
5074ea062edSArnaldo Carvalho de Melo 	struct hists *hists = evsel__hists(evsel);
5080506aeccSNamhyung Kim 	/*
5090506aeccSNamhyung Kim 	 * expected output:
5100506aeccSNamhyung Kim 	 *
5110506aeccSNamhyung Kim 	 * Children      Self  Command  Shared Object                   Symbol
5120506aeccSNamhyung Kim 	 * ========  ========  =======  =============  =======================
5130506aeccSNamhyung Kim 	 *   70.00%    20.00%     perf  perf           [.] main
5140506aeccSNamhyung Kim 	 *              |
5150506aeccSNamhyung Kim 	 *              --- main
5160506aeccSNamhyung Kim 	 *
5170506aeccSNamhyung Kim 	 *   50.00%     0.00%     perf  perf           [.] run_command
5180506aeccSNamhyung Kim 	 *              |
5190506aeccSNamhyung Kim 	 *              --- run_command
5200506aeccSNamhyung Kim 	 *                  main
5210506aeccSNamhyung Kim 	 *
5220506aeccSNamhyung Kim 	 *   30.00%    10.00%     bash  bash           [.] main
5230506aeccSNamhyung Kim 	 *              |
5240506aeccSNamhyung Kim 	 *              --- main
5250506aeccSNamhyung Kim 	 *
5260506aeccSNamhyung Kim 	 *   30.00%    10.00%     perf  perf           [.] cmd_record
5270506aeccSNamhyung Kim 	 *              |
5280506aeccSNamhyung Kim 	 *              --- cmd_record
5290506aeccSNamhyung Kim 	 *                  run_command
5300506aeccSNamhyung Kim 	 *                  main
5310506aeccSNamhyung Kim 	 *
5320506aeccSNamhyung Kim 	 *   20.00%     0.00%     bash  libc           [.] malloc
5330506aeccSNamhyung Kim 	 *              |
5340506aeccSNamhyung Kim 	 *              --- malloc
5350506aeccSNamhyung Kim 	 *                 |
5360506aeccSNamhyung Kim 	 *                 |--50.00%-- xmalloc
5370506aeccSNamhyung Kim 	 *                 |           main
5380506aeccSNamhyung Kim 	 *                  --50.00%-- main
5390506aeccSNamhyung Kim 	 *
5400506aeccSNamhyung Kim 	 *   10.00%    10.00%     bash  [kernel]       [k] page_fault
5410506aeccSNamhyung Kim 	 *              |
5420506aeccSNamhyung Kim 	 *              --- page_fault
5430506aeccSNamhyung Kim 	 *                  malloc
5440506aeccSNamhyung Kim 	 *                  main
5450506aeccSNamhyung Kim 	 *
5465ca82710SNamhyung Kim 	 *   10.00%    10.00%     bash  bash           [.] xmalloc
5470506aeccSNamhyung Kim 	 *              |
5485ca82710SNamhyung Kim 	 *              --- xmalloc
5495ca82710SNamhyung Kim 	 *                  malloc
5505ca82710SNamhyung Kim 	 *                  xmalloc     <--- NOTE: there's a cycle
5515ca82710SNamhyung Kim 	 *                  malloc
5525ca82710SNamhyung Kim 	 *                  xmalloc
5530506aeccSNamhyung Kim 	 *                  main
5540506aeccSNamhyung Kim 	 *
5550506aeccSNamhyung Kim 	 *   10.00%     0.00%     perf  [kernel]       [k] sys_perf_event_open
5560506aeccSNamhyung Kim 	 *              |
5570506aeccSNamhyung Kim 	 *              --- sys_perf_event_open
5580506aeccSNamhyung Kim 	 *                  run_command
5590506aeccSNamhyung Kim 	 *                  main
5600506aeccSNamhyung Kim 	 *
5610506aeccSNamhyung Kim 	 *   10.00%    10.00%     perf  [kernel]       [k] page_fault
5620506aeccSNamhyung Kim 	 *              |
5630506aeccSNamhyung Kim 	 *              --- page_fault
5640506aeccSNamhyung Kim 	 *                  sys_perf_event_open
5650506aeccSNamhyung Kim 	 *                  run_command
5660506aeccSNamhyung Kim 	 *                  main
5670506aeccSNamhyung Kim 	 *
5685ca82710SNamhyung Kim 	 *   10.00%    10.00%     perf  [kernel]       [k] schedule
5695ca82710SNamhyung Kim 	 *              |
5705ca82710SNamhyung Kim 	 *              --- schedule
5715ca82710SNamhyung Kim 	 *                  run_command
5725ca82710SNamhyung Kim 	 *                  main
5735ca82710SNamhyung Kim 	 *
5740506aeccSNamhyung Kim 	 *   10.00%    10.00%     perf  libc           [.] free
5750506aeccSNamhyung Kim 	 *              |
5760506aeccSNamhyung Kim 	 *              --- free
5770506aeccSNamhyung Kim 	 *                  cmd_record
5780506aeccSNamhyung Kim 	 *                  run_command
5790506aeccSNamhyung Kim 	 *                  main
5800506aeccSNamhyung Kim 	 *
5810506aeccSNamhyung Kim 	 *   10.00%    10.00%     perf  libc           [.] malloc
5820506aeccSNamhyung Kim 	 *              |
5830506aeccSNamhyung Kim 	 *              --- malloc
5840506aeccSNamhyung Kim 	 *                  cmd_record
5850506aeccSNamhyung Kim 	 *                  run_command
5860506aeccSNamhyung Kim 	 *                  main
5870506aeccSNamhyung Kim 	 *
5880506aeccSNamhyung Kim 	 */
5890506aeccSNamhyung Kim 	struct result expected[] = {
5900506aeccSNamhyung Kim 		{ 7000, 2000, "perf", "perf",     "main" },
5910506aeccSNamhyung Kim 		{ 5000,    0, "perf", "perf",     "run_command" },
5920506aeccSNamhyung Kim 		{ 3000, 1000, "bash", "bash",     "main" },
5930506aeccSNamhyung Kim 		{ 3000, 1000, "perf", "perf",     "cmd_record" },
5940506aeccSNamhyung Kim 		{ 2000,    0, "bash", "libc",     "malloc" },
5950506aeccSNamhyung Kim 		{ 1000, 1000, "bash", "[kernel]", "page_fault" },
5965ca82710SNamhyung Kim 		{ 1000, 1000, "bash", "bash",     "xmalloc" },
5970506aeccSNamhyung Kim 		{ 1000,    0, "perf", "[kernel]", "sys_perf_event_open" },
5980506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "[kernel]", "page_fault" },
5995ca82710SNamhyung Kim 		{ 1000, 1000, "perf", "[kernel]", "schedule" },
6000506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "libc",     "free" },
6010506aeccSNamhyung Kim 		{ 1000, 1000, "perf", "libc",     "malloc" },
6020506aeccSNamhyung Kim 	};
6030506aeccSNamhyung Kim 	struct callchain_result expected_callchain[] = {
6040506aeccSNamhyung Kim 		{
6050506aeccSNamhyung Kim 			1, {	{ "perf",     "main" }, },
6060506aeccSNamhyung Kim 		},
6070506aeccSNamhyung Kim 		{
6080506aeccSNamhyung Kim 			2, {	{ "perf",     "run_command" },
6090506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6100506aeccSNamhyung Kim 		},
6110506aeccSNamhyung Kim 		{
6120506aeccSNamhyung Kim 			1, {	{ "bash",     "main" }, },
6130506aeccSNamhyung Kim 		},
6140506aeccSNamhyung Kim 		{
6150506aeccSNamhyung Kim 			3, {	{ "perf",     "cmd_record" },
6160506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6170506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6180506aeccSNamhyung Kim 		},
6190506aeccSNamhyung Kim 		{
6200506aeccSNamhyung Kim 			4, {	{ "libc",     "malloc" },
6210506aeccSNamhyung Kim 				{ "bash",     "xmalloc" },
6220506aeccSNamhyung Kim 				{ "bash",     "main" },
6230506aeccSNamhyung Kim 				{ "bash",     "main" }, },
6240506aeccSNamhyung Kim 		},
6250506aeccSNamhyung Kim 		{
6260506aeccSNamhyung Kim 			3, {	{ "[kernel]", "page_fault" },
6270506aeccSNamhyung Kim 				{ "libc",     "malloc" },
6280506aeccSNamhyung Kim 				{ "bash",     "main" }, },
6290506aeccSNamhyung Kim 		},
6300506aeccSNamhyung Kim 		{
6315ca82710SNamhyung Kim 			6, {	{ "bash",     "xmalloc" },
6325ca82710SNamhyung Kim 				{ "libc",     "malloc" },
6335ca82710SNamhyung Kim 				{ "bash",     "xmalloc" },
6345ca82710SNamhyung Kim 				{ "libc",     "malloc" },
6355ca82710SNamhyung Kim 				{ "bash",     "xmalloc" },
6365ca82710SNamhyung Kim 				{ "bash",     "main" }, },
6370506aeccSNamhyung Kim 		},
6380506aeccSNamhyung Kim 		{
6390506aeccSNamhyung Kim 			3, {	{ "[kernel]", "sys_perf_event_open" },
6400506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6410506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6420506aeccSNamhyung Kim 		},
6430506aeccSNamhyung Kim 		{
6440506aeccSNamhyung Kim 			4, {	{ "[kernel]", "page_fault" },
6450506aeccSNamhyung Kim 				{ "[kernel]", "sys_perf_event_open" },
6460506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6470506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6480506aeccSNamhyung Kim 		},
6490506aeccSNamhyung Kim 		{
6505ca82710SNamhyung Kim 			3, {	{ "[kernel]", "schedule" },
6515ca82710SNamhyung Kim 				{ "perf",     "run_command" },
6525ca82710SNamhyung Kim 				{ "perf",     "main" }, },
6535ca82710SNamhyung Kim 		},
6545ca82710SNamhyung Kim 		{
6550506aeccSNamhyung Kim 			4, {	{ "libc",     "free" },
6560506aeccSNamhyung Kim 				{ "perf",     "cmd_record" },
6570506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6580506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6590506aeccSNamhyung Kim 		},
6600506aeccSNamhyung Kim 		{
6610506aeccSNamhyung Kim 			4, {	{ "libc",     "malloc" },
6620506aeccSNamhyung Kim 				{ "perf",     "cmd_record" },
6630506aeccSNamhyung Kim 				{ "perf",     "run_command" },
6640506aeccSNamhyung Kim 				{ "perf",     "main" }, },
6650506aeccSNamhyung Kim 		},
6660506aeccSNamhyung Kim 	};
6670506aeccSNamhyung Kim 
6680506aeccSNamhyung Kim 	symbol_conf.use_callchain = true;
6690506aeccSNamhyung Kim 	symbol_conf.cumulate_callchain = true;
670f9db0d0fSKan Liang 	perf_evsel__set_sample_bit(evsel, CALLCHAIN);
6710506aeccSNamhyung Kim 
67240184c46SNamhyung Kim 	setup_sorting(NULL);
673347ca878SJiri Olsa 
674347ca878SJiri Olsa 	callchain_param = callchain_param_default;
6750506aeccSNamhyung Kim 	callchain_register_param(&callchain_param);
6760506aeccSNamhyung Kim 
6770506aeccSNamhyung Kim 	err = add_hist_entries(hists, machine);
6780506aeccSNamhyung Kim 	if (err < 0)
6790506aeccSNamhyung Kim 		goto out;
6800506aeccSNamhyung Kim 
6810506aeccSNamhyung Kim 	err = do_test(hists, expected, ARRAY_SIZE(expected),
6820506aeccSNamhyung Kim 		      expected_callchain, ARRAY_SIZE(expected_callchain));
6830506aeccSNamhyung Kim 
6840506aeccSNamhyung Kim out:
6850506aeccSNamhyung Kim 	del_hist_entries(hists);
6860506aeccSNamhyung Kim 	reset_output_field();
6870506aeccSNamhyung Kim 	return err;
6880506aeccSNamhyung Kim }
6890506aeccSNamhyung Kim 
690*81f17c90SArnaldo Carvalho de Melo int test__hists_cumulate(struct test *test __maybe_unused, int subtest __maybe_unused)
6910506aeccSNamhyung Kim {
6920506aeccSNamhyung Kim 	int err = TEST_FAIL;
6930506aeccSNamhyung Kim 	struct machines machines;
6940506aeccSNamhyung Kim 	struct machine *machine;
6950506aeccSNamhyung Kim 	struct perf_evsel *evsel;
6960506aeccSNamhyung Kim 	struct perf_evlist *evlist = perf_evlist__new();
6970506aeccSNamhyung Kim 	size_t i;
6980506aeccSNamhyung Kim 	test_fn_t testcases[] = {
6990506aeccSNamhyung Kim 		test1,
7000506aeccSNamhyung Kim 		test2,
7010506aeccSNamhyung Kim 		test3,
7020506aeccSNamhyung Kim 		test4,
7030506aeccSNamhyung Kim 	};
7040506aeccSNamhyung Kim 
7050506aeccSNamhyung Kim 	TEST_ASSERT_VAL("No memory", evlist);
7060506aeccSNamhyung Kim 
707b39b8393SJiri Olsa 	err = parse_events(evlist, "cpu-clock", NULL);
7080506aeccSNamhyung Kim 	if (err)
7090506aeccSNamhyung Kim 		goto out;
710b0500c16SWang Nan 	err = TEST_FAIL;
7110506aeccSNamhyung Kim 
7120506aeccSNamhyung Kim 	machines__init(&machines);
7130506aeccSNamhyung Kim 
7140506aeccSNamhyung Kim 	/* setup threads/dso/map/symbols also */
7150506aeccSNamhyung Kim 	machine = setup_fake_machine(&machines);
7160506aeccSNamhyung Kim 	if (!machine)
7170506aeccSNamhyung Kim 		goto out;
7180506aeccSNamhyung Kim 
7190506aeccSNamhyung Kim 	if (verbose > 1)
7200506aeccSNamhyung Kim 		machine__fprintf(machine, stderr);
7210506aeccSNamhyung Kim 
7220506aeccSNamhyung Kim 	evsel = perf_evlist__first(evlist);
7230506aeccSNamhyung Kim 
7240506aeccSNamhyung Kim 	for (i = 0; i < ARRAY_SIZE(testcases); i++) {
7250506aeccSNamhyung Kim 		err = testcases[i](evsel, machine);
7260506aeccSNamhyung Kim 		if (err < 0)
7270506aeccSNamhyung Kim 			break;
7280506aeccSNamhyung Kim 	}
7290506aeccSNamhyung Kim 
7300506aeccSNamhyung Kim out:
7310506aeccSNamhyung Kim 	/* tear down everything */
7320506aeccSNamhyung Kim 	perf_evlist__delete(evlist);
7330506aeccSNamhyung Kim 	machines__exit(&machines);
7340506aeccSNamhyung Kim 
7350506aeccSNamhyung Kim 	return err;
7360506aeccSNamhyung Kim }
737