From patchwork Tue Oct 18 02:02:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 3884 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1734722wrs; Mon, 17 Oct 2022 19:05:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5v5vm+nFgm4hZyGpJW7g59dXlRvyIIjGaDc+Wpiu2MbxypNBKUJNfBIattrzuP+myjFlf0 X-Received: by 2002:a17:902:6b88:b0:17e:f177:400 with SMTP id p8-20020a1709026b8800b0017ef1770400mr660971plk.72.1666058701057; Mon, 17 Oct 2022 19:05:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666058701; cv=none; d=google.com; s=arc-20160816; b=bpApoNIXOeRBWdhT+p6D1E8zMa3kNMdvD6M4gighiOzK77zUuArVBVNpCP6P18r016 DcJM0P+bTb6KL7a4p/O+oV52W1VrmOJv0eR5vyRk2HOOMQfzXuaOJGM1go0VmCV4AXGI ar2OhlMK7ynPP6enwOGbK56m5M3gA/oGEMdU1kB2+VeYn1fRYDkaSZwL5QUrtAsv+Obn ij3iQbQio+tqHztjgBjW9rx/Te0L3q/Br+QpnWPmkG1zy86NlN0fhQ4p4/z0wpElyF/0 wiYL7plO7RIHM9v19k1qkbsS0gt9JxyuElJZ95ayORMy9/bSFBLJEa4oKnYAuypkgmkz es/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=45K39jThQAzcpDReWZZtA2vEDUWmLg4vPVifalEZNJI=; b=gRTYy3xXPVauXV4GErLC8S9GuVHVuEpC7EyaFANLOlvGC9uy/HlWNnGRj0MYDOt+8i +nSgGyG/0RPH5zwZ2onJ5prulVBDfbTFS4igbKhMuiajL6b1mCoNa94LNZwzwEnpMGGv kRSXHc0+KqIgPh21+1BvtXduI2wVfMf0RmtIeE93+MGDiBpC06e6iSJcT6uFVg1yA+cd EFDcXjwrUlv0bB8T3ML7TGbsOh6IU0HUTtuytvOCQgeoFAcHRjBwHTeIZx833x6+yHMt SHgaQ61rK0vks/tT/3fhBuGoEraGTTNXTHtTtMpSsgiF1yCoNGFaH/y+j9aCrMUELoWu nVQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RRCmWXoQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f68-20020a636a47000000b00460f2778434si13592617pgc.652.2022.10.17.19.04.48; Mon, 17 Oct 2022 19:05:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=RRCmWXoQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231214AbiJRCDx (ORCPT + 99 others); Mon, 17 Oct 2022 22:03:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230151AbiJRCDP (ORCPT ); Mon, 17 Oct 2022 22:03:15 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5CA78D0EA; Mon, 17 Oct 2022 19:02:53 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id o21so10057548ple.5; Mon, 17 Oct 2022 19:02:53 -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=45K39jThQAzcpDReWZZtA2vEDUWmLg4vPVifalEZNJI=; b=RRCmWXoQWPtnH+4Ky1/XpCLaYx2vBLbMMXmwSd7IPEj9WWBYYoGU6A2pE6DXXBMZ8N wDAloXeoQ3Bi/zhVYXtQLWjX+QWrzK52erK/EnlrfIk41h89PM6umD1ktGcvEqZ5pMXP bwqD4l1L/hwkQf5dNXgq13ecX0ZQ/BtZxN3+RUqoSwE+luf45Rk90kRVfRWA/BjBghwS UJNkIf0BvaYQ/jyv+nZHh+V+2BNsHWSQoJesE3cjQuIcNyoqMTWUfbhIMLq0NdBsQBAM pe8f0RThFlZQ0QjsAHiOgbeL4AUItmYUJXMT8KFwESkTNcQG2dXg32vf2EBKwdXlWF8d 5LIQ== 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=45K39jThQAzcpDReWZZtA2vEDUWmLg4vPVifalEZNJI=; b=2YXABTwFY+sZmFyz4Kh7YEKRGS50W8SZoaPN++igXW5E7SUv7s91wgMBNoV5BQOYdL z793PchlmgtySfy+HboZgUTua09f2VWP+qywtdlifWQFErv8yHp/PQ1Xj1NzvXCvDrw8 kJ2hqMkgjDyiMxnsgDiaMhBq9OYj6kimLXmw2zZYZm+WT1VtGapqQVa1vdeHR2PN/joI F1UOYCdMa0CaBA0aVW+k6DS3XwDZbbHK+USR42gmP/A+NJh+dKEEzybhUOACzTnu98c3 8zpB9O2pI0yPTP1gk3lORRycIC0Ajn5Hk4GbVUvkZWL42/qes7K4iOoqoRz8cr/CGkS0 Y/Rw== X-Gm-Message-State: ACrzQf1enHE9MkL8yqGYEFaeKSy8dN/SQMG8jmnyNW1VkC7nLrEwU6sg Vb0y3sfNZhOq176HSuL0KTo= X-Received: by 2002:a17:902:7295:b0:17d:5176:fe6e with SMTP id d21-20020a170902729500b0017d5176fe6emr578396pll.147.1666058572444; Mon, 17 Oct 2022 19:02:52 -0700 (PDT) Received: from balhae.hsd1.ca.comcast.net ([2601:647:6780:1f90:85c4:58f0:7a81:6bb5]) by smtp.gmail.com with ESMTPSA id t4-20020a655544000000b00464858cf6b0sm6851564pgr.54.2022.10.17.19.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 19:02:52 -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 , Michael Petlan Subject: [PATCH 12/20] perf stat: Allocate aggr counts for recorded data Date: Mon, 17 Oct 2022 19:02:19 -0700 Message-Id: <20221018020227.85905-13-namhyung@kernel.org> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog In-Reply-To: <20221018020227.85905-1-namhyung@kernel.org> References: <20221018020227.85905-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746989168298533918?= X-GMAIL-MSGID: =?utf-8?q?1746989168298533918?= 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 *config, aggr_get_id_t get_id, struct perf_cpu cpu) { - struct aggr_cpu_id id = aggr_cpu_id__empty(); + struct aggr_cpu_id id; + + /* per-process mode - should use global aggr mode */ + if (cpu.cpu == -1) + return get_id(config, cpu); if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu])) config->cpus_aggr_map->map[cpu.cpu] = 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 != AGGR_UNSET) pr_warning("warning: processing task data, aggregation mode not set\n"); - return 0; - } - - if (st->aggr_mode != AGGR_UNSET) + } else if (st->aggr_mode != AGGR_UNSET) { stat_config.aggr_mode = st->aggr_mode; + } if (perf_stat.data.is_pipe) perf_stat_init_aggr_mode(); else perf_stat_init_aggr_mode_file(st); + if (stat_config.aggr_map) { + int nr_aggr = 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; } diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 5b04c9d16156..1b9048115a18 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); } +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; 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 *evlist); 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); + int perf_stat_process_counter(struct perf_stat_config *config, struct evsel *counter); struct perf_tool;