Linux Perf
counts.c
Go to the documentation of this file.
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 "util.h"
7 
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 
27 void perf_counts__delete(struct perf_counts *counts)
28 {
29  if (counts) {
30  xyarray__delete(counts->values);
31  free(counts);
32  }
33 }
34 
35 static void perf_counts__reset(struct perf_counts *counts)
36 {
37  xyarray__reset(counts->values);
38 }
39 
41 {
42  perf_counts__reset(evsel->counts);
43 }
44 
45 int 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 
52 {
54  evsel->counts = NULL;
55 }
void xyarray__delete(struct xyarray *xy)
Definition: xyarray.c:30
Definition: xyarray.h:7
struct xyarray * xyarray__new(int xlen, int ylen, size_t entry_size)
Definition: xyarray.c:7
void perf_evsel__reset_counts(struct perf_evsel *evsel)
Definition: counts.c:40
static unsigned int nthreads
Definition: futex-hash.c:31
struct xyarray * values
Definition: counts.h:22
static void perf_counts__reset(struct perf_counts *counts)
Definition: counts.c:35
struct perf_counts * counts
Definition: evsel.h:98
void perf_evsel__free_counts(struct perf_evsel *evsel)
Definition: counts.c:51
void perf_counts__delete(struct perf_counts *counts)
Definition: counts.c:27
int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads)
Definition: counts.c:45
struct perf_counts * perf_counts__new(int ncpus, int nthreads)
Definition: counts.c:8
static unsigned int ncpus
Definition: futex-wake.c:45
void free(void *)
void static void * zalloc(size_t size)
Definition: util.h:20
void xyarray__reset(struct xyarray *xy)
Definition: xyarray.c:23