From patchwork Wed Feb 28 17:56:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 207943 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3510565dyb; Wed, 28 Feb 2024 09:58:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXkBb401wAcsNFJtcvbSZX3U2IwRnyK6m45v3/2l6cJ6hPx/l7hSqOy/EVLETVzukP3zUkENugU9HyUamQFAmHVq7c4vQ== X-Google-Smtp-Source: AGHT+IG2GtNF7wcJPeWTdOIVzUtT8GnnkE8OOLQvsmR8B9GCfVhSJ63geH0C52wEzdokpKYrUTlT X-Received: by 2002:a17:906:4e8a:b0:a43:af8c:ef35 with SMTP id v10-20020a1709064e8a00b00a43af8cef35mr356044eju.75.1709143083731; Wed, 28 Feb 2024 09:58:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709143083; cv=pass; d=google.com; s=arc-20160816; b=A7Eswij8ExV4KnwP+kgSvv9HQaV0IpOuTW4aidgX063tsWa/II57L7YNVDrvzyvCHO 1sOF5xMoGVFQT6rS74nbeSpZD4kGPWHbIaFzs61+yUeTH0cZ5sk5PRskdf1UW1sI0b2E Bd7we05dfbRi5/4geJxChppBj0m/zU99h5yen/GboNRDF0fvpcoEbtBT/CKOR1PIRPd8 6f6HsUShazjhKlLflyVjqsjGnad1zOw6A21IO2yqarc+qzkEy/yklVyd3wdSd6g5RAg0 2AntIeKWX/D3GicSCdknUAY2XGVXje5lQFcLpbaWHgDV0oeWJa49Yw4u1iXtjx2xDNXN ACtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=bBWDWJvSshoSjEVW3Suakt0O9q+vGDdTpywx5NXn+PM=; fh=Lw0McdTWQUeymXp9IXvLQj0c2dKLcZyqgwcnhv5lBj4=; b=UXpYs1nhZgDq+V8Lzb7SdZLr2B8Pm1YqZtRubL2EKdOIvIToVrQ6i4e4OQfuMfb6vZ CwhyEmVKh0J/5ooF8o7NkobeUsypXeTwjSrwS9NxI+JFdFdrIiU/KXoFSNe3OBeeUeL8 yXt+s7jDbkLfJAVb6ii0oTdc/FHUKChY+MYD9HMdCnGQ0h0EqRncsECYIef0Pv7hE0l1 sBWMfg5/q57AdFUFFQIhSBp9r2YJtMhsblCtYm7q2mjOBwzcT/gR++55X6sPoeysZ6vN uDwJ4J74OkYussMYUXu1oL/iOcQ9ZGhx11NYDhab69sh1apvYw5XhonM6urEUuvru3Ci 7ONg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3k6CA1bp; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85480-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85480-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lt7-20020a170906fa8700b00a435146e567si1848935ejb.621.2024.02.28.09.58.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 09:58:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85480-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3k6CA1bp; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85480-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85480-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5686D1F229B8 for ; Wed, 28 Feb 2024 17:58:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 23EE240868; Wed, 28 Feb 2024 17:56:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3k6CA1bp" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C65581649CF for ; Wed, 28 Feb 2024 17:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709143010; cv=none; b=Ag6qDPEzyqAIBml/7H2c7WvnZ5OuNY5NUCP2xwFtNTzRktcl9apijgLA2OI3Ad8KiVuVTUVRAkScac6atRffqJcJ34o/oh5JuMmHVOz2Nook48+PZX/mRRxLraAQWojSOnxsIAk+C2t2iz3F1bo334NiAB47dz/OcZH2mpOvXVs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709143010; c=relaxed/simple; bh=j1Uteud1mWr9qwRDjsafkmahAN/I9mDRvh5Ckh8gIQo=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=GOz5lb7tpic774pLlG4r8egCcM6rkBTBpGIGs9C1iPt477mJXEpjmiN3I8sdOXkBe8+35GSGw5p0VrMQ9bphYV8PS9MAogrCZjfVEq9HVuzicOI329qpUwt4x3/Fd1l61E/x0qBRULAp199+HoU54E6UVAFPuE4EfsNop1tFWhM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=3k6CA1bp; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dcd1779adbeso82098276.3 for ; Wed, 28 Feb 2024 09:56:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709143008; x=1709747808; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=bBWDWJvSshoSjEVW3Suakt0O9q+vGDdTpywx5NXn+PM=; b=3k6CA1bpfOmxIZqZ6XVv7CzRmNKcgV9+xxZd4QbyRuFL9qbfZA7fBUXbWRxg58O75y Y0zcONqYc1lMfvmjKr0M838/ae0DDkiJXZ0VpJcYnikcsxGsvXymJz4xk+3c5+BVYwHf Hy/Y+PufKcI6gpn8jER++lq/YzUFT+XPz1eeDIrCTr2oKPCd/tnDhVFXQRYkyJLlPI7s yAJcfjOwQY2qFKtNrzQS69UOHLLmxKAgT/jGjGBkGsRhXVmfTn2Y3wmw0CaB2QRqkU/C JmFJ0FK2BGk93+m5PZqQ6bI634ToCmTVZgr/HmSfFwqFSJitJeU3zcf7DqMTt/ZM1KM+ Tacg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709143008; x=1709747808; h=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=bBWDWJvSshoSjEVW3Suakt0O9q+vGDdTpywx5NXn+PM=; b=Wo95nGnJDYvdi/guBoqEBKgLGcyzfgVUUjAQGvs2Za2yziSj0rqwSc//WBBPmWQTOa EnKMaODGkMUDDtc4FFpvknBkFL++WQVHZn5SsbVlpU86GPq9cgywta25W5fJnsWbma1z VAYG9R7HYHMyiXB6RBbYwGRBR7HAbCYfvGapXwgoxQKHYVYUPRGf8CKGdUrjFSdFqqfV PfC/iby8GluB7oCTRapOrnmxXz8jCSWsB8yKLQpl0li5AgEpFaQ7T02cX+bH1DY+SqcM 1qwSMfMtGgiZL0x1XqpfU2KnQu/wRZBbq3I0XdbsWyS9qtdWvMxb2Aq62QfC3nRRMMKa 8eqQ== X-Forwarded-Encrypted: i=1; AJvYcCUHmWlRuOJUg+2ZXNzkPnsy8JAzqUdN3voW1B3bL2X3EddMp6yMuCmq9J0BVFKOxxrNx7fVDp1cZzCX/pv7z7/77jzl7w6spbvABmY3 X-Gm-Message-State: AOJu0Yyw/VPcgwBVPh/38fq9oqe7Bv7jzc03CXxgJLWP9SZcFcw6lOp3 2rLOZQFn3mOfQ3+HDV+S3PTV+cD6YxlTSdic7CifnkUjcM4/p9ixmCuXwt/+B1zDpVfqJ/hJo0Z Jh6OhOQ== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:77dc:144c:334e:e2dd]) (user=irogers job=sendgmr) by 2002:a05:6902:1142:b0:dc7:9218:df47 with SMTP id p2-20020a056902114200b00dc79218df47mr2908ybu.5.1709143007864; Wed, 28 Feb 2024 09:56:47 -0800 (PST) Date: Wed, 28 Feb 2024 09:56:10 -0800 In-Reply-To: <20240228175617.4049201-1-irogers@google.com> Message-Id: <20240228175617.4049201-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240228175617.4049201-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v1 05/12] perf jevents: Support parsing negative exponents From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , John Garry , Kan Liang , Jing Zhang , Thomas Richter , James Clark , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andi Kleen , Kajol Jain , Sandipan Das , Ravi Bangoria , Perry Taylor , Samantha Alt , Caleb Biggers , Weilin Wang , Edward Baker , Stephane Eranian X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792166418302073477 X-GMAIL-MSGID: 1792166418302073477 Support negative exponents when parsing from a json metric string by making the numbers after the 'e' optional in the 'Event' insertion fix up. Signed-off-by: Ian Rogers --- tools/perf/pmu-events/metric.py | 2 +- tools/perf/pmu-events/metric_test.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py index 847b614d40d5..31eea2f45152 100644 --- a/tools/perf/pmu-events/metric.py +++ b/tools/perf/pmu-events/metric.py @@ -573,7 +573,7 @@ def ParsePerfJson(orig: str) -> Expression: # a double by the Bison parser py = re.sub(r'0Event\(r"[xX]([0-9a-fA-F]*)"\)', r'Event("0x\1")', py) # Convert accidentally converted scientific notation constants back - py = re.sub(r'([0-9]+)Event\(r"(e[0-9]+)"\)', r'\1\2', py) + py = re.sub(r'([0-9]+)Event\(r"(e[0-9]*)"\)', r'\1\2', py) # Convert all the known keywords back from events to just the keyword keywords = ['if', 'else', 'min', 'max', 'd_ratio', 'source_count', 'has_event', 'strcmp_cpuid_str'] for kw in keywords: diff --git a/tools/perf/pmu-events/metric_test.py b/tools/perf/pmu-events/metric_test.py index ee22ff43ddd7..8acfe4652b55 100755 --- a/tools/perf/pmu-events/metric_test.py +++ b/tools/perf/pmu-events/metric_test.py @@ -61,6 +61,10 @@ class TestMetricExpressions(unittest.TestCase): after = before self.assertEqual(ParsePerfJson(before).ToPerfJson(), after) + before = r'a + 3e-12 + b' + after = before + self.assertEqual(ParsePerfJson(before).ToPerfJson(), after) + def test_IfElseTests(self): # if-else needs rewriting to Select and back. before = r'Event1 if #smt_on else Event2'