Commit 050059e1 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf stat: Aggregate per-thread stats using evsel->stats->aggr

Per-thread aggregation doesn't use the CPU numbers but the logic should
be the same.  Initialize cpu_aggr_map separately for AGGR_THREAD and use
thread map idx to aggregate counter values.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarIan 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-12-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 049aba09
...@@ -1465,6 +1465,21 @@ static int perf_stat_init_aggr_mode(void) ...@@ -1465,6 +1465,21 @@ static int perf_stat_init_aggr_mode(void)
stat_config.aggr_get_id = aggr_mode__get_id(stat_config.aggr_mode); stat_config.aggr_get_id = aggr_mode__get_id(stat_config.aggr_mode);
} }
if (stat_config.aggr_mode == AGGR_THREAD) {
nr = perf_thread_map__nr(evsel_list->core.threads);
stat_config.aggr_map = cpu_aggr_map__empty_new(nr);
if (stat_config.aggr_map == NULL)
return -ENOMEM;
for (int s = 0; s < nr; s++) {
struct aggr_cpu_id id = aggr_cpu_id__empty();
id.thread_idx = s;
stat_config.aggr_map->map[s] = id;
}
return 0;
}
/* /*
* The evsel_list->cpus is the base we operate on, * The evsel_list->cpus is the base we operate on,
* taking the highest cpu number to be the size of * taking the highest cpu number to be the size of
...@@ -1674,6 +1689,22 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st) ...@@ -1674,6 +1689,22 @@ static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
aggr_cpu_id_get_t get_id = aggr_mode__get_aggr_file(stat_config.aggr_mode); aggr_cpu_id_get_t get_id = aggr_mode__get_aggr_file(stat_config.aggr_mode);
bool needs_sort = stat_config.aggr_mode != AGGR_NONE; bool needs_sort = stat_config.aggr_mode != AGGR_NONE;
if (stat_config.aggr_mode == AGGR_THREAD) {
int nr = perf_thread_map__nr(evsel_list->core.threads);
stat_config.aggr_map = cpu_aggr_map__empty_new(nr);
if (stat_config.aggr_map == NULL)
return -ENOMEM;
for (int s = 0; s < nr; s++) {
struct aggr_cpu_id id = aggr_cpu_id__empty();
id.thread_idx = s;
stat_config.aggr_map->map[s] = id;
}
return 0;
}
if (!get_id) if (!get_id)
return 0; return 0;
......
...@@ -422,6 +422,24 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, ...@@ -422,6 +422,24 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
evsel__compute_deltas(evsel, cpu_map_idx, thread, count); evsel__compute_deltas(evsel, cpu_map_idx, thread, count);
perf_counts_values__scale(count, config->scale, NULL); perf_counts_values__scale(count, config->scale, NULL);
if (config->aggr_mode == AGGR_THREAD) {
struct perf_counts_values *aggr_counts = &ps->aggr[thread].counts;
/*
* Skip value 0 when enabling --per-thread globally,
* otherwise too many 0 output.
*/
if (count->val == 0 && config->system_wide)
return 0;
ps->aggr[thread].nr++;
aggr_counts->val += count->val;
aggr_counts->ena += count->ena;
aggr_counts->run += count->run;
goto update;
}
if (ps->aggr) { if (ps->aggr) {
struct perf_cpu cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx); struct perf_cpu cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx);
struct aggr_cpu_id aggr_id = config->aggr_get_id(config, cpu); struct aggr_cpu_id aggr_id = config->aggr_get_id(config, cpu);
...@@ -436,8 +454,9 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, ...@@ -436,8 +454,9 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
ps_aggr->nr++; ps_aggr->nr++;
/* /*
* When any result is bad, make them all to give * When any result is bad, make them all to give consistent output
* consistent output in interval mode. * in interval mode. But per-task counters can have 0 enabled time
* when some tasks are idle.
*/ */
if (evsel__count_has_error(evsel, count, config) && !ps_aggr->failed) { if (evsel__count_has_error(evsel, count, config) && !ps_aggr->failed) {
ps_aggr->counts.val = 0; ps_aggr->counts.val = 0;
...@@ -455,6 +474,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel, ...@@ -455,6 +474,7 @@ process_counter_values(struct perf_stat_config *config, struct evsel *evsel,
} }
} }
update:
switch (config->aggr_mode) { switch (config->aggr_mode) {
case AGGR_THREAD: case AGGR_THREAD:
case AGGR_CORE: case AGGR_CORE:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment