[PATCH 12/19] perf stat: Reset aggr counts for each interval

From: Namhyung Kim
Date: Mon Oct 10 2022 - 01:37:10 EST


The evsel->stats->aggr->count should be reset for interval processing
since we want to use the values directly for display.

Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-stat.c | 3 +++
tools/perf/util/stat.c | 13 +++++++++++++
tools/perf/util/stat.h | 1 +
3 files changed, 17 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 983f38cd4caa..38036f40e993 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -492,6 +492,8 @@ static void process_interval(void)
diff_timespec(&rs, &ts, &ref_time);

perf_stat__reset_shadow_per_stat(&rt_stat);
+ evlist__reset_aggr_stats(evsel_list);
+
read_counters(&rs);

if (STAT_RECORD) {
@@ -965,6 +967,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)

evlist__copy_prev_raw_counts(evsel_list);
evlist__reset_prev_raw_counts(evsel_list);
+ evlist__reset_aggr_stats(evsel_list);
perf_stat__reset_shadow_per_stat(&rt_stat);
} else {
update_stats(&walltime_nsecs_stats, t1 - t0);
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 279aa4ea342d..4edfc1c5dc07 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -276,6 +276,19 @@ void evlist__reset_stats(struct evlist *evlist)
}
}

+void evlist__reset_aggr_stats(struct evlist *evlist)
+{
+ struct evsel *evsel;
+
+ evlist__for_each_entry(evlist, evsel) {
+ struct perf_stat_evsel *ps = evsel->stats;
+ struct perf_stat_aggr *aggr = ps->aggr;
+
+ if (aggr)
+ memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr);
+ }
+}
+
void evlist__reset_prev_raw_counts(struct evlist *evlist)
{
struct evsel *evsel;
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index 936c0709ce0d..3a876ad2870b 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -266,6 +266,7 @@ void evlist__copy_prev_raw_counts(struct evlist *evlist);
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);

int perf_stat_process_counter(struct perf_stat_config *config,
struct evsel *counter);
--
2.38.0.rc1.362.ged0d419d3c-goog