perf stat: Use thread map index for shadow stat
authorNamhyung Kim <namhyung@kernel.org>
Fri, 30 Sep 2022 20:21:07 +0000 (13:21 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 6 Oct 2022 11:03:53 +0000 (08:03 -0300)
When AGGR_THREAD is active, it aggregates the values for each thread.
Previously it used cpu map index which is invalid for AGGR_THREAD so
it had to use separate runtime stats with index 0.

But it can just use the rt_stat with thread_map_index.  Rename the
first_shadow_map_idx() and make it return the thread index.

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

index 234491f43c36b9c786e4929c85f98c863634012c..570e2c04d47d2d70a967bdca76be7af643f4eeb1 100644 (file)
@@ -442,7 +442,7 @@ static void print_metric_header(struct perf_stat_config *config,
                fprintf(os->fh, "%*s ", config->metric_only_len, unit);
 }
 
-static int first_shadow_cpu_map_idx(struct perf_stat_config *config,
+static int first_shadow_map_idx(struct perf_stat_config *config,
                                struct evsel *evsel, const struct aggr_cpu_id *id)
 {
        struct perf_cpu_map *cpus = evsel__cpus(evsel);
@@ -452,6 +452,9 @@ static int first_shadow_cpu_map_idx(struct perf_stat_config *config,
        if (config->aggr_mode == AGGR_NONE)
                return perf_cpu_map__idx(cpus, id->cpu);
 
+       if (config->aggr_mode == AGGR_THREAD)
+               return id->thread;
+
        if (!config->aggr_get_id)
                return 0;
 
@@ -646,7 +649,7 @@ static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int
        }
 
        perf_stat__print_shadow_stats(config, counter, uval,
-                               first_shadow_cpu_map_idx(config, counter, &id),
+                               first_shadow_map_idx(config, counter, &id),
                                &out, &config->metric_events, st);
        if (!config->csv_output && !config->metric_only && !config->json_output) {
                print_noise(config, counter, noise);
@@ -676,7 +679,7 @@ static void aggr_update_shadow(struct perf_stat_config *config,
                                val += perf_counts(counter->counts, idx, 0)->val;
                        }
                        perf_stat__update_shadow_stats(counter, val,
-                                       first_shadow_cpu_map_idx(config, counter, &id),
+                                       first_shadow_map_idx(config, counter, &id),
                                        &rt_stat);
                }
        }
@@ -979,14 +982,9 @@ static void print_aggr_thread(struct perf_stat_config *config,
                        fprintf(output, "%s", prefix);
 
                id = buf[thread].id;
-               if (config->stats)
-                       printout(config, id, 0, buf[thread].counter, buf[thread].uval,
-                                prefix, buf[thread].run, buf[thread].ena, 1.0,
-                                &config->stats[id.thread]);
-               else
-                       printout(config, id, 0, buf[thread].counter, buf[thread].uval,
-                                prefix, buf[thread].run, buf[thread].ena, 1.0,
-                                &rt_stat);
+               printout(config, id, 0, buf[thread].counter, buf[thread].uval,
+                        prefix, buf[thread].run, buf[thread].ena, 1.0,
+                        &rt_stat);
                fputc('\n', output);
        }
 
index 48634b95669e8b5b6fe3e2ccc52bf3e7caff208e..60c8709fb53c807cc914224b0f50ede8af0560d7 100644 (file)
@@ -33,7 +33,7 @@ struct saved_value {
        struct evsel *evsel;
        enum stat_type type;
        int ctx;
-       int map_idx;  /* cpu map index */
+       int map_idx;  /* cpu or thread map index */
        struct cgroup *cgrp;
        struct runtime_stat *stat;
        struct stats stats;
index 7e9543cff31cfb30cd8716fba54124b493c3f81c..8ec8bb4a99129b19176cae155e0ff9e5dd6e900d 100644 (file)
@@ -389,12 +389,8 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
                }
 
                if (config->aggr_mode == AGGR_THREAD) {
-                       if (config->stats)
-                               perf_stat__update_shadow_stats(evsel,
-                                       count->val, 0, &config->stats[thread]);
-                       else
-                               perf_stat__update_shadow_stats(evsel,
-                                       count->val, 0, &rt_stat);
+                       perf_stat__update_shadow_stats(evsel, count->val,
+                                                      thread, &rt_stat);
                }
                break;
        case AGGR_GLOBAL: