perf stat: Use xyarray for cpu evsel counts
authorJiri Olsa <jolsa@kernel.org>
Fri, 26 Jun 2015 09:29:10 +0000 (11:29 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 26 Jun 2015 14:19:19 +0000 (11:19 -0300)
Switching single dimensional array of 'struct perf_counts_values'
with xyarray object, so we could store thread dimension counts.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1435310967-14570-6-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-stat.c
tools/perf/tests/openat-syscall.c
tools/perf/util/stat.c
tools/perf/util/stat.h

index 49b90374232cbd34143c7726f830293caefe1da9..055ce83dd6f27e2464ed5fea9d37d7657b1d75aa 100644 (file)
@@ -218,7 +218,7 @@ static void perf_stat__reset_stats(struct perf_evlist *evlist)
 
        evlist__for_each(evlist, evsel) {
                perf_evsel__reset_stat_priv(evsel);
-               perf_evsel__reset_counts(evsel, perf_evsel__nr_cpus(evsel));
+               perf_evsel__reset_counts(evsel);
        }
 
        perf_stat__reset_shadow_stats();
index e86fc477a74f9c23cca62e9d2f341dfb4c3ee278..bd882f09ebbcda66c382dc3762a3c25140d985db 100644 (file)
@@ -46,7 +46,7 @@ int test__openat_syscall_event(void)
 
        if (perf_counts(evsel->counts, 0)->val != nr_openat_calls) {
                pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n",
-                        nr_openat_calls, evsel->counts->cpu[0].val);
+                        nr_openat_calls, perf_counts(evsel->counts, 0)->val);
                goto out_close_fd;
        }
 
index 4014b709f956b96b86dab3526f3b35fec6d8c166..453480aa7650252b038203e47f603394233beaa4 100644 (file)
@@ -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)
index 5e43348836a608fee066ae2d4a384955c2ccbdaa..6d07612545e001767036a0d75804b61a3dcbcc32 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <linux/types.h>
 #include <stdio.h>
+#include "xyarray.h"
 
 struct stats
 {
@@ -45,13 +46,13 @@ struct perf_counts_values {
 struct perf_counts {
        s8                        scaled;
        struct perf_counts_values aggr;
-       struct perf_counts_values cpu[];
+       struct xyarray            *cpu;
 };
 
 static inline struct perf_counts_values*
 perf_counts(struct perf_counts *counts, int cpu)
 {
-       return &counts->cpu[cpu];
+       return xyarray__entry(counts->cpu, cpu, 0);
 }
 
 void update_stats(struct stats *stats, u64 val);
@@ -88,7 +89,7 @@ void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel,
 struct perf_counts *perf_counts__new(int ncpus);
 void perf_counts__delete(struct perf_counts *counts);
 
-void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus);
+void perf_evsel__reset_counts(struct perf_evsel *evsel);
 int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
 void perf_evsel__free_counts(struct perf_evsel *evsel);
 #endif