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