perf stat: Allocate aggr counts for recorded data

In the process_stat_config_event() it sets the aggr_mode that means the
earlier evlist__alloc_stats() cannot allocate the aggr counts due to the
missing aggr_mode.

Do it after setting the aggr_map using evlist__alloc_aggr_stats().

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ian 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-13-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Namhyung Kim
2022-10-17 19:02:19 -07:00
committed by Arnaldo Carvalho de Melo
parent 050059e1b1
commit ae7e6492ee
3 changed files with 48 additions and 13 deletions

View File

@@ -141,6 +141,31 @@ static void evsel__reset_stat_priv(struct evsel *evsel)
memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr);
}
static int evsel__alloc_aggr_stats(struct evsel *evsel, int nr_aggr)
{
struct perf_stat_evsel *ps = evsel->stats;
if (ps == NULL)
return 0;
ps->nr_aggr = nr_aggr;
ps->aggr = calloc(nr_aggr, sizeof(*ps->aggr));
if (ps->aggr == NULL)
return -ENOMEM;
return 0;
}
int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr)
{
struct evsel *evsel;
evlist__for_each_entry(evlist, evsel) {
if (evsel__alloc_aggr_stats(evsel, nr_aggr) < 0)
return -1;
}
return 0;
}
static int evsel__alloc_stat_priv(struct evsel *evsel, int nr_aggr)
{
@@ -150,16 +175,14 @@ static int evsel__alloc_stat_priv(struct evsel *evsel, int nr_aggr)
if (ps == NULL)
return -ENOMEM;
if (nr_aggr) {
ps->nr_aggr = nr_aggr;
ps->aggr = calloc(nr_aggr, sizeof(*ps->aggr));
if (ps->aggr == NULL) {
free(ps);
return -ENOMEM;
}
evsel->stats = ps;
if (nr_aggr && evsel__alloc_aggr_stats(evsel, nr_aggr) < 0) {
evsel->stats = NULL;
free(ps);
return -ENOMEM;
}
evsel->stats = ps;
perf_stat_evsel_id_init(evsel);
evsel__reset_stat_priv(evsel);
return 0;