perf metrics: Don't scale counts going into metrics
authorIan Rogers <irogers@google.com>
Tue, 4 Oct 2022 02:15:53 +0000 (19:15 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 6 Oct 2022 11:03:52 +0000 (08:03 -0300)
Counts are scaled prior to going into saved_value, reverse the scaling
so that metrics don't double scale values.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Ahmad Yasin <ahmad.yasin@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kshipra Bopardikar <kshipra.bopardikar@intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Miaoqian Lin <linmq006@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Samantha Alt <samantha.alt@intel.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221004021612.325521-5-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/stat-shadow.c

index 9e1edde..b5cedd3 100644 (file)
@@ -865,11 +865,16 @@ static int prepare_metric(struct evsel **metric_events,
                        if (!v)
                                break;
                        stats = &v->stats;
-                       scale = 1.0;
+                       /*
+                        * If an event was scaled during stat gathering, reverse
+                        * the scale before computing the metric.
+                        */
+                       scale = 1.0 / metric_events[i]->scale;
+
                        source_count = evsel__source_count(metric_events[i]);
 
                        if (v->metric_other)
-                               metric_total = v->metric_total;
+                               metric_total = v->metric_total * scale;
                }
                n = strdup(evsel__metric_id(metric_events[i]));
                if (!n)