From nobody Tue Apr 7 10:56:56 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0030C433FE for ; Fri, 14 Oct 2022 06:16:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229885AbiJNGQu (ORCPT ); Fri, 14 Oct 2022 02:16:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229852AbiJNGQW (ORCPT ); Fri, 14 Oct 2022 02:16:22 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21C1C17434; Thu, 13 Oct 2022 23:16:11 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id i3so3998913pfk.9; Thu, 13 Oct 2022 23:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=1bVysEQHf7eswq/CEhQ6wbCV3Rg3qd7TUjqKNRIeNeE=; b=GUH+jcz2YrnwSsaJtxMkbKTcBz74pdxJwwFX8CexctZBDJc5Hh9YB3avVH6EZd33Em w2cBjLSRGRLgwGDCAO5RbiSEsmKFEvw+VsRir4V3rm8yJ+x+6349eTltQJG7XyENc2Gu pCb5dQ9d1O7ZQq17D7t6oBIG50I0fYkf3Ne4ExVT6V3cYPRldrqr4n9npruaCGt3aSWa 8NFoZrCLppFPjVpcPZSxw2XO7OglEfZzYYS0GGupH5Lav15TtXBWO2aikd6koAidrxnr t5crTOcNK9xYWh+2TsisSaf8golRNtwWfmQPJhb5spvb809lb2RLHhb4f/PdJdf7Do9K WDhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1bVysEQHf7eswq/CEhQ6wbCV3Rg3qd7TUjqKNRIeNeE=; b=RN75FvixC6Qxwx3/ukaQ/qHk0HWXG7g4J/Ev+rzy37F6FV5GtuRSEg+LryCqjtWkJ2 LJ3e0JtSGSdlwIpukRzAhQU5voarbVNfgf4tsuwR/hD9UNf6SrZuffEFRYTG4Y6iUNmn S01MR1mDVEbTED+iQ4GYu6UDNV/yv9Jqp8ouBymc/xR9a+98pIIYsv/UF9joSaHPR1GH Se+6b6kN4o/BwhaV0tNEA43HXiWuExFJZbvY1m9wixOTt2a7RoBzlP1qr4/zBVjrDabV OBf/K4I8RSLHvWppPbZ+i/DIqHVrqXwvEbt03mIpz4I2Cn+RtG/U7BAXv+xlOXLfq6AO s3IA== X-Gm-Message-State: ACrzQf2cYR5oi6sQLzRtqBW1H0IUZihTHpCjprGNHIRJT5nltXBN8Cc8 sjZ1Q7Frp52kxLJ+uoEE4X8= X-Google-Smtp-Source: AMsMyM77gWM2jS2vuCpjUZLZg0pA7po+ChrNGOqwYD8nCKV5xCflPpDezpxC20iCytVeaaLd1S+MLw== X-Received: by 2002:a63:534e:0:b0:44e:12bf:2df8 with SMTP id t14-20020a63534e000000b0044e12bf2df8mr3205202pgl.143.1665728170544; Thu, 13 Oct 2022 23:16:10 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1040:630:195c:38a7:a411]) by smtp.gmail.com with ESMTPSA id 94-20020a17090a09e700b0020af2411721sm721942pjo.34.2022.10.13.23.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 23:16:10 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ingo Molnar , Peter Zijlstra , LKML , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, Kan Liang , Leo Yan , Andi Kleen , Athira Rajeev , James Clark , Xing Zhengjun Subject: [PATCH 11/19] perf stat: Allocate aggr counts for recorded data Date: Thu, 13 Oct 2022 23:15:42 -0700 Message-Id: <20221014061550.463644-12-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221014061550.463644-1-namhyung@kernel.org> References: <20221014061550.463644-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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(). Acked-by: Ian Rogers Signed-off-by: Namhyung Kim --- tools/perf/builtin-stat.c | 20 +++++++++++++++----- tools/perf/util/stat.c | 39 +++++++++++++++++++++++++++++++-------- tools/perf/util/stat.h | 2 ++ 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 6777fef0d56c..2a6a5d0c5563 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1342,7 +1342,11 @@ static struct aggr_cpu_id perf_stat__get_cpu(struct = perf_stat_config *config __m static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *con= fig, aggr_get_id_t get_id, struct perf_cpu cpu) { - struct aggr_cpu_id id =3D aggr_cpu_id__empty(); + struct aggr_cpu_id id; + + /* per-process mode - should use global aggr mode */ + if (cpu.cpu =3D=3D -1) + return get_id(config, cpu); =20 if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu])) config->cpus_aggr_map->map[cpu.cpu] =3D get_id(config, cpu); @@ -2125,17 +2129,23 @@ int process_stat_config_event(struct perf_session *= session, if (perf_cpu_map__empty(st->cpus)) { if (st->aggr_mode !=3D AGGR_UNSET) pr_warning("warning: processing task data, aggregation mode not set\n"); - return 0; - } - - if (st->aggr_mode !=3D AGGR_UNSET) + } else if (st->aggr_mode !=3D AGGR_UNSET) { stat_config.aggr_mode =3D st->aggr_mode; + } =20 if (perf_stat.data.is_pipe) perf_stat_init_aggr_mode(); else perf_stat_init_aggr_mode_file(st); =20 + if (stat_config.aggr_map) { + int nr_aggr =3D stat_config.aggr_map->nr; + + if (evlist__alloc_aggr_stats(session->evlist, nr_aggr) < 0) { + pr_err("cannot allocate aggr counts\n"); + return -1; + } + } return 0; } =20 diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 3593af403188..d0e5c4c402aa 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -141,6 +141,31 @@ static void evsel__reset_stat_priv(struct evsel *evsel) memset(aggr, 0, sizeof(*aggr) * ps->nr_aggr); } =20 +static int evsel__alloc_aggr_stats(struct evsel *evsel, int nr_aggr) +{ + struct perf_stat_evsel *ps =3D evsel->stats; + + if (ps =3D=3D NULL) + return 0; + + ps->nr_aggr =3D nr_aggr; + ps->aggr =3D calloc(nr_aggr, sizeof(*ps->aggr)); + if (ps->aggr =3D=3D 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; +} =20 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 =3D=3D NULL) return -ENOMEM; =20 - if (nr_aggr) { - ps->nr_aggr =3D nr_aggr; - ps->aggr =3D calloc(nr_aggr, sizeof(*ps->aggr)); - if (ps->aggr =3D=3D NULL) { - free(ps); - return -ENOMEM; - } + evsel->stats =3D ps; + + if (nr_aggr && evsel__alloc_aggr_stats(evsel, nr_aggr) < 0) { + evsel->stats =3D NULL; + free(ps); + return -ENOMEM; } =20 - evsel->stats =3D ps; perf_stat_evsel_id_init(evsel); evsel__reset_stat_priv(evsel); return 0; diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 0980875b9be1..4c00f814bd79 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -275,6 +275,8 @@ void evlist__reset_prev_raw_counts(struct evlist *evlis= t); void evlist__copy_prev_raw_counts(struct evlist *evlist); void evlist__save_aggr_prev_raw_counts(struct evlist *evlist); =20 +int evlist__alloc_aggr_stats(struct evlist *evlist, int nr_aggr); + int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); struct perf_tool; --=20 2.38.0.413.g74048e4d9e-goog