Loading...
1// SPDX-License-Identifier: GPL-2.0
2#include <errno.h>
3#include <stdlib.h>
4#include "evsel.h"
5#include "counts.h"
6#include <linux/zalloc.h>
7
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 values = xyarray__new(ncpus, nthreads, sizeof(bool));
24 if (!values) {
25 xyarray__delete(counts->values);
26 free(counts);
27 return NULL;
28 }
29
30 counts->loaded = values;
31 }
32
33 return counts;
34}
35
36void perf_counts__delete(struct perf_counts *counts)
37{
38 if (counts) {
39 xyarray__delete(counts->loaded);
40 xyarray__delete(counts->values);
41 free(counts);
42 }
43}
44
45static void perf_counts__reset(struct perf_counts *counts)
46{
47 xyarray__reset(counts->loaded);
48 xyarray__reset(counts->values);
49}
50
51void perf_evsel__reset_counts(struct evsel *evsel)
52{
53 perf_counts__reset(evsel->counts);
54}
55
56int perf_evsel__alloc_counts(struct evsel *evsel, int ncpus, int nthreads)
57{
58 evsel->counts = perf_counts__new(ncpus, nthreads);
59 return evsel->counts != NULL ? 0 : -ENOMEM;
60}
61
62void perf_evsel__free_counts(struct evsel *evsel)
63{
64 perf_counts__delete(evsel->counts);
65 evsel->counts = NULL;
66}
1// SPDX-License-Identifier: GPL-2.0
2#include <errno.h>
3#include <stdlib.h>
4#include <string.h>
5#include "evsel.h"
6#include "counts.h"
7#include <linux/zalloc.h>
8
9struct perf_counts *perf_counts__new(int ncpus, int nthreads)
10{
11 struct perf_counts *counts = zalloc(sizeof(*counts));
12
13 if (counts) {
14 struct xyarray *values;
15
16 values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values));
17 if (!values) {
18 free(counts);
19 return NULL;
20 }
21
22 counts->values = values;
23
24 values = xyarray__new(ncpus, nthreads, sizeof(bool));
25 if (!values) {
26 xyarray__delete(counts->values);
27 free(counts);
28 return NULL;
29 }
30
31 counts->loaded = values;
32 }
33
34 return counts;
35}
36
37void perf_counts__delete(struct perf_counts *counts)
38{
39 if (counts) {
40 xyarray__delete(counts->loaded);
41 xyarray__delete(counts->values);
42 free(counts);
43 }
44}
45
46void perf_counts__reset(struct perf_counts *counts)
47{
48 xyarray__reset(counts->loaded);
49 xyarray__reset(counts->values);
50 memset(&counts->aggr, 0, sizeof(struct perf_counts_values));
51}
52
53void evsel__reset_counts(struct evsel *evsel)
54{
55 perf_counts__reset(evsel->counts);
56}
57
58int evsel__alloc_counts(struct evsel *evsel, int ncpus, int nthreads)
59{
60 evsel->counts = perf_counts__new(ncpus, nthreads);
61 return evsel->counts != NULL ? 0 : -ENOMEM;
62}
63
64void evsel__free_counts(struct evsel *evsel)
65{
66 perf_counts__delete(evsel->counts);
67 evsel->counts = NULL;
68}