Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4969468rdb; Tue, 12 Dec 2023 15:04:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGsWs6W6KhBuUdk34lWLJXaCf0kIW8K+RhAnQ0pcsdS2Psj9ThDeTyfQjSKPBHGy7cGeyQf X-Received: by 2002:a05:6a20:561a:b0:18f:97c:9791 with SMTP id ir26-20020a056a20561a00b0018f097c9791mr7492649pzc.121.1702422287327; Tue, 12 Dec 2023 15:04:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702422287; cv=none; d=google.com; s=arc-20160816; b=MwaOUeFRJHuViQVUVD7f6+/L5q8WQpahV811bFi3mLNdSdRQE9w6SPErIGnOkHwCDM AUthtcp1mbKXe6xu/uVxwtPAkOwvTOdk3lMclEQFH+Ri5Nlludwhx7ZyUcUK+6oJPBlL Hsljzmdw8FElW2t4qAVp9MLUX6WmMxNIEtXvsq40xptLkasSp0amWtoVjS0Y1WZ13Pxa ls4EIIYsb5y6tH6epJWuV2ZCMGz9lCcfXb8P8qrlf1i8hJq3ES9iX177RvHI0qPK9Rma ikDy7bqH/4ayhyKb1WYGtLPPQaBvWophjd0w4Q9GsUscK1yTlBXlfpPOa05VyR1mfoNi 0f8g== 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 :dkim-signature; bh=1ROYLXZZDB8UzpNrnBNdyb3oU28IB2OiqbefsromB3o=; fh=fjecWn2tsXHKF5pPtw+gI2dQE/iSXdFsWSc8KUP/zmc=; b=AIdPgO7PYjryc2q393CvhZMNAf6SJ+cNsaWe6P/qdMacUM7UAboXFoeQo8QSnjr971 2ZXSI9B02EhPXtBT2UT4CnVGNIjAlk1LbJH9nRC8IoUokE1TOOJAZM69qRuHYahZ3g3q CcCU3EofQbRIRhgPWsjmpTahvvzroHFQa+ifi+L81YiHt7eSLBv98hCOGL/rRrswIIvS e/zid6jfeBeF8YoOiXW96UnDhvXLaXd6ggBVohNG5qGGmzdTVwvAzwWbxB8id1rsD2Pc zCqXzNuekR/WDwu2DaYUa11tUZ2hiy9SBcufrC+LefGpvrrYlzwaP8uYccVk1zETTfqi cxWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="avP/fPAO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id y13-20020a056a00190d00b006cd8cddf8c5si8592829pfi.14.2023.12.12.15.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 15:04:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="avP/fPAO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 09D6A80B180C; Tue, 12 Dec 2023 15:04:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377999AbjLLXE2 (ORCPT + 99 others); Tue, 12 Dec 2023 18:04:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378009AbjLLXEH (ORCPT ); Tue, 12 Dec 2023 18:04:07 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 980B7183; Tue, 12 Dec 2023 15:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702422230; x=1733958230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HOyOzk0+wNdz1WzmnRxxfaKj7IPbOKpt9kNKcGEtJHc=; b=avP/fPAOdtWmbyQphOliWqClgISSQNywF65CTl3Xc23t/M8aijuuv0JM D1MhcQ/CP0UQSxeFUq5K2wwBff2R/FMGjtro6S8SjoKRTVA6jwLXTLuyb c2f910jh+o7MiAtNDR1q0WqVYkL/25oUrUpw9uJspjXgH9y8uInKOHLuz kBYBgXdWSBCX4gxTfzMrrVsciENVedqK6FJrEHGInYVl7rSfRnqh11rz9 tM+0kOf+Dr9xwSCf4tmotniuyyQCq/4kzU5GDoyYEJQ8/Uko/pQ397Hjq QeND1oTZAKST7+SkLuc3wJ9mxt3Qhc2ybf7quWt19e41yHWkNcCYTED2p A==; X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="392056003" X-IronPort-AV: E=Sophos;i="6.04,271,1695711600"; d="scan'208";a="392056003" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2023 15:02:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="864392024" X-IronPort-AV: E=Sophos;i="6.04,271,1695711600"; d="scan'208";a="864392024" Received: from node-10329.jf.intel.com ([10.54.34.22]) by FMSMGA003.fm.intel.com with ESMTP; 12 Dec 2023 15:02:55 -0800 From: weilin.wang@intel.com To: weilin.wang@intel.com, Ian Rogers , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers , Mark Rutland , Yang Jihong Subject: [RFC PATCH v3 12/18] perf stat: Add function to combine metrics for hardware-grouping Date: Tue, 12 Dec 2023 15:02:18 -0800 Message-Id: <20231212230224.1473300-14-weilin.wang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231212230224.1473300-1-weilin.wang@intel.com> References: <20231212230224.1473300-1-weilin.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 12 Dec 2023 15:04:45 -0800 (PST) From: Weilin Wang This function is very similar to the existing build_combined_expr_ctx(). Should be able to reuse current function instead of adding a new one. Will fix this later. Signed-off-by: Weilin Wang --- tools/perf/util/metricgroup.c | 51 +++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 03383f820e06..016ea949ba5d 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1432,10 +1432,50 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, return ret; } +/** + * hw_aware_build_combined_expr_ctx - Make an expr_parse_ctx with all !group_events + * metric IDs, as the IDs are held in a set, + * duplicates will be removed. + * @metric_list: List to take metrics from. + * @combined: Out argument for result. + */ +static int hw_aware_build_combined_expr_ctx(const struct list_head *metric_list, + struct expr_parse_ctx **combined) +{ + struct hashmap_entry *cur; + size_t bkt; + struct metric *m; + char *dup; + int ret; + + *combined = expr__ctx_new(); + if (!*combined) + return -ENOMEM; + + list_for_each_entry(m, metric_list, nd) { + hashmap__for_each_entry(m->pctx->ids, cur, bkt) { + pr_debug2("metric: %s\n", m->metric_name); + dup = strdup(cur->pkey); + if (!dup) { + ret = -ENOMEM; + goto err_out; + } + ret = expr__add_id(*combined, dup); + if (ret) + goto err_out; + } + } + return 0; +err_out: + expr__ctx_free(*combined); + *combined = NULL; + return ret; +} + /** * set_counter_bitmap - The counter bit mapping: [8-15,0-7], e.g. the GP0 is the - * 8th bit and GP7 is the 1st bit in this 16-bits bitmap. It is helpful for - * assigning GP4-7 before GP0-3 because some events can be collected using GP0-3 + * 8th bit and GP7 is the 1st bit in this 16-bits bitmap. The is helpful to + * assign GP4-7 before GP0-3 because some events can be collected using GP0-3 * only on some platforms. */ static int set_counter_bitmap(int pos, unsigned long *bitmap) @@ -1722,8 +1762,7 @@ static int metricgroup__add_pmu_layout_callback(const struct pmu_layout *pl, * @table: pmu_layouts table that is searched for counter info. */ static int get_pmu_counter_layouts(struct list_head *pmu_info_list, - const struct pmu_layouts_table - *table) + const struct pmu_layouts_table *table) { LIST_HEAD(list); int ret; @@ -2155,6 +2194,8 @@ static int hw_aware_parse_ids(struct perf_pmu *fake_pmu, *out_evlist = parsed_evlist; parsed_evlist = NULL; err_out: + parse_events_error__exit(&parse_error); + evlist__delete(parsed_evlist); metricgroup__free_grouping_strs(&groupings); return ret; } @@ -2277,7 +2318,7 @@ static int hw_aware_parse_groups(struct evlist *perf_evlist, if (!metric_no_merge) { struct expr_parse_ctx *combined = NULL; - ret = build_combined_expr_ctx(&metric_list, &combined); + ret = hw_aware_build_combined_expr_ctx(&metric_list, &combined); if (!ret && combined && hashmap__size(combined->ids)) { ret = hw_aware_parse_ids(fake_pmu, combined, -- 2.39.3