Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp174638lqp; Fri, 12 Apr 2024 14:10:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWDzDbwWmpa3/Eem/qFSTajJ0P+ErUkrY8fbpe8c288pCK/TkMWn+Z2mg0V+jNDiU2zFCQwpd4WWL1ukkvnCRCZTS6UrCaD5Ozm6uTOxw== X-Google-Smtp-Source: AGHT+IFotFbDhZOGA6Np1pSicJYkJdtRC+4ArMVblb4NyprwG5eQH4Xbar4uBmcFy4TwoR/FvYQM X-Received: by 2002:a17:90b:3597:b0:2a5:5334:e223 with SMTP id mm23-20020a17090b359700b002a55334e223mr3361418pjb.24.1712956217804; Fri, 12 Apr 2024 14:10:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712956217; cv=pass; d=google.com; s=arc-20160816; b=pcK8dfkYEbgc/zMxMylBh4sAmjTYEyKy1rxqUtYnkeL0tXnsVkvHuuXN3IOM3QnY+U kwqEO8TYHYsSdwaZelayCrdsQNdSwRGvdKUIdrCf6Eq0Kx/uFdi18YYl1m1GR023hW5L ASLQvRByRDLZIjBEGMoXixcZo9+VxNgkXS1sIelqcgtPdYeo/3khmOql8seQyihd7Hyv Q27CfTQWGrXdO/TSvKyccPS2B3SDNcCdLkJKX/YJA8A2Az1ZJDMQ9mqvA+XV/rGFxG4T XifAYCzcm2Q21uaBS17ZbjFix4xWzHVFtlvD+T5hUSQcAyp4i3LOzW7ybdRRG6q3qbtt QWuA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fh7il97WzReqGu5tgxns9spUb71RCLVGgqFQenx0JNk=; fh=2mx6v3byCNS4RNMabLmfY6Bz0Xn6VvJsmk1bF8Vd49Q=; b=p33XyiEOlFmBpWMpCFWhrizfQFYLZAPe/GeBjEcSDsXes0DuKdBeavL/mGrQnPcohA 2bkuocWASexJbYGWWU6C3QOd0gkX9Zw9Vy7343bVOV7rkyX+26p5jTidcpSflXRB5fLs gE40QVSopQqeL0VCTYVdJxAjpsfj1Xewe5Jy9585NUGMJV7xW+P3eEYpFEZCl9qKZTWE Hhc98IGzmvOUd/h6nDt4UiJEdme2UvI/7yMdWu3Ke0j/pdoO15zXZ0IoZ5tgCzEp8LiY CEL5U1euhJQKyJMX2SdgdrfgfWRSs2SJqf8f8kj1C5t5aLNJCBS9tGEktOlTQAbimqF2 oa2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AxV0iNPg; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-143363-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143363-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y22-20020a17090aa41600b002a08fd2c322si6209805pjp.116.2024.04.12.14.10.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 14:10:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143363-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=AxV0iNPg; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-143363-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143363-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 7F5182817B2 for ; Fri, 12 Apr 2024 21:10:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EB3D15350F; Fri, 12 Apr 2024 21:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AxV0iNPg" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9FDD6152527; Fri, 12 Apr 2024 21:08:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712956098; cv=none; b=rQ5RFaLGfwCcqOn2Li6eohmU0HvHJLu6s7tl8efmfYL31ysAUl9zWzKm9VXCytkgePKJRAxAzkeCH+XEqsgVUQkEZvzCMO69FwmFlMl1XbXGgBLu0Lje38D/Exa9jk4p9xH/4+X87C9OyEMcXrwWuuVFj7c5Wp7g4Pld67MlMzQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712956098; c=relaxed/simple; bh=QkVtBQWWBMMe1MNkeP0H8yozIjK/9HP9b2M/bd9n5rI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NRL49wY4w9Etc6bshtlG2G7j8Y541iJc+S9qxCVonmX8jRbUpgxESUQ6TtG50xNS68BiahSqXw2dZykDwtuEy/I6olnIjdIXs4lo8wHHbacaVefvV7kC6Ji/Vp/SgFOB4o5pvlCSJlJ/q4+7b5CfFZSkMq9+bnMJe0Ho10Zxm8o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AxV0iNPg; arc=none smtp.client-ip=198.175.65.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712956096; x=1744492096; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QkVtBQWWBMMe1MNkeP0H8yozIjK/9HP9b2M/bd9n5rI=; b=AxV0iNPgRfNDHLAx2GA9T37UiNxf0Ju8RGbd9H1F5q0TfZ0fMkOozWHQ YB9n/uu8pN/9AHw74glxd39oYQCjLxgt1P8APYhVAT+xguWhIpKMEimKf WQH5PGk7599nKKMM9Hnxfx5MKEUzrrUcY/6eoxLqtsD7LGWAgpwn9Svx3 +CR/8Akr3uZm39wvBySkrdS5HxV1k3gOAxTCrsdcXXUk1uCKmTE84t72s Rb97oO6sNjwvuWr9tP827WPzx4+pStd3II95/Y2797weZo5DbOXi2qoby yIWc3NwYW/HGv27D5q/RIY6Ak7/opmGJ8wDI7Dgg7z+bGj9YVRGfNTT4S w==; X-CSE-ConnectionGUID: j+9YggPBQ02gntylHSuP2g== X-CSE-MsgGUID: +DhTQty5RJKupYEQVavYFA== X-IronPort-AV: E=McAfee;i="6600,9927,11042"; a="19575478" X-IronPort-AV: E=Sophos;i="6.07,197,1708416000"; d="scan'208";a="19575478" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2024 14:08:11 -0700 X-CSE-ConnectionGUID: CP8JkpW1QJCivNJxMLE4Pw== X-CSE-MsgGUID: CLNit7O2RaucMSlIVoQdiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,197,1708416000"; d="scan'208";a="21772108" Received: from b49691a74b80.jf.intel.com ([10.165.54.183]) by orviesa006.jf.intel.com with ESMTP; 12 Apr 2024 14:08:10 -0700 From: weilin.wang@intel.com To: weilin.wang@intel.com, Ian Rogers , Kan Liang , Namhyung Kim , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Adrian Hunter Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers Subject: [RFC PATCH v5 10/16] perf stat: Add function to combine metrics for hardware-grouping Date: Fri, 12 Apr 2024 14:07:50 -0700 Message-ID: <20240412210756.309828-11-weilin.wang@intel.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240412210756.309828-1-weilin.wang@intel.com> References: <20240412210756.309828-1-weilin.wang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 | 47 ++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 681aacc15787..b9e46dff1e17 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -1528,6 +1528,46 @@ 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 bitmap: [0-15]. */ @@ -1851,8 +1891,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; @@ -2288,6 +2327,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; } @@ -2410,7 +2451,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.42.0