perf stat: Add perf_stat_process_shadow_stats()
authorNamhyung Kim <namhyung@kernel.org>
Tue, 18 Oct 2022 02:02:24 +0000 (19:02 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 27 Oct 2022 19:37:25 +0000 (16:37 -0300)
This function updates the shadow stats using the aggregated counts
uniformly since it uses the aggr_counts for the every aggr mode.

It'd have duplicate shadow stats for each items for now since the
display routines will update them once again.  But that'd be fine
as it shows the average values and it'd be gone eventually.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221018020227.85905-18-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-stat.c
tools/perf/util/stat.c
tools/perf/util/stat.h

index d6a006e41da09d11c9c52dfff9a716b89345b746..d7c52cef70a3a020b66e9a797dab098f5196485b 100644 (file)
@@ -489,6 +489,7 @@ static void process_counters(void)
 
        perf_stat_merge_counters(&stat_config, evsel_list);
        perf_stat_process_percore(&stat_config, evsel_list);
+       perf_stat_process_shadow_stats(&stat_config, evsel_list);
 }
 
 static void process_interval(void)
index 26c48ef7ca92098aaa28503c2939dd437e57f77f..c0955a0427ab3e2636629050c8c8a2522750fc6a 100644 (file)
@@ -474,7 +474,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
                aggr_counts->val += count->val;
                aggr_counts->ena += count->ena;
                aggr_counts->run += count->run;
-               goto update;
+               return 0;
        }
 
        if (ps->aggr) {
@@ -511,32 +511,10 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
                }
        }
 
-update:
-       switch (config->aggr_mode) {
-       case AGGR_THREAD:
-       case AGGR_CORE:
-       case AGGR_DIE:
-       case AGGR_SOCKET:
-       case AGGR_NODE:
-       case AGGR_NONE:
-               if ((config->aggr_mode == AGGR_NONE) && (!evsel->percore)) {
-                       perf_stat__update_shadow_stats(evsel, count->val,
-                                                      cpu_map_idx, &rt_stat);
-               }
-
-               if (config->aggr_mode == AGGR_THREAD) {
-                       perf_stat__update_shadow_stats(evsel, count->val,
-                                                      thread, &rt_stat);
-               }
-               break;
-       case AGGR_GLOBAL:
+       if (config->aggr_mode == AGGR_GLOBAL) {
                aggr->val += count->val;
                aggr->ena += count->ena;
                aggr->run += count->run;
-       case AGGR_UNSET:
-       case AGGR_MAX:
-       default:
-               break;
        }
 
        return 0;
@@ -762,6 +740,30 @@ void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *e
                evsel__process_percore(evsel);
 }
 
+static void evsel__update_shadow_stats(struct evsel *evsel)
+{
+       struct perf_stat_evsel *ps = evsel->stats;
+       int i;
+
+       if (ps->aggr == NULL)
+               return;
+
+       for (i = 0; i < ps->nr_aggr; i++) {
+               struct perf_counts_values *aggr_counts = &ps->aggr[i].counts;
+
+               perf_stat__update_shadow_stats(evsel, aggr_counts->val, i, &rt_stat);
+       }
+}
+
+void perf_stat_process_shadow_stats(struct perf_stat_config *config __maybe_unused,
+                                   struct evlist *evlist)
+{
+       struct evsel *evsel;
+
+       evlist__for_each_entry(evlist, evsel)
+               evsel__update_shadow_stats(evsel);
+}
+
 int perf_event__process_stat_event(struct perf_session *session,
                                   union perf_event *event)
 {
index d23f8743e44223c3fd788f0b41caa84a889069a9..3d413ba8c68a60271dd313c352b9414649759e83 100644 (file)
@@ -284,6 +284,7 @@ int perf_stat_process_counter(struct perf_stat_config *config,
                              struct evsel *counter);
 void perf_stat_merge_counters(struct perf_stat_config *config, struct evlist *evlist);
 void perf_stat_process_percore(struct perf_stat_config *config, struct evlist *evlist);
+void perf_stat_process_shadow_stats(struct perf_stat_config *config, struct evlist *evlist);
 
 struct perf_tool;
 union perf_event;