Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp391926rwr; Wed, 26 Apr 2023 00:21:13 -0700 (PDT) X-Google-Smtp-Source: AKy350bhNGpEiPc0LnZLmMq+UWwi27BsbLmSmULbPKL7+iifvmE6nMjm8pNhZNclwnQebBklhW6f X-Received: by 2002:a05:6a20:8424:b0:ef:6c30:5798 with SMTP id c36-20020a056a20842400b000ef6c305798mr24732824pzd.27.1682493672708; Wed, 26 Apr 2023 00:21:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682493672; cv=none; d=google.com; s=arc-20160816; b=N+XBDM9iSypWxS4lHVYS+d1m5A9yNCuHrRgrxEnOYPr7YrW8tcGexvpRyAY1xjUIYJ l5mx4GQ+G53CEPspWJP1sYrHDmhZSlCFyToOI/91POC7945bEbyZoH7gclUg5lH8ID8z friV7uKO2ztdtUL0nBoQuvsBUmfepLVjJyvfqAqIoKd6fvhErsKs7hNpvCpDgJALRkB/ 301LwAI0B6RbFe1svvCSle58LCkaxJmnVk0sq0aOTvruSTkU73KLsOMMak0WGk3k6zHx l1Ow7hyI3emPRsbuKT9aHRyUObYkKBSavbihu4LYnICw05XGu8vxQVNcJfHoiJfkjOEQ poGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=6DTTYiMDl8Yj+KSHhgdntFRxS2mVbWmHBiQYwku76Lg=; b=G9aYYV1KmZ+XXqX8G/KRumFifL8vg8l0Z7JG23pGKCQwuqq/d6eEn6UObeA4gwQdZt b+Xvz0bf4rYHyFUut3uui9UwH01w7JGMWkthk5VXh98rEed506uONFIIIWrO8/ppTKJ6 S0tPFgNMskVMX9dvbDXsho3PyfkW3W+OQqB4l0h8TKglYzDLHcZXU0W0C85H4Tr4YbBF K3W5kNNLXKd1I0928QLaFF5xP3XMk2R6V15xmqza6nI67r73Kog7ZU/X7on/KSzS5Qk2 Iamx5x7Mv7sxOF/9qG88VbA7z8Rvyf3728J25RGfOK/7XbT6WKrmunTudPmNQKQY6GKF T+cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=NuU46hM8; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv189-20020a632ec6000000b005139bf86110si15295829pgb.673.2023.04.26.00.21.00; Wed, 26 Apr 2023 00:21:12 -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=@google.com header.s=20221208 header.b=NuU46hM8; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239943AbjDZHNq (ORCPT + 99 others); Wed, 26 Apr 2023 03:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239624AbjDZHNT (ORCPT ); Wed, 26 Apr 2023 03:13:19 -0400 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CAB13C06 for ; Wed, 26 Apr 2023 00:12:37 -0700 (PDT) Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-b9a25f6aa0eso1478580276.1 for ; Wed, 26 Apr 2023 00:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682492788; x=1685084788; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=6DTTYiMDl8Yj+KSHhgdntFRxS2mVbWmHBiQYwku76Lg=; b=NuU46hM8LqQefH+YUTb3RKzWxAv35JqvJXoIH5cWztwofbicXwg7nad3a6f9YfDNEL rEtUMgkRfEzT1d2Vwg+Atwo1CgX6Ua4BRxM4sfuvrH5Y9uT1uimewphrq8Orj+A/FjhY nh1UFa/id/1xp7od0utvoOYBMMUYApzDoJH9+ckOtTEzj5/ft0UquC6DP/QnX+XH0pd9 o4Zcl2XAEf6GCsalvz9OezYmZJnhUJtgcNIHU3DbIx+CjQ4XLGWHqNW9yhAG1E+KihJO JNhPN/xm0YvM2apAOD79h/cXTF9wIUNgAC/ydIZcOKYxjQPoJj/rSkMZmxxNbZuik0pm ubvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682492788; x=1685084788; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6DTTYiMDl8Yj+KSHhgdntFRxS2mVbWmHBiQYwku76Lg=; b=jT2J2YLXZMY+yHRbdBohE9ldjmRs322LoKqyKqRia4JCpz0Up5SAMbxXLQrAJErHtt goWAfDCrhdgWT76z9DnbEoH89XpU/TAmiN3evZ5UdFK4g/aXTBwdWaaoTD7uMLIjz2Vr F3HB2oux4nIpgK5gnQcGS8LUbvwK7Jj9295y1a3FUcqLrms3j/kcjbv/cc3BHGBQsjR2 ppV5xbBkn7Q47OJEllBHXC2zmzNnGNa2LysBYBXV53mURivMrSeyLEzkL4Rv/BtklqjF 2HJK37GWFzv7PmJGWJkRLagMLvneNn0OvoBH7mjjerSZSCHaDRUgcY+1Wz2giMVWBLXk 4pdw== X-Gm-Message-State: AAQBX9flp2xldzQekS7urm5lDhXYDRylNpZhtFVwn8p3fR4hEAdW3w2W RyYYIZ9CqkFBj0tNvRe0o++d2w4kfqt2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:144f:e890:2b29:48d9]) (user=irogers job=sendgmr) by 2002:a25:cf13:0:b0:b92:37f6:faff with SMTP id f19-20020a25cf13000000b00b9237f6faffmr7735741ybg.10.1682492788563; Wed, 26 Apr 2023 00:06:28 -0700 (PDT) Date: Wed, 26 Apr 2023 00:00:49 -0700 In-Reply-To: <20230426070050.1315519-1-irogers@google.com> Message-Id: <20230426070050.1315519-40-irogers@google.com> Mime-Version: 1.0 References: <20230426070050.1315519-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Subject: [PATCH v1 39/40] perf jevents: Don't rewrite metrics across PMUs From: Ian Rogers To: Arnaldo Carvalho de Melo , Kan Liang , Ahmad Yasin , Peter Zijlstra , Ingo Molnar , Stephane Eranian , Andi Kleen , Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Florian Fischer , Rob Herring , Zhengjun Xing , John Garry , Kajol Jain , Sumanth Korikkar , Thomas Richter , Tiezhu Yang , Ravi Bangoria , Leo Yan , Yang Jihong , James Clark , Suzuki Poulouse , Kang Minchul , Athira Rajeev , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ian Rogers Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 Don't rewrite metrics across PMUs as the result events likely won't be found. Identify metrics with a pair of PMU name and metric name. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/jevents.py | 4 ++-- tools/perf/pmu-events/metric.py | 28 +++++++++++++++++----------- tools/perf/pmu-events/metric_test.py | 6 +++--- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py index b18dd2fcbf04..487ff01baf1b 100755 --- a/tools/perf/pmu-events/jevents.py +++ b/tools/perf/pmu-events/jevents.py @@ -391,11 +391,11 @@ def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]: except BaseException as err: print(f"Exception processing {path}") raise - metrics: list[Tuple[str, metric.Expression]] = [] + metrics: list[Tuple[str, str, metric.Expression]] = [] for event in events: event.topic = topic if event.metric_name and '-' not in event.metric_name: - metrics.append((event.metric_name, event.metric_expr)) + metrics.append((event.pmu, event.metric_name, event.metric_expr)) updates = metric.RewriteMetricsInTermsOfOthers(metrics) if updates: for event in events: diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py index 8ec0ba884673..af58b74d1644 100644 --- a/tools/perf/pmu-events/metric.py +++ b/tools/perf/pmu-events/metric.py @@ -552,28 +552,34 @@ def ParsePerfJson(orig: str) -> Expression: return _Constify(eval(compile(parsed, orig, 'eval'))) -def RewriteMetricsInTermsOfOthers(metrics: List[Tuple[str, Expression]] - )-> Dict[str, Expression]: +def RewriteMetricsInTermsOfOthers(metrics: List[Tuple[str, str, Expression]] + )-> Dict[Tuple[str, str], Expression]: """Shorten metrics by rewriting in terms of others. Args: - metrics (list): pairs of metric names and their expressions. + metrics (list): pmus, metric names and their expressions. Returns: - Dict: mapping from a metric name to a shortened expression. + Dict: mapping from a pmu, metric name pair to a shortened expression. """ - updates: Dict[str, Expression] = dict() - for outer_name, outer_expression in metrics: + updates: Dict[Tuple[str, str], Expression] = dict() + for outer_pmu, outer_name, outer_expression in metrics: + if outer_pmu is None: + outer_pmu = 'cpu' updated = outer_expression while True: - for inner_name, inner_expression in metrics: + for inner_pmu, inner_name, inner_expression in metrics: + if inner_pmu is None: + inner_pmu = 'cpu' + if inner_pmu.lower() != outer_pmu.lower(): + continue if inner_name.lower() == outer_name.lower(): continue - if inner_name in updates: - inner_expression = updates[inner_name] + if (inner_pmu, inner_name) in updates: + inner_expression = updates[(inner_pmu, inner_name)] updated = updated.Substitute(inner_name, inner_expression) if updated.Equals(outer_expression): break - if outer_name in updates and updated.Equals(updates[outer_name]): + if (outer_pmu, outer_name) in updates and updated.Equals(updates[(outer_pmu, outer_name)]): break - updates[outer_name] = updated + updates[(outer_pmu, outer_name)] = updated return updates diff --git a/tools/perf/pmu-events/metric_test.py b/tools/perf/pmu-events/metric_test.py index 40a3c7d8b2bc..ee22ff43ddd7 100755 --- a/tools/perf/pmu-events/metric_test.py +++ b/tools/perf/pmu-events/metric_test.py @@ -158,9 +158,9 @@ class TestMetricExpressions(unittest.TestCase): def test_RewriteMetricsInTermsOfOthers(self): Expression.__eq__ = lambda e1, e2: e1.Equals(e2) - before = [('m1', ParsePerfJson('a + b + c + d')), - ('m2', ParsePerfJson('a + b + c'))] - after = {'m1': ParsePerfJson('m2 + d')} + before = [('cpu', 'm1', ParsePerfJson('a + b + c + d')), + ('cpu', 'm2', ParsePerfJson('a + b + c'))] + after = {('cpu', 'm1'): ParsePerfJson('m2 + d')} self.assertEqual(RewriteMetricsInTermsOfOthers(before), after) Expression.__eq__ = None -- 2.40.1.495.gc816e09b53d-goog