diff options
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/evsel.c | 47 | ||||
-rw-r--r-- | tools/perf/util/evsel.h | 3 |
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 | ||
900 | void 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 | |||
900 | int __perf_evsel__read_on_cpu(struct perf_evsel *evsel, | 920 | int __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; | |||
110 | struct perf_evlist; | 110 | struct perf_evlist; |
111 | struct record_opts; | 111 | struct record_opts; |
112 | 112 | ||
113 | void perf_counts_values__scale(struct perf_counts_values *count, | ||
114 | bool scale, s8 *pscaled); | ||
115 | |||
113 | void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu, | 116 | void perf_evsel__compute_deltas(struct perf_evsel *evsel, int cpu, |
114 | struct perf_counts_values *count); | 117 | struct perf_counts_values *count); |
115 | 118 | ||