Received: by 2002:ab2:5c0e:0:b0:1ef:a325:1205 with SMTP id i14csp177967lqk; Wed, 13 Mar 2024 22:35:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVGG0q5Ppa64ptudOZ3295zvUZJtK0BZT/w/jUnpoIvZsz+OpqqOJ1WuJG40horLOi2ujN4bly2l0UY23pGEjX8Nwp7Cz4/FrA4Vz7CbQ== X-Google-Smtp-Source: AGHT+IEin4X2AFu5jk15899srZXTHcptGrwbubHmjLlGj1HFo5FqWnpxkHjC1088Tj0MOIL3pFJ7 X-Received: by 2002:a05:6214:508:b0:691:2629:d5d5 with SMTP id px8-20020a056214050800b006912629d5d5mr1014080qvb.56.1710394555648; Wed, 13 Mar 2024 22:35:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710394555; cv=pass; d=google.com; s=arc-20160816; b=tklcPVtQmeaTGeoL9dZPiFKGhLz8ETvBwf7rtt8OOyIEzYMf02KXjAa4rA/K3Erf+9 jADobmqYkywxF16+pWrMkULf7YoLihi09nAhGJyY6P09aBR5RB4qhnN1QYo6bgK8p7RG aRSNZwdnMSJG8AX+l4OwCw86jAhOkMullZEnZfQL8xOWEw0YOVLvfh1fWdDdU7CYE8w3 tGSelvKh30ri13iyttvq1WGm85/ejdIJiVbt1jhNvJY3aWMQIpnQ/wLcBwXCFYOpjB2Z SLtoqUG/bdh9dLoDk59YCFa1JKGQpcE/sN2egjujMAwYIbeTh8d1cJ2AA2B6xXLpSyc6 9zqA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=eRDPxJVTHieOMR3Hi1d1OF7eIKdaIqrR5LQQJbNyQzY=; fh=HNUxJI4PnnClA4RzN2ani8J/AnU4SYjvuSxVwGDkTqE=; b=teLu3PU7/kDdOi1cbf2jL4uBn8hT9/Y7FRMeg9cZRbyl5JBdVkCi5rb0ng32Z/WL4O kflmqoDcv0DQqQAf0Pp/hMlYSIiVuleo9SsTfooRQu/196U1HspHSOZDqRM86A8OW1KV 0S574WbDMlsCDObBEj/ugyWgnXgOxHygRbmttsSo7w+BZlNnJThhKPRSXnpOU/K/bWzm tNaCU+KZ16/LIgZXhDgP8vRVlwJKmOvbcyv3pRhDP+ECgngRUAQ2Rvbst9tVgFBHR1B/ aikaflguSGPF9dLPz1IMtnHeaw87XLTbJK0iFEE3QI/Le3OFQ3wuzQo6EUJ7pLDkBJWp A8WA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Nh+tgZg+; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-102789-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102789-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gw6-20020a0562140f0600b0068f876e6065si829550qvb.207.2024.03.13.22.35.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 22:35:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102789-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Nh+tgZg+; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-102789-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102789-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3A6821C21CE3 for ; Thu, 14 Mar 2024 05:35:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D713FDDC1; Thu, 14 Mar 2024 05:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Nh+tgZg+" Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) (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 72FF58F7A for ; Thu, 14 Mar 2024 05:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710394537; cv=none; b=TGPvQNHj24Xb8ogQ6IqrYhr1g0lhAo3DLGV5EVlndM3VHhQOrNmO9XvMPjG/8HqhFX6DKIUhyissZ4GchZAacB4zxEWvgmFiYalnf6RVL6pjmh9Qjx0sQR6ofReNr9S4NzyrUSc04SsPRsIt/Kfv84MwK/i8M1s/0Qad09fsFX8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710394537; c=relaxed/simple; bh=xy+yihGYgmGmElHluWjV+klBZIrdr8SZjpVJJwUTbRo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=M9BbEztw1ENn2AMj4neWtsh11BTehJhNd7CacZf8vIxWX66LFB64xFzPlttVeAD9TCh+NwriIJ5ON/MEZfYhqeBjdyyhwyow49ORM9OGsbAI80OCoHamvU2eqZHkLnt/t6Y4pV/N2SbpYgt/55inZF0VRH7UHkibvnq5NE+zpJI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Nh+tgZg+; arc=none smtp.client-ip=209.85.166.170 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=google.com Received: by mail-il1-f170.google.com with SMTP id e9e14a558f8ab-36646d1c2b7so44965ab.1 for ; Wed, 13 Mar 2024 22:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710394534; x=1710999334; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=eRDPxJVTHieOMR3Hi1d1OF7eIKdaIqrR5LQQJbNyQzY=; b=Nh+tgZg+lhnywmiFpFav38vo/wDiDXwzTtJHxdkkOeW/7BEeI2t6kWWQPV0UYeKyfP BwiOjCHhWvOGDQoeRMVdUwnUoN1gmA0EIrkrTut6vD6VIaCrEm4R92D2T1YTQV9PgMqa sqLjD1aF9PJgUDBank0O1Vkk+KJb0fSN/QGqkCyHZI36EeSElW+oQi3C+aFfgYFV0ehx E4wYLONf3c84wj6I2FPSaDpC3/vUWL07aoxDdH4u65rSNf8nIohDKsV0t7JGbjTtIlHG Q/LrrS8xIUsBACIbHPXR2EXe1UXxZEaVwaN2POTPYWU1EX9kaA/GFyjx8Obd661HcLZ3 l8gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710394534; x=1710999334; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eRDPxJVTHieOMR3Hi1d1OF7eIKdaIqrR5LQQJbNyQzY=; b=AjGJeHVdAtLrJWgawnad+BWBgVpuEbwSTzceRAAmZ0CEN1uAYF0cGdy05VqAI2JN5K FfReu8fp8z+iFJAV9PVdsEiIjcX3elYUY9GMwRE1lmciDQtwzEcbEscNTSch0tHN3n20 RTyti9HYw1S52LNdXW6EFfOaK2eCT3HmrG9yq+mI+//SQiznRCUOsLMNv9CQChtdUgPS Xp9tZhl6DNov5wYIoseMxB7OWrwVrA3vXyyke4gwzRa4ZQVZl32un8iDyTckNr55539B Lu8qJiRymO/QURn4/enbbhjinnu9fRXEmjdXa86TPczGtXCMbOSjMfeBwUgWEPcyqn2J ryoQ== X-Forwarded-Encrypted: i=1; AJvYcCWi5S0PthzYbjmIk/s4549GQov212UzyylIHgUqLg5tU7+eYrIvXeAV0PT/f9jl4HdQ88ap4HC0oniqwPmlqBghbZ5OnUViD/sI1hBC X-Gm-Message-State: AOJu0YwNPG7jBorr/vjnNMrOXXVHzFbgwZwiH/7w9AER3RFUJQA9csb/ AYL/4rrz5WhIwNj2zNiSPCd13ogx4H93ohygrVFEY24BqZ+RZje0mm8OgtsW/Epzr1C1TMVoL75 Ja6Vn2dgD6HhtzLQ07vkIppIjLtUbh47nY+F5 X-Received: by 2002:a92:ca45:0:b0:366:796e:eb95 with SMTP id q5-20020a92ca45000000b00366796eeb95mr146084ilo.29.1710394534350; Wed, 13 Mar 2024 22:35:34 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240302005950.2847058-1-irogers@google.com> <20240302005950.2847058-6-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Wed, 13 Mar 2024 22:35:20 -0700 Message-ID: Subject: Re: [PATCH v2 05/12] perf jevents: Support parsing negative exponents To: Namhyung Kim Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 5, 2024 at 11:20=E2=80=AFPM Namhyung Kim = wrote: > > On Fri, Mar 1, 2024 at 5:00=E2=80=AFPM Ian Rogers wr= ote: > > > > 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/me= tric.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 =3D re.sub(r'0Event\(r"[xX]([0-9a-fA-F]*)"\)', r'Event("0x\1")', = py) > > # Convert accidentally converted scientific notation constants back > > - py =3D re.sub(r'([0-9]+)Event\(r"(e[0-9]+)"\)', r'\1\2', py) > > + py =3D re.sub(r'([0-9]+)Event\(r"(e[0-9]*)"\)', r'\1\2', py) > > I don't understand how it can handle negative numbers. > Why isn't it like Event\(r"(e-?[0-9]+)"\) ? When something like 3e12 is converted at this point it would be: 3Event("e12") and so this substitution remove the Event and puts it back to: 3e12 but it expects a number with the "e". For a negative exponent like 3e-12 we= get: 3Event("e")-12 and so there's no number and no substitution. Changing the + to a * means the number in the event next to the "e" becomes optional and so we match and remove the Event again. I'm wondering about having this be a bit more of a parser, but then it kind of defeats using Python's eval as being the parser. Thanks, Ian > Thanks, > Namhyung > > > > # Convert all the known keywords back from events to just the keywor= d > > keywords =3D ['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-even= ts/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 =3D before > > self.assertEqual(ParsePerfJson(before).ToPerfJson(), after) > > > > + before =3D r'a + 3e-12 + b' > > + after =3D before > > + self.assertEqual(ParsePerfJson(before).ToPerfJson(), after) > > + > > def test_IfElseTests(self): > > # if-else needs rewriting to Select and back. > > before =3D r'Event1 if #smt_on else Event2' > > -- > > 2.44.0.278.ge034bb2e1d-goog > >