blob: 03032b410c291a1404c9fa6228f2320cdd68c1b7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Arnaldo Carvalho de Meloa43783a2017-04-18 10:46:11 -03002#include <errno.h>
Jiri Olsad8095602015-08-07 12:51:03 +02003#include <stdlib.h>
4#include "evsel.h"
5#include "counts.h"
Arnaldo Carvalho de Melo9a3993d2017-04-18 11:33:48 -03006#include "util.h"
Jiri Olsad8095602015-08-07 12:51:03 +02007
8struct perf_counts *perf_counts__new(int ncpus, int nthreads)
9{
10 struct perf_counts *counts = zalloc(sizeof(*counts));
11
12 if (counts) {
13 struct xyarray *values;
14
15 values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values));
16 if (!values) {
17 free(counts);
18 return NULL;
19 }
20
21 counts->values = values;
22 }
23
24 return counts;
25}
26
27void perf_counts__delete(struct perf_counts *counts)
28{
29 if (counts) {
30 xyarray__delete(counts->values);
31 free(counts);
32 }
33}
34
35static void perf_counts__reset(struct perf_counts *counts)
36{
37 xyarray__reset(counts->values);
38}
39
40void perf_evsel__reset_counts(struct perf_evsel *evsel)
41{
42 perf_counts__reset(evsel->counts);
43}
44
45int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads)
46{
47 evsel->counts = perf_counts__new(ncpus, nthreads);
48 return evsel->counts != NULL ? 0 : -ENOMEM;
49}
50
51void perf_evsel__free_counts(struct perf_evsel *evsel)
52{
53 perf_counts__delete(evsel->counts);
54 evsel->counts = NULL;
55}