Re: [PATCH 12/19] perf stat: Reset aggr counts for each interval
From: Namhyung Kim
Date: Tue Oct 11 2022 - 19:49:05 EST
On Mon, Oct 10, 2022 at 4:20 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
>
> On Sun, Oct 9, 2022 at 10:36 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> >
> > 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);
>
> Perhaps this would be cleaner with helper functions on perf_stat_evsel
> and perf_stat_aggr?
Sounds good. Will add.
Thanks,
Namhyung