xref: /openbmc/linux/tools/perf/tests/hists_link.c (revision 4ea062ed431d00153af0ac370cb6fef0620e5fa1)
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;
67a1891aa4SNamhyung Kim 	struct perf_sample sample = { .period = 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) {
76*4ea062edSArnaldo Carvalho de Melo 		struct hists *hists = evsel__hists(evsel);
77*4ea062edSArnaldo 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 
85ef89325fSAdrian Hunter 			sample.pid = fake_common_samples[k].pid;
8613ce34dfSNamhyung Kim 			sample.tid = fake_common_samples[k].pid;
87ef89325fSAdrian Hunter 			sample.ip = fake_common_samples[k].ip;
88f8ebb0cdSNamhyung Kim 			if (perf_event__preprocess_sample(&event, machine, &al,
89e44baa3eSAdrian Hunter 							  &sample) < 0)
90f8ebb0cdSNamhyung Kim 				goto out;
91f8ebb0cdSNamhyung Kim 
92*4ea062edSArnaldo Carvalho de Melo 			he = __hists__add_entry(hists, &al, NULL,
93a0b51af3SNamhyung Kim 						NULL, NULL, 1, 1, 0, true);
94f8ebb0cdSNamhyung Kim 			if (he == NULL)
95f8ebb0cdSNamhyung Kim 				goto out;
96f8ebb0cdSNamhyung Kim 
97f8ebb0cdSNamhyung Kim 			fake_common_samples[k].thread = al.thread;
98f8ebb0cdSNamhyung Kim 			fake_common_samples[k].map = al.map;
99f8ebb0cdSNamhyung Kim 			fake_common_samples[k].sym = al.sym;
100f8ebb0cdSNamhyung Kim 		}
101f8ebb0cdSNamhyung Kim 
102f8ebb0cdSNamhyung Kim 		for (k = 0; k < ARRAY_SIZE(fake_samples[i]); k++) {
103f8ebb0cdSNamhyung Kim 			const union perf_event event = {
104f8ebb0cdSNamhyung Kim 				.header = {
105f8ebb0cdSNamhyung Kim 					.misc = PERF_RECORD_MISC_USER,
106f8ebb0cdSNamhyung Kim 				},
107f8ebb0cdSNamhyung Kim 			};
108f8ebb0cdSNamhyung Kim 
109ef89325fSAdrian Hunter 			sample.pid = fake_samples[i][k].pid;
11013ce34dfSNamhyung Kim 			sample.tid = fake_samples[i][k].pid;
111ef89325fSAdrian Hunter 			sample.ip = fake_samples[i][k].ip;
112f8ebb0cdSNamhyung Kim 			if (perf_event__preprocess_sample(&event, machine, &al,
113e44baa3eSAdrian Hunter 							  &sample) < 0)
114f8ebb0cdSNamhyung Kim 				goto out;
115f8ebb0cdSNamhyung Kim 
116*4ea062edSArnaldo Carvalho de Melo 			he = __hists__add_entry(hists, &al, NULL,
117a0b51af3SNamhyung Kim 						NULL, NULL, 1, 1, 0, true);
118f8ebb0cdSNamhyung Kim 			if (he == NULL)
119f8ebb0cdSNamhyung Kim 				goto out;
120f8ebb0cdSNamhyung Kim 
121f8ebb0cdSNamhyung Kim 			fake_samples[i][k].thread = al.thread;
122f8ebb0cdSNamhyung Kim 			fake_samples[i][k].map = al.map;
123f8ebb0cdSNamhyung Kim 			fake_samples[i][k].sym = al.sym;
124f8ebb0cdSNamhyung Kim 		}
125f8ebb0cdSNamhyung Kim 		i++;
126f8ebb0cdSNamhyung Kim 	}
127f8ebb0cdSNamhyung Kim 
128f8ebb0cdSNamhyung Kim 	return 0;
129f8ebb0cdSNamhyung Kim 
130f8ebb0cdSNamhyung Kim out:
131f8ebb0cdSNamhyung Kim 	pr_debug("Not enough memory for adding a hist entry\n");
132f8ebb0cdSNamhyung Kim 	return -1;
133f8ebb0cdSNamhyung Kim }
134f8ebb0cdSNamhyung Kim 
135f8ebb0cdSNamhyung Kim static int find_sample(struct sample *samples, size_t nr_samples,
136f8ebb0cdSNamhyung Kim 		       struct thread *t, struct map *m, struct symbol *s)
137f8ebb0cdSNamhyung Kim {
138f8ebb0cdSNamhyung Kim 	while (nr_samples--) {
139f8ebb0cdSNamhyung Kim 		if (samples->thread == t && samples->map == m &&
140f8ebb0cdSNamhyung Kim 		    samples->sym == s)
141f8ebb0cdSNamhyung Kim 			return 1;
142f8ebb0cdSNamhyung Kim 		samples++;
143f8ebb0cdSNamhyung Kim 	}
144f8ebb0cdSNamhyung Kim 	return 0;
145f8ebb0cdSNamhyung Kim }
146f8ebb0cdSNamhyung Kim 
147f8ebb0cdSNamhyung Kim static int __validate_match(struct hists *hists)
148f8ebb0cdSNamhyung Kim {
149f8ebb0cdSNamhyung Kim 	size_t count = 0;
150f8ebb0cdSNamhyung Kim 	struct rb_root *root;
151f8ebb0cdSNamhyung Kim 	struct rb_node *node;
152f8ebb0cdSNamhyung Kim 
153f8ebb0cdSNamhyung Kim 	/*
154f8ebb0cdSNamhyung Kim 	 * Only entries from fake_common_samples should have a pair.
155f8ebb0cdSNamhyung Kim 	 */
156f8ebb0cdSNamhyung Kim 	if (sort__need_collapse)
157f8ebb0cdSNamhyung Kim 		root = &hists->entries_collapsed;
158f8ebb0cdSNamhyung Kim 	else
159f8ebb0cdSNamhyung Kim 		root = hists->entries_in;
160f8ebb0cdSNamhyung Kim 
161f8ebb0cdSNamhyung Kim 	node = rb_first(root);
162f8ebb0cdSNamhyung Kim 	while (node) {
163f8ebb0cdSNamhyung Kim 		struct hist_entry *he;
164f8ebb0cdSNamhyung Kim 
165f8ebb0cdSNamhyung Kim 		he = rb_entry(node, struct hist_entry, rb_node_in);
166f8ebb0cdSNamhyung Kim 
167f8ebb0cdSNamhyung Kim 		if (hist_entry__has_pairs(he)) {
168f8ebb0cdSNamhyung Kim 			if (find_sample(fake_common_samples,
169f8ebb0cdSNamhyung Kim 					ARRAY_SIZE(fake_common_samples),
170f8ebb0cdSNamhyung Kim 					he->thread, he->ms.map, he->ms.sym)) {
171f8ebb0cdSNamhyung Kim 				count++;
172f8ebb0cdSNamhyung Kim 			} else {
173f8ebb0cdSNamhyung Kim 				pr_debug("Can't find the matched entry\n");
174f8ebb0cdSNamhyung Kim 				return -1;
175f8ebb0cdSNamhyung Kim 			}
176f8ebb0cdSNamhyung Kim 		}
177f8ebb0cdSNamhyung Kim 
178f8ebb0cdSNamhyung Kim 		node = rb_next(node);
179f8ebb0cdSNamhyung Kim 	}
180f8ebb0cdSNamhyung Kim 
181f8ebb0cdSNamhyung Kim 	if (count != ARRAY_SIZE(fake_common_samples)) {
182f8ebb0cdSNamhyung Kim 		pr_debug("Invalid count for matched entries: %zd of %zd\n",
183f8ebb0cdSNamhyung Kim 			 count, ARRAY_SIZE(fake_common_samples));
184f8ebb0cdSNamhyung Kim 		return -1;
185f8ebb0cdSNamhyung Kim 	}
186f8ebb0cdSNamhyung Kim 
187f8ebb0cdSNamhyung Kim 	return 0;
188f8ebb0cdSNamhyung Kim }
189f8ebb0cdSNamhyung Kim 
190f8ebb0cdSNamhyung Kim static int validate_match(struct hists *leader, struct hists *other)
191f8ebb0cdSNamhyung Kim {
192f8ebb0cdSNamhyung Kim 	return __validate_match(leader) || __validate_match(other);
193f8ebb0cdSNamhyung Kim }
194f8ebb0cdSNamhyung Kim 
195f8ebb0cdSNamhyung Kim static int __validate_link(struct hists *hists, int idx)
196f8ebb0cdSNamhyung Kim {
197f8ebb0cdSNamhyung Kim 	size_t count = 0;
198f8ebb0cdSNamhyung Kim 	size_t count_pair = 0;
199f8ebb0cdSNamhyung Kim 	size_t count_dummy = 0;
200f8ebb0cdSNamhyung Kim 	struct rb_root *root;
201f8ebb0cdSNamhyung Kim 	struct rb_node *node;
202f8ebb0cdSNamhyung Kim 
203f8ebb0cdSNamhyung Kim 	/*
204f8ebb0cdSNamhyung Kim 	 * Leader hists (idx = 0) will have dummy entries from other,
205f8ebb0cdSNamhyung Kim 	 * and some entries will have no pair.  However every entry
206f8ebb0cdSNamhyung Kim 	 * in other hists should have (dummy) pair.
207f8ebb0cdSNamhyung Kim 	 */
208f8ebb0cdSNamhyung Kim 	if (sort__need_collapse)
209f8ebb0cdSNamhyung Kim 		root = &hists->entries_collapsed;
210f8ebb0cdSNamhyung Kim 	else
211f8ebb0cdSNamhyung Kim 		root = hists->entries_in;
212f8ebb0cdSNamhyung Kim 
213f8ebb0cdSNamhyung Kim 	node = rb_first(root);
214f8ebb0cdSNamhyung Kim 	while (node) {
215f8ebb0cdSNamhyung Kim 		struct hist_entry *he;
216f8ebb0cdSNamhyung Kim 
217f8ebb0cdSNamhyung Kim 		he = rb_entry(node, struct hist_entry, rb_node_in);
218f8ebb0cdSNamhyung Kim 
219f8ebb0cdSNamhyung Kim 		if (hist_entry__has_pairs(he)) {
220f8ebb0cdSNamhyung Kim 			if (!find_sample(fake_common_samples,
221f8ebb0cdSNamhyung Kim 					 ARRAY_SIZE(fake_common_samples),
222f8ebb0cdSNamhyung Kim 					 he->thread, he->ms.map, he->ms.sym) &&
223f8ebb0cdSNamhyung Kim 			    !find_sample(fake_samples[idx],
224f8ebb0cdSNamhyung Kim 					 ARRAY_SIZE(fake_samples[idx]),
225f8ebb0cdSNamhyung Kim 					 he->thread, he->ms.map, he->ms.sym)) {
226f8ebb0cdSNamhyung Kim 				count_dummy++;
227f8ebb0cdSNamhyung Kim 			}
228f8ebb0cdSNamhyung Kim 			count_pair++;
229f8ebb0cdSNamhyung Kim 		} else if (idx) {
230f8ebb0cdSNamhyung Kim 			pr_debug("A entry from the other hists should have pair\n");
231f8ebb0cdSNamhyung Kim 			return -1;
232f8ebb0cdSNamhyung Kim 		}
233f8ebb0cdSNamhyung Kim 
234f8ebb0cdSNamhyung Kim 		count++;
235f8ebb0cdSNamhyung Kim 		node = rb_next(node);
236f8ebb0cdSNamhyung Kim 	}
237f8ebb0cdSNamhyung Kim 
238f8ebb0cdSNamhyung Kim 	/*
239f8ebb0cdSNamhyung Kim 	 * Note that we have a entry collapsed in the other (idx = 1) hists.
240f8ebb0cdSNamhyung Kim 	 */
241f8ebb0cdSNamhyung Kim 	if (idx == 0) {
242f8ebb0cdSNamhyung Kim 		if (count_dummy != ARRAY_SIZE(fake_samples[1]) - 1) {
243f8ebb0cdSNamhyung Kim 			pr_debug("Invalid count of dummy entries: %zd of %zd\n",
244f8ebb0cdSNamhyung Kim 				 count_dummy, ARRAY_SIZE(fake_samples[1]) - 1);
245f8ebb0cdSNamhyung Kim 			return -1;
246f8ebb0cdSNamhyung Kim 		}
247f8ebb0cdSNamhyung Kim 		if (count != count_pair + ARRAY_SIZE(fake_samples[0])) {
248f8ebb0cdSNamhyung Kim 			pr_debug("Invalid count of total leader entries: %zd of %zd\n",
249f8ebb0cdSNamhyung Kim 				 count, count_pair + ARRAY_SIZE(fake_samples[0]));
250f8ebb0cdSNamhyung Kim 			return -1;
251f8ebb0cdSNamhyung Kim 		}
252f8ebb0cdSNamhyung Kim 	} else {
253f8ebb0cdSNamhyung Kim 		if (count != count_pair) {
254f8ebb0cdSNamhyung Kim 			pr_debug("Invalid count of total other entries: %zd of %zd\n",
255f8ebb0cdSNamhyung Kim 				 count, count_pair);
256f8ebb0cdSNamhyung Kim 			return -1;
257f8ebb0cdSNamhyung Kim 		}
258f8ebb0cdSNamhyung Kim 		if (count_dummy > 0) {
259f8ebb0cdSNamhyung Kim 			pr_debug("Other hists should not have dummy entries: %zd\n",
260f8ebb0cdSNamhyung Kim 				 count_dummy);
261f8ebb0cdSNamhyung Kim 			return -1;
262f8ebb0cdSNamhyung Kim 		}
263f8ebb0cdSNamhyung Kim 	}
264f8ebb0cdSNamhyung Kim 
265f8ebb0cdSNamhyung Kim 	return 0;
266f8ebb0cdSNamhyung Kim }
267f8ebb0cdSNamhyung Kim 
268f8ebb0cdSNamhyung Kim static int validate_link(struct hists *leader, struct hists *other)
269f8ebb0cdSNamhyung Kim {
270f8ebb0cdSNamhyung Kim 	return __validate_link(leader, 0) || __validate_link(other, 1);
271f8ebb0cdSNamhyung Kim }
272f8ebb0cdSNamhyung Kim 
273f8ebb0cdSNamhyung Kim int test__hists_link(void)
274f8ebb0cdSNamhyung Kim {
275f8ebb0cdSNamhyung Kim 	int err = -1;
276*4ea062edSArnaldo Carvalho de Melo 	struct hists *hists, *first_hists;
277876650e6SArnaldo Carvalho de Melo 	struct machines machines;
278f8ebb0cdSNamhyung Kim 	struct machine *machine = NULL;
279f8ebb0cdSNamhyung Kim 	struct perf_evsel *evsel, *first;
280334fe7a3SNamhyung Kim 	struct perf_evlist *evlist = perf_evlist__new();
281f8ebb0cdSNamhyung Kim 
282f8ebb0cdSNamhyung Kim 	if (evlist == NULL)
283f8ebb0cdSNamhyung Kim                 return -ENOMEM;
284f8ebb0cdSNamhyung Kim 
285d8f7bbc9SJiri Olsa 	err = parse_events(evlist, "cpu-clock");
286f8ebb0cdSNamhyung Kim 	if (err)
287f8ebb0cdSNamhyung Kim 		goto out;
288d8f7bbc9SJiri Olsa 	err = parse_events(evlist, "task-clock");
289f8ebb0cdSNamhyung Kim 	if (err)
290f8ebb0cdSNamhyung Kim 		goto out;
291f8ebb0cdSNamhyung Kim 
292f8ebb0cdSNamhyung Kim 	/* default sort order (comm,dso,sym) will be used */
29355309985SNamhyung Kim 	if (setup_sorting() < 0)
29455309985SNamhyung Kim 		goto out;
295f8ebb0cdSNamhyung Kim 
296876650e6SArnaldo Carvalho de Melo 	machines__init(&machines);
297876650e6SArnaldo Carvalho de Melo 
298f8ebb0cdSNamhyung Kim 	/* setup threads/dso/map/symbols also */
299876650e6SArnaldo Carvalho de Melo 	machine = setup_fake_machine(&machines);
300f8ebb0cdSNamhyung Kim 	if (!machine)
301f8ebb0cdSNamhyung Kim 		goto out;
302f8ebb0cdSNamhyung Kim 
303f8ebb0cdSNamhyung Kim 	if (verbose > 1)
304f8ebb0cdSNamhyung Kim 		machine__fprintf(machine, stderr);
305f8ebb0cdSNamhyung Kim 
306f8ebb0cdSNamhyung Kim 	/* process sample events */
307f8ebb0cdSNamhyung Kim 	err = add_hist_entries(evlist, machine);
308f8ebb0cdSNamhyung Kim 	if (err < 0)
309f8ebb0cdSNamhyung Kim 		goto out;
310f8ebb0cdSNamhyung Kim 
3110050f7aaSArnaldo Carvalho de Melo 	evlist__for_each(evlist, evsel) {
312*4ea062edSArnaldo Carvalho de Melo 		hists = evsel__hists(evsel);
313*4ea062edSArnaldo Carvalho de Melo 		hists__collapse_resort(hists, NULL);
314f8ebb0cdSNamhyung Kim 
315f8ebb0cdSNamhyung Kim 		if (verbose > 2)
316*4ea062edSArnaldo Carvalho de Melo 			print_hists_in(hists);
317f8ebb0cdSNamhyung Kim 	}
318f8ebb0cdSNamhyung Kim 
319f8ebb0cdSNamhyung Kim 	first = perf_evlist__first(evlist);
320f8ebb0cdSNamhyung Kim 	evsel = perf_evlist__last(evlist);
321f8ebb0cdSNamhyung Kim 
322*4ea062edSArnaldo Carvalho de Melo 	first_hists = evsel__hists(first);
323*4ea062edSArnaldo Carvalho de Melo 	hists = evsel__hists(evsel);
324*4ea062edSArnaldo Carvalho de Melo 
325f8ebb0cdSNamhyung Kim 	/* match common entries */
326*4ea062edSArnaldo Carvalho de Melo 	hists__match(first_hists, hists);
327*4ea062edSArnaldo Carvalho de Melo 	err = validate_match(first_hists, hists);
328f8ebb0cdSNamhyung Kim 	if (err)
329f8ebb0cdSNamhyung Kim 		goto out;
330f8ebb0cdSNamhyung Kim 
331f8ebb0cdSNamhyung Kim 	/* link common and/or dummy entries */
332*4ea062edSArnaldo Carvalho de Melo 	hists__link(first_hists, hists);
333*4ea062edSArnaldo Carvalho de Melo 	err = validate_link(first_hists, hists);
334f8ebb0cdSNamhyung Kim 	if (err)
335f8ebb0cdSNamhyung Kim 		goto out;
336f8ebb0cdSNamhyung Kim 
337f8ebb0cdSNamhyung Kim 	err = 0;
338f8ebb0cdSNamhyung Kim 
339f8ebb0cdSNamhyung Kim out:
340f8ebb0cdSNamhyung Kim 	/* tear down everything */
341f8ebb0cdSNamhyung Kim 	perf_evlist__delete(evlist);
342f21d1815SNamhyung Kim 	reset_output_field();
343876650e6SArnaldo Carvalho de Melo 	machines__exit(&machines);
344f8ebb0cdSNamhyung Kim 
345f8ebb0cdSNamhyung Kim 	return err;
346f8ebb0cdSNamhyung Kim }
347