aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2014-11-21 04:31:06 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-11-24 16:03:50 -0500
commit13112bbf595d4081f291f7061bb096dbf4401d41 (patch)
treefe47db3282a875e1b359d358e243c8161f185d4a /tools/perf
parent857a94a226d7d345c3f492d5679e802e59f824a9 (diff)
perf evsel: Introduce perf_counts_values__scale function
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>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/evsel.c47
-rw-r--r--tools/perf/util/evsel.h3
2 files changed, 25 insertions, 25 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 1c73bc4d57d3..6dc7a67e6d35 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -897,6 +897,26 @@ void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
897 count->run = count->run - tmp.run; 897 count->run = count->run - tmp.run;
898} 898}
899 899
900void perf_counts_values__scale(struct perf_counts_values *count,
901 bool scale, s8 *pscaled)
902{
903 s8 scaled = 0;
904
905 if (scale) {
906 if (count->run == 0) {
907 scaled = -1;
908 count->val = 0;
909 } else if (count->run < count->ena) {
910 scaled = 1;
911 count->val = (u64)((double) count->val * count->ena / count->run + 0.5);
912 }
913 } else
914 count->ena = count->run = 0;
915
916 if (pscaled)
917 *pscaled = scaled;
918}
919
900int __perf_evsel__read_on_cpu(struct perf_evsel *evsel, 920int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
901 int cpu, int thread, bool scale) 921 int cpu, int thread, bool scale)
902{ 922{
@@ -913,15 +933,7 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
913 return -errno; 933 return -errno;
914 934
915 perf_evsel__compute_deltas(evsel, cpu, &count); 935 perf_evsel__compute_deltas(evsel, cpu, &count);
916 936 perf_counts_values__scale(&count, scale, NULL);
917 if (scale) {
918 if (count.run == 0)
919 count.val = 0;
920 else if (count.run < count.ena)
921 count.val = (u64)((double)count.val * count.ena / count.run + 0.5);
922 } else
923 count.ena = count.run = 0;
924
925 evsel->counts->cpu[cpu] = count; 937 evsel->counts->cpu[cpu] = count;
926 return 0; 938 return 0;
927} 939}
@@ -956,22 +968,7 @@ int __perf_evsel__read(struct perf_evsel *evsel,
956 } 968 }
957 969
958 perf_evsel__compute_deltas(evsel, -1, aggr); 970 perf_evsel__compute_deltas(evsel, -1, aggr);
959 971 perf_counts_values__scale(aggr, scale, &evsel->counts->scaled);
960 evsel->counts->scaled = 0;
961 if (scale) {
962 if (aggr->run == 0) {
963 evsel->counts->scaled = -1;
964 aggr->val = 0;
965 return 0;
966 }
967
968 if (aggr->run < aggr->ena) {
969 evsel->counts->scaled = 1;
970 aggr->val = (u64)((double)aggr->val * aggr->ena / aggr->run + 0.5);
971 }
972 } else
973 aggr->ena = aggr->run = 0;
974
975 return 0; 972 return 0;
976} 973}
977 974
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 746b7ea84589..7af0377ceb18 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -110,6 +110,9 @@ struct thread_map;
110struct perf_evlist; 110struct perf_evlist;
111struct record_opts; 111struct record_opts;
112 112
113void perf_counts_values__scale(struct perf_counts_values *count,
114 bool scale, s8 *pscaled);
115
113void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu, 116void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu,
114 struct perf_counts_values *count); 117 struct perf_counts_values *count);
115 118