]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/perf/util/counts.c
Merge tag 'xfs-4.13-fixes-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[mirror_ubuntu-bionic-kernel.git] / tools / perf / util / counts.c
CommitLineData
a43783ae 1#include <errno.h>
d809560b
JO
2#include <stdlib.h>
3#include "evsel.h"
4#include "counts.h"
9a3993d4 5#include "util.h"
d809560b
JO
6
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}