perf stat: Introduce perf_counts function
authorJiri Olsa <jolsa@kernel.org>
Fri, 26 Jun 2015 09:29:09 +0000 (11:29 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 26 Jun 2015 14:11:26 +0000 (11:11 -0300)
Introducing perf_counts function, that returns
'struct perf_counts_values' pointer for given cpu.

Also moving perf_counts* structures into stat.h.

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-5-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-all-cpus.c
tools/perf/tests/openat-syscall.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/stat.h

index 3e1636cae76b96d4ecac5bc9b7fc1367af171854..49b90374232cbd34143c7726f830293caefe1da9 100644 (file)
@@ -316,7 +316,7 @@ static int read_cb(struct perf_evsel *evsel, int cpu, int thread __maybe_unused,
                if (!evsel->snapshot)
                        perf_evsel__compute_deltas(evsel, cpu, count);
                perf_counts_values__scale(count, scale, NULL);
-               evsel->counts->cpu[cpu] = *count;
+               *perf_counts(evsel->counts, cpu) = *count;
                if (aggr_mode == AGGR_NONE)
                        perf_stat__update_shadow_stats(evsel, count->values, cpu);
                break;
@@ -805,9 +805,9 @@ static void print_aggr(char *prefix)
                                s2 = aggr_get_id(evsel_list->cpus, cpu2);
                                if (s2 != id)
                                        continue;
-                               val += counter->counts->cpu[cpu].val;
-                               ena += counter->counts->cpu[cpu].ena;
-                               run += counter->counts->cpu[cpu].run;
+                               val += perf_counts(counter->counts, cpu)->val;
+                               ena += perf_counts(counter->counts, cpu)->ena;
+                               run += perf_counts(counter->counts, cpu)->run;
                                nr++;
                        }
                        if (prefix)
@@ -915,9 +915,9 @@ static void print_counter(struct perf_evsel *counter, char *prefix)
        int cpu;
 
        for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
-               val = counter->counts->cpu[cpu].val;
-               ena = counter->counts->cpu[cpu].ena;
-               run = counter->counts->cpu[cpu].run;
+               val = perf_counts(counter->counts, cpu)->val;
+               ena = perf_counts(counter->counts, cpu)->ena;
+               run = perf_counts(counter->counts, cpu)->run;
 
                if (prefix)
                        fprintf(output, "%s", prefix);
index b8d552b13950e98f2e1112dfa122303e1e7d3085..e8d944fe1bd08790f605d0023baa47583f4eab0e 100644 (file)
@@ -98,9 +98,9 @@ int test__openat_syscall_event_on_all_cpus(void)
                }
 
                expected = nr_openat_calls + cpu;
-               if (evsel->counts->cpu[cpu].val != expected) {
+               if (perf_counts(evsel->counts, cpu)->val != expected) {
                        pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64 "\n",
-                                expected, cpus->map[cpu], evsel->counts->cpu[cpu].val);
+                                expected, cpus->map[cpu], perf_counts(evsel->counts, cpu)->val);
                        err = -1;
                }
        }
index bdfa1f446681eaffd6cb77da607da1dfbe839466..e86fc477a74f9c23cca62e9d2f341dfb4c3ee278 100644 (file)
@@ -44,7 +44,7 @@ int test__openat_syscall_event(void)
                goto out_close_fd;
        }
 
-       if (evsel->counts->cpu[0].val != nr_openat_calls) {
+       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);
                goto out_close_fd;
index 1b2f480a3e821a397c225c3ca91943b9b787520f..8401b042b9d463275e01cd92a43f404bbba263a5 100644 (file)
@@ -910,8 +910,8 @@ void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
                tmp = evsel->prev_raw_counts->aggr;
                evsel->prev_raw_counts->aggr = *count;
        } else {
-               tmp = evsel->prev_raw_counts->cpu[cpu];
-               evsel->prev_raw_counts->cpu[cpu] = *count;
+               tmp = *perf_counts(evsel->prev_raw_counts, cpu);
+               *perf_counts(evsel->prev_raw_counts, cpu) = *count;
        }
 
        count->val = count->val - tmp.val;
@@ -972,7 +972,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
 
        perf_evsel__compute_deltas(evsel, cpu, &count);
        perf_counts_values__scale(&count, scale, NULL);
-       evsel->counts->cpu[cpu] = count;
+       *perf_counts(evsel->counts, cpu) = count;
        return 0;
 }
 
index 4dbf32d94dfb4edda649d57603e647dcb941b9df..b420f8f5fc5d930dd843130324ba9f0dc3c15b23 100644 (file)
@@ -9,23 +9,7 @@
 #include "xyarray.h"
 #include "symbol.h"
 #include "cpumap.h"
-
-struct perf_counts_values {
-       union {
-               struct {
-                       u64 val;
-                       u64 ena;
-                       u64 run;
-               };
-               u64 values[3];
-       };
-};
-
-struct perf_counts {
-       s8                        scaled;
-       struct perf_counts_values aggr;
-       struct perf_counts_values cpu[];
-};
+#include "stat.h"
 
 struct perf_evsel;
 
index 093dc3cb28dd3f62cb593095dfdc9c59317e0446..5e43348836a608fee066ae2d4a384955c2ccbdaa 100644 (file)
@@ -31,6 +31,29 @@ enum aggr_mode {
        AGGR_CORE,
 };
 
+struct perf_counts_values {
+       union {
+               struct {
+                       u64 val;
+                       u64 ena;
+                       u64 run;
+               };
+               u64 values[3];
+       };
+};
+
+struct perf_counts {
+       s8                        scaled;
+       struct perf_counts_values aggr;
+       struct perf_counts_values cpu[];
+};
+
+static inline struct perf_counts_values*
+perf_counts(struct perf_counts *counts, int cpu)
+{
+       return &counts->cpu[cpu];
+}
+
 void update_stats(struct stats *stats, u64 val);
 double avg_stats(struct stats *stats);
 double stddev_stats(struct stats *stats);
This page took 0.031049 seconds and 5 git commands to generate.