perf evsel: Introduce perf_counts_values__scale function
authorJiri Olsa <jolsa@kernel.org>
Fri, 21 Nov 2014 09:31:06 +0000 (10:31 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 24 Nov 2014 21:03:50 +0000 (18:03 -0300)
Factoring out scale login into perf_counts_values__scale function.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Matt Fleming <matt.fleming@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1416562275-12404-3-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evsel.c
tools/perf/util/evsel.h

index 1c73bc4d57d370aa55e065fadfb1c0e744f68275..6dc7a67e6d359023c57338e8e105fd7dbff1d77f 100644 (file)
@@ -897,6 +897,26 @@ void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
        count->run = count->run - tmp.run;
 }
 
+void perf_counts_values__scale(struct perf_counts_values *count,
+                              bool scale, s8 *pscaled)
+{
+       s8 scaled = 0;
+
+       if (scale) {
+               if (count->run == 0) {
+                       scaled = -1;
+                       count->val = 0;
+               } else if (count->run < count->ena) {
+                       scaled = 1;
+                       count->val = (u64)((double) count->val * count->ena / count->run + 0.5);
+               }
+       } else
+               count->ena = count->run = 0;
+
+       if (pscaled)
+               *pscaled = scaled;
+}
+
 int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
                              int cpu, int thread, bool scale)
 {
@@ -913,15 +933,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
                return -errno;
 
        perf_evsel__compute_deltas(evsel, cpu, &count);
-
-       if (scale) {
-               if (count.run == 0)
-                       count.val = 0;
-               else if (count.run < count.ena)
-                       count.val = (u64)((double)count.val * count.ena / count.run + 0.5);
-       } else
-               count.ena = count.run = 0;
-
+       perf_counts_values__scale(&count, scale, NULL);
        evsel->counts->cpu[cpu] = count;
        return 0;
 }
@@ -956,22 +968,7 @@ int __perf_evsel__read(struct perf_evsel *evsel,
        }
 
        perf_evsel__compute_deltas(evsel, -1, aggr);
-
-       evsel->counts->scaled = 0;
-       if (scale) {
-               if (aggr->run == 0) {
-                       evsel->counts->scaled = -1;
-                       aggr->val = 0;
-                       return 0;
-               }
-
-               if (aggr->run < aggr->ena) {
-                       evsel->counts->scaled = 1;
-                       aggr->val = (u64)((double)aggr->val * aggr->ena / aggr->run + 0.5);
-               }
-       } else
-               aggr->ena = aggr->run = 0;
-
+       perf_counts_values__scale(aggr, scale, &evsel->counts->scaled);
        return 0;
 }
 
index 746b7ea845891ccf22154b8971f863f0af814769..7af0377ceb18117a2cb0ff0f983c08b540196dd8 100644 (file)
@@ -110,6 +110,9 @@ struct thread_map;
 struct perf_evlist;
 struct record_opts;
 
+void perf_counts_values__scale(struct perf_counts_values *count,
+                              bool scale, s8 *pscaled);
+
 void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
                                struct perf_counts_values *count);