Skip to content

Commit

Permalink
perf stat: Show average value on multiple runs
Browse files Browse the repository at this point in the history
When -r option is used, perf stat runs the command multiple times and
update stats in the evsel->stats.res_stats for global aggregation.  But
the value is never used and the value it prints at the end is just the
value from the last run.  I think we should print the average number of
multiple runs.

Add evlist__copy_res_stats() to update the aggr counter (for display)
using the values in the evsel->stats.res_stats.

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: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230616073211.1057936-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed Jun 16, 2023
1 parent ed4090a commit dada1a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2831,8 +2831,11 @@ int cmd_stat(int argc, const char **argv)
}
}

if (!forever && status != -1 && (!interval || stat_config.summary))
if (!forever && status != -1 && (!interval || stat_config.summary)) {
if (stat_config.run_count > 1)
evlist__copy_res_stats(&stat_config, evsel_list);
print_counters(NULL, argc, argv);
}

evlist__finalize_ctlfd(evsel_list);

Expand Down
22 changes: 22 additions & 0 deletions tools/perf/util/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,28 @@ void evlist__copy_prev_raw_counts(struct evlist *evlist)
evsel__copy_prev_raw_counts(evsel);
}

static void evsel__copy_res_stats(struct evsel *evsel)
{
struct perf_stat_evsel *ps = evsel->stats;

/*
* For GLOBAL aggregation mode, it updates the counts for each run
* in the evsel->stats.res_stats. See perf_stat_process_counter().
*/
*ps->aggr[0].counts.values = avg_stats(&ps->res_stats);
}

void evlist__copy_res_stats(struct perf_stat_config *config, struct evlist *evlist)
{
struct evsel *evsel;

if (config->aggr_mode != AGGR_GLOBAL)
return;

evlist__for_each_entry(evlist, evsel)
evsel__copy_res_stats(evsel);
}

static size_t pkg_id_hash(long __key, void *ctx __maybe_unused)
{
uint64_t *key = (uint64_t *) __key;
Expand Down
1 change: 1 addition & 0 deletions tools/perf/util/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ void evlist__save_aggr_prev_raw_counts(struct evlist *evlist);

int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr);
void evlist__reset_aggr_stats(struct evlist *evlist);
void evlist__copy_res_stats(struct perf_stat_config *config, struct evlist *evlist);

int perf_stat_process_counter(struct perf_stat_config *config,
struct evsel *counter);
Expand Down

0 comments on commit dada1a1

Please sign in to comment.