xref: /openbmc/linux/tools/perf/tests/hists_link.c (revision 473398a21d28c089555117a8db4ea04e371dd03c)
1f8ebb0cdSNamhyung Kim #include "perf.h"
2f8ebb0cdSNamhyung Kim #include "tests.h"
3f8ebb0cdSNamhyung Kim #include "debug.h"
4f8ebb0cdSNamhyung Kim #include "symbol.h"
5f8ebb0cdSNamhyung Kim #include "sort.h"
6f8ebb0cdSNamhyung Kim #include "evsel.h"
7f8ebb0cdSNamhyung Kim #include "evlist.h"
8f8ebb0cdSNamhyung Kim #include "machine.h"
9f8ebb0cdSNamhyung Kim #include "thread.h"
10f8ebb0cdSNamhyung Kim #include "parse-events.h"
116e344a95SNamhyung Kim #include "hists_common.h"
12f8ebb0cdSNamhyung Kim 
13f8ebb0cdSNamhyung Kim struct sample {
14f8ebb0cdSNamhyung Kim 	u32 pid;
15f8ebb0cdSNamhyung Kim 	u64 ip;
16f8ebb0cdSNamhyung Kim 	struct thread *thread;
17f8ebb0cdSNamhyung Kim 	struct map *map;
18f8ebb0cdSNamhyung Kim 	struct symbol *sym;
19f8ebb0cdSNamhyung Kim };
20f8ebb0cdSNamhyung Kim 
216e344a95SNamhyung Kim /* For the numbers, see hists_common.c */
22f8ebb0cdSNamhyung Kim static struct sample fake_common_samples[] = {
23f8ebb0cdSNamhyung Kim 	/* perf [kernel] schedule() */
24a1891aa4SNamhyung Kim 	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, },
25f8ebb0cdSNamhyung Kim 	/* perf [perf]   main() */
26a1891aa4SNamhyung Kim 	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, },
27f8ebb0cdSNamhyung Kim 	/* perf [perf]   cmd_record() */
28a1891aa4SNamhyung Kim 	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, },
29f8ebb0cdSNamhyung Kim 	/* bash [bash]   xmalloc() */
30a1891aa4SNamhyung Kim 	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XMALLOC, },
31f8ebb0cdSNamhyung Kim 	/* bash [libc]   malloc() */
32a1891aa4SNamhyung Kim 	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_MALLOC, },
33f8ebb0cdSNamhyung Kim };
34f8ebb0cdSNamhyung Kim 
35f8ebb0cdSNamhyung Kim static struct sample fake_samples[][5] = {
36f8ebb0cdSNamhyung Kim 	{
37f8ebb0cdSNamhyung Kim 		/* perf [perf]   run_command() */
38a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_RUN_COMMAND, },
39f8ebb0cdSNamhyung Kim 		/* perf [libc]   malloc() */
40a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, },
41f8ebb0cdSNamhyung Kim 		/* perf [kernel] page_fault() */
42a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
43f8ebb0cdSNamhyung Kim 		/* perf [kernel] sys_perf_event_open() */
44a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_SYS_PERF_EVENT_OPEN, },
45f8ebb0cdSNamhyung Kim 		/* bash [libc]   free() */
46a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_FREE, },
47f8ebb0cdSNamhyung Kim 	},
48f8ebb0cdSNamhyung Kim 	{
49f8ebb0cdSNamhyung Kim 		/* perf [libc]   free() */
50a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_LIBC_FREE, },
51f8ebb0cdSNamhyung Kim 		/* bash [libc]   malloc() */
52a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_MALLOC, }, /* will be merged */
53f8ebb0cdSNamhyung Kim 		/* bash [bash]   xfee() */
54a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XFREE, },
55f8ebb0cdSNamhyung Kim 		/* bash [libc]   realloc() */
56a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_REALLOC, },
57f8ebb0cdSNamhyung Kim 		/* bash [kernel] page_fault() */
58a1891aa4SNamhyung Kim 		{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
59f8ebb0cdSNamhyung Kim 	},
60f8ebb0cdSNamhyung Kim };
61f8ebb0cdSNamhyung Kim 
62f8ebb0cdSNamhyung Kim static int add_hist_entries(struct perf_evlist *evlist, struct machine *machine)
63f8ebb0cdSNamhyung Kim {
64f8ebb0cdSNamhyung Kim 	struct perf_evsel *evsel;
65f8ebb0cdSNamhyung Kim 	struct addr_location al;
66f8ebb0cdSNamhyung Kim 	struct hist_entry *he;
67fd36f3ddSNamhyung Kim 	struct perf_sample sample = { .period = 1, .weight = 1, };
68f8ebb0cdSNamhyung Kim 	size_t i = 0, k;
69f8ebb0cdSNamhyung Kim 
70f8ebb0cdSNamhyung Kim 	/*
71f8ebb0cdSNamhyung Kim 	 * each evsel will have 10 samples - 5 common and 5 distinct.
72f8ebb0cdSNamhyung Kim 	 * However the second evsel also has a collapsed entry for
73f8ebb0cdSNamhyung Kim 	 * "bash [libc] malloc" so total 9 entries will be in the tree.
74f8ebb0cdSNamhyung Kim 	 */
750050f7aaSArnaldo Carvalho de Melo 	evlist__for_each(evlist, evsel) {
764ea062edSArnaldo Carvalho de Melo 		struct hists *hists = evsel__hists(evsel);
774ea062edSArnaldo Carvalho de Melo 
78f8ebb0cdSNamhyung Kim 		for (k = 0; k < ARRAY_SIZE(fake_common_samples); k++) {
79f8ebb0cdSNamhyung Kim 			const union perf_event event = {
80f8ebb0cdSNamhyung Kim 				.header = {
81f8ebb0cdSNamhyung Kim 					.misc = PERF_RECORD_MISC_USER,
82f8ebb0cdSNamhyung Kim 				},
83f8ebb0cdSNamhyung Kim 			};
84f8ebb0cdSNamhyung Kim 
85*473398a2SArnaldo Carvalho de Melo 			sample.cpumode = PERF_RECORD_MISC_USER;
86ef89325fSAdrian Hunter 			sample.pid = fake_common_samples[k].pid;
8713ce34dfSNamhyung Kim 			sample.tid = fake_common_samples[k].pid;
88ef89325fSAdrian Hunter 			sample.ip = fake_common_samples[k].ip;
89f8ebb0cdSNamhyung Kim 			if (perf_event__preprocess_sample(&event, machine, &al,
90e44baa3eSAdrian Hunter 							  &sample) < 0)
91f8ebb0cdSNamhyung Kim 				goto out;
92f8ebb0cdSNamhyung Kim 
934ea062edSArnaldo Carvalho de Melo 			he = __hists__add_entry(hists, &al, NULL,
94fd36f3ddSNamhyung Kim 						NULL, NULL, &sample, true);
95b91fc39fSArnaldo Carvalho de Melo 			if (he == NULL) {
96b91fc39fSArnaldo Carvalho de Melo 				addr_location__put(&al);
97f8ebb0cdSNamhyung Kim 				goto out;
98b91fc39fSArnaldo Carvalho de Melo 			}
99f8ebb0cdSNamhyung Kim 
100f8ebb0cdSNamhyung Kim 			fake_common_samples[k].thread = al.thread;
101f8ebb0cdSNamhyung Kim 			fake_common_samples[k].map = al.map;
102f8ebb0cdSNamhyung Kim 			fake_common_samples[k].sym = al.sym;
103f8ebb0cdSNamhyung Kim 		}
104f8ebb0cdSNamhyung Kim 
105f8ebb0cdSNamhyung Kim 		for (k = 0; k < ARRAY_SIZE(fake_samples[i]); k++) {
106f8ebb0cdSNamhyung Kim 			const union perf_event event = {
107f8ebb0cdSNamhyung Kim 				.header = {
108f8ebb0cdSNamhyung Kim 					.misc = PERF_RECORD_MISC_USER,
109f8ebb0cdSNamhyung Kim 				},
110f8ebb0cdSNamhyung Kim 			};
111f8ebb0cdSNamhyung Kim 
112ef89325fSAdrian Hunter 			sample.pid = fake_samples[i][k].pid;
11313ce34dfSNamhyung Kim 			sample.tid = fake_samples[i][k].pid;
114ef89325fSAdrian Hunter 			sample.ip = fake_samples[i][k].ip;
115f8ebb0cdSNamhyung Kim 			if (perf_event__preprocess_sample(&event, machine, &al,
116e44baa3eSAdrian Hunter 							  &sample) < 0)
117f8ebb0cdSNamhyung Kim 				goto out;
118f8ebb0cdSNamhyung Kim 
1194ea062edSArnaldo Carvalho de Melo 			he = __hists__add_entry(hists, &al, NULL,
120fd36f3ddSNamhyung Kim 						NULL, NULL, &sample, true);
121b91fc39fSArnaldo Carvalho de Melo 			if (he == NULL) {
122b91fc39fSArnaldo Carvalho de Melo 				addr_location__put(&al);
123f8ebb0cdSNamhyung Kim 				goto out;
124b91fc39fSArnaldo Carvalho de Melo 			}
125f8ebb0cdSNamhyung Kim 
126f8ebb0cdSNamhyung Kim 			fake_samples[i][k].thread = al.thread;
127f8ebb0cdSNamhyung Kim 			fake_samples[i][k].map = al.map;
128f8ebb0cdSNamhyung Kim 			fake_samples[i][k].sym = al.sym;
129f8ebb0cdSNamhyung Kim 		}
130f8ebb0cdSNamhyung Kim 		i++;
131f8ebb0cdSNamhyung Kim 	}
132f8ebb0cdSNamhyung Kim 
133f8ebb0cdSNamhyung Kim 	return 0;
134f8ebb0cdSNamhyung Kim 
135f8ebb0cdSNamhyung Kim out:
136f8ebb0cdSNamhyung Kim 	pr_debug("Not enough memory for adding a hist entry\n");
137f8ebb0cdSNamhyung Kim 	return -1;
138f8ebb0cdSNamhyung Kim }
139f8ebb0cdSNamhyung Kim 
140f8ebb0cdSNamhyung Kim static int find_sample(struct sample *samples, size_t nr_samples,
141f8ebb0cdSNamhyung Kim 		       struct thread *t, struct map *m, struct symbol *s)
142f8ebb0cdSNamhyung Kim {
143f8ebb0cdSNamhyung Kim 	while (nr_samples--) {
144f8ebb0cdSNamhyung Kim 		if (samples->thread == t && samples->map == m &&
145f8ebb0cdSNamhyung Kim 		    samples->sym == s)
146f8ebb0cdSNamhyung Kim 			return 1;
147f8ebb0cdSNamhyung Kim 		samples++;
148f8ebb0cdSNamhyung Kim 	}
149f8ebb0cdSNamhyung Kim 	return 0;
150f8ebb0cdSNamhyung Kim }
151f8ebb0cdSNamhyung Kim 
152f8ebb0cdSNamhyung Kim static int __validate_match(struct hists *hists)
153f8ebb0cdSNamhyung Kim {
154f8ebb0cdSNamhyung Kim 	size_t count = 0;
155f8ebb0cdSNamhyung Kim 	struct rb_root *root;
156f8ebb0cdSNamhyung Kim 	struct rb_node *node;
157f8ebb0cdSNamhyung Kim 
158f8ebb0cdSNamhyung Kim 	/*
159f8ebb0cdSNamhyung Kim 	 * Only entries from fake_common_samples should have a pair.
160f8ebb0cdSNamhyung Kim 	 */
161f8ebb0cdSNamhyung Kim 	if (sort__need_collapse)
162f8ebb0cdSNamhyung Kim 		root = &hists->entries_collapsed;
163f8ebb0cdSNamhyung Kim 	else
164f8ebb0cdSNamhyung Kim 		root = hists->entries_in;
165f8ebb0cdSNamhyung Kim 
166f8ebb0cdSNamhyung Kim 	node = rb_first(root);
167f8ebb0cdSNamhyung Kim 	while (node) {
168f8ebb0cdSNamhyung Kim 		struct hist_entry *he;
169f8ebb0cdSNamhyung Kim 
170f8ebb0cdSNamhyung Kim 		he = rb_entry(node, struct hist_entry, rb_node_in);
171f8ebb0cdSNamhyung Kim 
172f8ebb0cdSNamhyung Kim 		if (hist_entry__has_pairs(he)) {
173f8ebb0cdSNamhyung Kim 			if (find_sample(fake_common_samples,
174f8ebb0cdSNamhyung Kim 					ARRAY_SIZE(fake_common_samples),
175f8ebb0cdSNamhyung Kim 					he->thread, he->ms.map, he->ms.sym)) {
176f8ebb0cdSNamhyung Kim 				count++;
177f8ebb0cdSNamhyung Kim 			} else {
178f8ebb0cdSNamhyung Kim 				pr_debug("Can't find the matched entry\n");
179f8ebb0cdSNamhyung Kim 				return -1;
180f8ebb0cdSNamhyung Kim 			}
181f8ebb0cdSNamhyung Kim 		}
182f8ebb0cdSNamhyung Kim 
183f8ebb0cdSNamhyung Kim 		node = rb_next(node);
184f8ebb0cdSNamhyung Kim 	}
185f8ebb0cdSNamhyung Kim 
186f8ebb0cdSNamhyung Kim 	if (count != ARRAY_SIZE(fake_common_samples)) {
187f8ebb0cdSNamhyung Kim 		pr_debug("Invalid count for matched entries: %zd of %zd\n",
188f8ebb0cdSNamhyung Kim 			 count, ARRAY_SIZE(fake_common_samples));
189f8ebb0cdSNamhyung Kim 		return -1;
190f8ebb0cdSNamhyung Kim 	}
191f8ebb0cdSNamhyung Kim 
192f8ebb0cdSNamhyung Kim 	return 0;
193f8ebb0cdSNamhyung Kim }
194f8ebb0cdSNamhyung Kim 
195f8ebb0cdSNamhyung Kim static int validate_match(struct hists *leader, struct hists *other)
196f8ebb0cdSNamhyung Kim {
197f8ebb0cdSNamhyung Kim 	return __validate_match(leader) || __validate_match(other);
198f8ebb0cdSNamhyung Kim }
199f8ebb0cdSNamhyung Kim 
200f8ebb0cdSNamhyung Kim static int __validate_link(struct hists *hists, int idx)
201f8ebb0cdSNamhyung Kim {
202f8ebb0cdSNamhyung Kim 	size_t count = 0;
203f8ebb0cdSNamhyung Kim 	size_t count_pair = 0;
204f8ebb0cdSNamhyung Kim 	size_t count_dummy = 0;
205f8ebb0cdSNamhyung Kim 	struct rb_root *root;
206f8ebb0cdSNamhyung Kim 	struct rb_node *node;
207f8ebb0cdSNamhyung Kim 
208f8ebb0cdSNamhyung Kim 	/*
209f8ebb0cdSNamhyung Kim 	 * Leader hists (idx = 0) will have dummy entries from other,
210f8ebb0cdSNamhyung Kim 	 * and some entries will have no pair.  However every entry
211f8ebb0cdSNamhyung Kim 	 * in other hists should have (dummy) pair.
212f8ebb0cdSNamhyung Kim 	 */
213f8ebb0cdSNamhyung Kim 	if (sort__need_collapse)
214f8ebb0cdSNamhyung Kim 		root = &hists->entries_collapsed;
215f8ebb0cdSNamhyung Kim 	else
216f8ebb0cdSNamhyung Kim 		root = hists->entries_in;
217f8ebb0cdSNamhyung Kim 
218f8ebb0cdSNamhyung Kim 	node = rb_first(root);
219f8ebb0cdSNamhyung Kim 	while (node) {
220f8ebb0cdSNamhyung Kim 		struct hist_entry *he;
221f8ebb0cdSNamhyung Kim 
222f8ebb0cdSNamhyung Kim 		he = rb_entry(node, struct hist_entry, rb_node_in);
223f8ebb0cdSNamhyung Kim 
224f8ebb0cdSNamhyung Kim 		if (hist_entry__has_pairs(he)) {
225f8ebb0cdSNamhyung Kim 			if (!find_sample(fake_common_samples,
226f8ebb0cdSNamhyung Kim 					 ARRAY_SIZE(fake_common_samples),
227f8ebb0cdSNamhyung Kim 					 he->thread, he->ms.map, he->ms.sym) &&
228f8ebb0cdSNamhyung Kim 			    !find_sample(fake_samples[idx],
229f8ebb0cdSNamhyung Kim 					 ARRAY_SIZE(fake_samples[idx]),
230f8ebb0cdSNamhyung Kim 					 he->thread, he->ms.map, he->ms.sym)) {
231f8ebb0cdSNamhyung Kim 				count_dummy++;
232f8ebb0cdSNamhyung Kim 			}
233f8ebb0cdSNamhyung Kim 			count_pair++;
234f8ebb0cdSNamhyung Kim 		} else if (idx) {
235f8ebb0cdSNamhyung Kim 			pr_debug("A entry from the other hists should have pair\n");
236f8ebb0cdSNamhyung Kim 			return -1;
237f8ebb0cdSNamhyung Kim 		}
238f8ebb0cdSNamhyung Kim 
239f8ebb0cdSNamhyung Kim 		count++;
240f8ebb0cdSNamhyung Kim 		node = rb_next(node);
241f8ebb0cdSNamhyung Kim 	}
242f8ebb0cdSNamhyung Kim 
243f8ebb0cdSNamhyung Kim 	/*
244f8ebb0cdSNamhyung Kim 	 * Note that we have a entry collapsed in the other (idx = 1) hists.
245f8ebb0cdSNamhyung Kim 	 */
246f8ebb0cdSNamhyung Kim 	if (idx == 0) {
247f8ebb0cdSNamhyung Kim 		if (count_dummy != ARRAY_SIZE(fake_samples[1]) - 1) {
248f8ebb0cdSNamhyung Kim 			pr_debug("Invalid count of dummy entries: %zd of %zd\n",
249f8ebb0cdSNamhyung Kim 				 count_dummy, ARRAY_SIZE(fake_samples[1]) - 1);
250f8ebb0cdSNamhyung Kim 			return -1;
251f8ebb0cdSNamhyung Kim 		}
252f8ebb0cdSNamhyung Kim 		if (count != count_pair + ARRAY_SIZE(fake_samples[0])) {
253f8ebb0cdSNamhyung Kim 			pr_debug("Invalid count of total leader entries: %zd of %zd\n",
254f8ebb0cdSNamhyung Kim 				 count, count_pair + ARRAY_SIZE(fake_samples[0]));
255f8ebb0cdSNamhyung Kim 			return -1;
256f8ebb0cdSNamhyung Kim 		}
257f8ebb0cdSNamhyung Kim 	} else {
258f8ebb0cdSNamhyung Kim 		if (count != count_pair) {
259f8ebb0cdSNamhyung Kim 			pr_debug("Invalid count of total other entries: %zd of %zd\n",
260f8ebb0cdSNamhyung Kim 				 count, count_pair);
261f8ebb0cdSNamhyung Kim 			return -1;
262f8ebb0cdSNamhyung Kim 		}
263f8ebb0cdSNamhyung Kim 		if (count_dummy > 0) {
264f8ebb0cdSNamhyung Kim 			pr_debug("Other hists should not have dummy entries: %zd\n",
265f8ebb0cdSNamhyung Kim 				 count_dummy);
266f8ebb0cdSNamhyung Kim 			return -1;
267f8ebb0cdSNamhyung Kim 		}
268f8ebb0cdSNamhyung Kim 	}
269f8ebb0cdSNamhyung Kim 
270f8ebb0cdSNamhyung Kim 	return 0;
271f8ebb0cdSNamhyung Kim }
272f8ebb0cdSNamhyung Kim 
273f8ebb0cdSNamhyung Kim static int validate_link(struct hists *leader, struct hists *other)
274f8ebb0cdSNamhyung Kim {
275f8ebb0cdSNamhyung Kim 	return __validate_link(leader, 0) || __validate_link(other, 1);
276f8ebb0cdSNamhyung Kim }
277f8ebb0cdSNamhyung Kim 
278721a1f53SArnaldo Carvalho de Melo int test__hists_link(int subtest __maybe_unused)
279f8ebb0cdSNamhyung Kim {
280f8ebb0cdSNamhyung Kim 	int err = -1;
2814ea062edSArnaldo Carvalho de Melo 	struct hists *hists, *first_hists;
282876650e6SArnaldo Carvalho de Melo 	struct machines machines;
283f8ebb0cdSNamhyung Kim 	struct machine *machine = NULL;
284f8ebb0cdSNamhyung Kim 	struct perf_evsel *evsel, *first;
285334fe7a3SNamhyung Kim 	struct perf_evlist *evlist = perf_evlist__new();
286f8ebb0cdSNamhyung Kim 
287f8ebb0cdSNamhyung Kim 	if (evlist == NULL)
288f8ebb0cdSNamhyung Kim                 return -ENOMEM;
289f8ebb0cdSNamhyung Kim 
290b39b8393SJiri Olsa 	err = parse_events(evlist, "cpu-clock", NULL);
291f8ebb0cdSNamhyung Kim 	if (err)
292f8ebb0cdSNamhyung Kim 		goto out;
293b39b8393SJiri Olsa 	err = parse_events(evlist, "task-clock", NULL);
294f8ebb0cdSNamhyung Kim 	if (err)
295f8ebb0cdSNamhyung Kim 		goto out;
296f8ebb0cdSNamhyung Kim 
297b0500c16SWang Nan 	err = TEST_FAIL;
298f8ebb0cdSNamhyung Kim 	/* default sort order (comm,dso,sym) will be used */
29940184c46SNamhyung Kim 	if (setup_sorting(NULL) < 0)
30055309985SNamhyung Kim 		goto out;
301f8ebb0cdSNamhyung Kim 
302876650e6SArnaldo Carvalho de Melo 	machines__init(&machines);
303876650e6SArnaldo Carvalho de Melo 
304f8ebb0cdSNamhyung Kim 	/* setup threads/dso/map/symbols also */
305876650e6SArnaldo Carvalho de Melo 	machine = setup_fake_machine(&machines);
306f8ebb0cdSNamhyung Kim 	if (!machine)
307f8ebb0cdSNamhyung Kim 		goto out;
308f8ebb0cdSNamhyung Kim 
309f8ebb0cdSNamhyung Kim 	if (verbose > 1)
310f8ebb0cdSNamhyung Kim 		machine__fprintf(machine, stderr);
311f8ebb0cdSNamhyung Kim 
312f8ebb0cdSNamhyung Kim 	/* process sample events */
313f8ebb0cdSNamhyung Kim 	err = add_hist_entries(evlist, machine);
314f8ebb0cdSNamhyung Kim 	if (err < 0)
315f8ebb0cdSNamhyung Kim 		goto out;
316f8ebb0cdSNamhyung Kim 
3170050f7aaSArnaldo Carvalho de Melo 	evlist__for_each(evlist, evsel) {
3184ea062edSArnaldo Carvalho de Melo 		hists = evsel__hists(evsel);
3194ea062edSArnaldo Carvalho de Melo 		hists__collapse_resort(hists, NULL);
320f8ebb0cdSNamhyung Kim 
321f8ebb0cdSNamhyung Kim 		if (verbose > 2)
3224ea062edSArnaldo Carvalho de Melo 			print_hists_in(hists);
323f8ebb0cdSNamhyung Kim 	}
324f8ebb0cdSNamhyung Kim 
325f8ebb0cdSNamhyung Kim 	first = perf_evlist__first(evlist);
326f8ebb0cdSNamhyung Kim 	evsel = perf_evlist__last(evlist);
327f8ebb0cdSNamhyung Kim 
3284ea062edSArnaldo Carvalho de Melo 	first_hists = evsel__hists(first);
3294ea062edSArnaldo Carvalho de Melo 	hists = evsel__hists(evsel);
3304ea062edSArnaldo Carvalho de Melo 
331f8ebb0cdSNamhyung Kim 	/* match common entries */
3324ea062edSArnaldo Carvalho de Melo 	hists__match(first_hists, hists);
3334ea062edSArnaldo Carvalho de Melo 	err = validate_match(first_hists, hists);
334f8ebb0cdSNamhyung Kim 	if (err)
335f8ebb0cdSNamhyung Kim 		goto out;
336f8ebb0cdSNamhyung Kim 
337f8ebb0cdSNamhyung Kim 	/* link common and/or dummy entries */
3384ea062edSArnaldo Carvalho de Melo 	hists__link(first_hists, hists);
3394ea062edSArnaldo Carvalho de Melo 	err = validate_link(first_hists, hists);
340f8ebb0cdSNamhyung Kim 	if (err)
341f8ebb0cdSNamhyung Kim 		goto out;
342f8ebb0cdSNamhyung Kim 
343f8ebb0cdSNamhyung Kim 	err = 0;
344f8ebb0cdSNamhyung Kim 
345f8ebb0cdSNamhyung Kim out:
346f8ebb0cdSNamhyung Kim 	/* tear down everything */
347f8ebb0cdSNamhyung Kim 	perf_evlist__delete(evlist);
348f21d1815SNamhyung Kim 	reset_output_field();
349876650e6SArnaldo Carvalho de Melo 	machines__exit(&machines);
350f8ebb0cdSNamhyung Kim 
351f8ebb0cdSNamhyung Kim 	return err;
352f8ebb0cdSNamhyung Kim }
353