xref: /linux/tools/perf/util/sample.c (revision 4f9786035f9e519db41375818e1d0b5f20da2f10)
1*dc6d2bc2SIan Rogers /* SPDX-License-Identifier: GPL-2.0 */
2*dc6d2bc2SIan Rogers #include "sample.h"
3*dc6d2bc2SIan Rogers #include "debug.h"
4*dc6d2bc2SIan Rogers #include <linux/zalloc.h>
5*dc6d2bc2SIan Rogers #include <stdlib.h>
6*dc6d2bc2SIan Rogers #include <string.h>
7*dc6d2bc2SIan Rogers 
8*dc6d2bc2SIan Rogers void perf_sample__init(struct perf_sample *sample, bool all)
9*dc6d2bc2SIan Rogers {
10*dc6d2bc2SIan Rogers 	if (all) {
11*dc6d2bc2SIan Rogers 		memset(sample, 0, sizeof(*sample));
12*dc6d2bc2SIan Rogers 	} else {
13*dc6d2bc2SIan Rogers 		sample->user_regs = NULL;
14*dc6d2bc2SIan Rogers 		sample->intr_regs = NULL;
15*dc6d2bc2SIan Rogers 	}
16*dc6d2bc2SIan Rogers }
17*dc6d2bc2SIan Rogers 
18*dc6d2bc2SIan Rogers void perf_sample__exit(struct perf_sample *sample)
19*dc6d2bc2SIan Rogers {
20*dc6d2bc2SIan Rogers 	free(sample->user_regs);
21*dc6d2bc2SIan Rogers 	free(sample->intr_regs);
22*dc6d2bc2SIan Rogers }
23*dc6d2bc2SIan Rogers 
24*dc6d2bc2SIan Rogers struct regs_dump *perf_sample__user_regs(struct perf_sample *sample)
25*dc6d2bc2SIan Rogers {
26*dc6d2bc2SIan Rogers 	if (!sample->user_regs) {
27*dc6d2bc2SIan Rogers 		sample->user_regs = zalloc(sizeof(*sample->user_regs));
28*dc6d2bc2SIan Rogers 		if (!sample->user_regs)
29*dc6d2bc2SIan Rogers 			pr_err("Failure to allocate sample user_regs");
30*dc6d2bc2SIan Rogers 	}
31*dc6d2bc2SIan Rogers 	return sample->user_regs;
32*dc6d2bc2SIan Rogers }
33*dc6d2bc2SIan Rogers 
34*dc6d2bc2SIan Rogers 
35*dc6d2bc2SIan Rogers struct regs_dump *perf_sample__intr_regs(struct perf_sample *sample)
36*dc6d2bc2SIan Rogers {
37*dc6d2bc2SIan Rogers 	if (!sample->intr_regs) {
38*dc6d2bc2SIan Rogers 		sample->intr_regs = zalloc(sizeof(*sample->intr_regs));
39*dc6d2bc2SIan Rogers 		if (!sample->intr_regs)
40*dc6d2bc2SIan Rogers 			pr_err("Failure to allocate sample intr_regs");
41*dc6d2bc2SIan Rogers 	}
42*dc6d2bc2SIan Rogers 	return sample->intr_regs;
43*dc6d2bc2SIan Rogers }
44