1 // SPDX-License-Identifier: GPL-2.0
7 #include <perf/threadmap.h>
8 #include <linux/zalloc.h>
10 struct perf_counts
*perf_counts__new(int ncpus
, int nthreads
)
12 struct perf_counts
*counts
= zalloc(sizeof(*counts
));
15 struct xyarray
*values
;
17 values
= xyarray__new(ncpus
, nthreads
, sizeof(struct perf_counts_values
));
23 counts
->values
= values
;
25 values
= xyarray__new(ncpus
, nthreads
, sizeof(bool));
27 xyarray__delete(counts
->values
);
32 counts
->loaded
= values
;
38 void perf_counts__delete(struct perf_counts
*counts
)
41 xyarray__delete(counts
->loaded
);
42 xyarray__delete(counts
->values
);
47 void perf_counts__reset(struct perf_counts
*counts
)
49 xyarray__reset(counts
->loaded
);
50 xyarray__reset(counts
->values
);
53 void evsel__reset_counts(struct evsel
*evsel
)
55 perf_counts__reset(evsel
->counts
);
58 int evsel__alloc_counts(struct evsel
*evsel
)
60 struct perf_cpu_map
*cpus
= evsel__cpus(evsel
);
61 int nthreads
= perf_thread_map__nr(evsel
->core
.threads
);
63 evsel
->counts
= perf_counts__new(perf_cpu_map__nr(cpus
), nthreads
);
64 return evsel
->counts
!= NULL
? 0 : -ENOMEM
;
67 void evsel__free_counts(struct evsel
*evsel
)
69 perf_counts__delete(evsel
->counts
);