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