From a8e02324dfe6bcafc15d02b790f33321ec4facb0 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Fri, 26 Jun 2015 11:29:10 +0200 Subject: perf stat: Use xyarray for cpu evsel counts Switching single dimensional array of 'struct perf_counts_values' with xyarray object, so we could store thread dimension counts. Signed-off-by: Jiri Olsa Cc: Adrian Hunter Cc: Andi Kleen Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1435310967-14570-6-git-send-email-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/stat.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'tools/perf/util/stat.c') diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 4014b709f956..453480aa7650 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -97,26 +97,39 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel) struct perf_counts *perf_counts__new(int ncpus) { - int size = sizeof(struct perf_counts) + - ncpus * sizeof(struct perf_counts_values); + struct perf_counts *counts = zalloc(sizeof(*counts)); - return zalloc(size); + if (counts) { + struct xyarray *cpu; + + cpu = xyarray__new(ncpus, 1, sizeof(struct perf_counts_values)); + if (!cpu) { + free(counts); + return NULL; + } + + counts->cpu = cpu; + } + + return counts; } void perf_counts__delete(struct perf_counts *counts) { - free(counts); + if (counts) { + xyarray__delete(counts->cpu); + free(counts); + } } -static void perf_counts__reset(struct perf_counts *counts, int ncpus) +static void perf_counts__reset(struct perf_counts *counts) { - memset(counts, 0, (sizeof(*counts) + - (ncpus * sizeof(struct perf_counts_values)))); + xyarray__reset(counts->cpu); } -void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus) +void perf_evsel__reset_counts(struct perf_evsel *evsel) { - perf_counts__reset(evsel->counts, ncpus); + perf_counts__reset(evsel->counts); } int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus) -- cgit v1.2.3