1 // SPDX-License-Identifier: GPL-2.0 << 2 #include <errno.h> 1 #include <errno.h> 3 #include <stdlib.h> 2 #include <stdlib.h> 4 #include <string.h> << 5 #include "evsel.h" 3 #include "evsel.h" 6 #include "counts.h" 4 #include "counts.h" 7 #include <perf/threadmap.h> !! 5 #include "util.h" 8 #include <linux/zalloc.h> << 9 6 10 struct perf_counts *perf_counts__new(int ncpus 7 struct perf_counts *perf_counts__new(int ncpus, int nthreads) 11 { 8 { 12 struct perf_counts *counts = zalloc(si 9 struct perf_counts *counts = zalloc(sizeof(*counts)); 13 10 14 if (counts) { 11 if (counts) { 15 struct xyarray *values; 12 struct xyarray *values; 16 13 17 values = xyarray__new(ncpus, n 14 values = xyarray__new(ncpus, nthreads, sizeof(struct perf_counts_values)); 18 if (!values) { 15 if (!values) { 19 free(counts); 16 free(counts); 20 return NULL; 17 return NULL; 21 } 18 } 22 19 23 counts->values = values; 20 counts->values = values; 24 << 25 values = xyarray__new(ncpus, n << 26 if (!values) { << 27 xyarray__delete(counts << 28 free(counts); << 29 return NULL; << 30 } << 31 << 32 counts->loaded = values; << 33 } 21 } 34 22 35 return counts; 23 return counts; 36 } 24 } 37 25 38 void perf_counts__delete(struct perf_counts *c 26 void perf_counts__delete(struct perf_counts *counts) 39 { 27 { 40 if (counts) { 28 if (counts) { 41 xyarray__delete(counts->loaded << 42 xyarray__delete(counts->values 29 xyarray__delete(counts->values); 43 free(counts); 30 free(counts); 44 } 31 } 45 } 32 } 46 33 47 void perf_counts__reset(struct perf_counts *co !! 34 static void perf_counts__reset(struct perf_counts *counts) 48 { 35 { 49 xyarray__reset(counts->loaded); << 50 xyarray__reset(counts->values); 36 xyarray__reset(counts->values); 51 } 37 } 52 38 53 void evsel__reset_counts(struct evsel *evsel) !! 39 void perf_evsel__reset_counts(struct perf_evsel *evsel) 54 { 40 { 55 perf_counts__reset(evsel->counts); 41 perf_counts__reset(evsel->counts); 56 } 42 } 57 43 58 int evsel__alloc_counts(struct evsel *evsel) !! 44 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus, int nthreads) 59 { 45 { 60 struct perf_cpu_map *cpus = evsel__cpu !! 46 evsel->counts = perf_counts__new(ncpus, nthreads); 61 int nthreads = perf_thread_map__nr(evs << 62 << 63 evsel->counts = perf_counts__new(perf_ << 64 return evsel->counts != NULL ? 0 : -EN 47 return evsel->counts != NULL ? 0 : -ENOMEM; 65 } 48 } 66 49 67 void evsel__free_counts(struct evsel *evsel) !! 50 void perf_evsel__free_counts(struct perf_evsel *evsel) 68 { 51 { 69 perf_counts__delete(evsel->counts); 52 perf_counts__delete(evsel->counts); 70 evsel->counts = NULL; 53 evsel->counts = NULL; 71 } 54 } 72 55
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.