linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: John Garry <john.g.garry@oracle.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Sumanth Korikkar <sumanthk@linux.ibm.com>,
	Thomas Richter <tmricht@linux.ibm.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH v4] perf jevents: Parse metrics during conversion
Date: Mon, 12 Dec 2022 12:46:06 -0300	[thread overview]
Message-ID: <Y5dMvhMd7kbkAUyY@kernel.org> (raw)
In-Reply-To: <CAP-5=fWa=zNK_ecpWGoGggHCQx7z-oW0eGMQf19Maywg0QK=4g@mail.gmail.com>

Em Thu, Dec 08, 2022 at 09:41:55AM -0800, Ian Rogers escreveu:
> Apologies, I found an issue with a double-if. Could you add the 1 line
> fix plus test:

Had to apply manually, the patch was munged, end result should be the
same:


diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py
index cc451a26575185f4..4797ed4fd817b1a0 100644
--- a/tools/perf/pmu-events/metric.py
+++ b/tools/perf/pmu-events/metric.py
@@ -462,6 +462,7 @@ class _RewriteIfExpToSelect(ast.NodeTransformer):
 
   def visit_IfExp(self, node):
     # pylint: disable=invalid-name
+    self.generic_visit(node)
     call = ast.Call(
         func=ast.Name(id='Select', ctx=ast.Load()),
         args=[node.body, node.test, node.orelse],
diff --git a/tools/perf/pmu-events/metric_test.py b/tools/perf/pmu-events/metric_test.py
index 4741b7b6612dc268..15315d0f716caf4e 100644
--- a/tools/perf/pmu-events/metric_test.py
+++ b/tools/perf/pmu-events/metric_test.py
@@ -87,6 +87,10 @@ class TestMetricExpressions(unittest.TestCase):
     after = r'min((a + b if c > 1 else c + d), e + f)'
     self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
 
+    before =3D r'a if b else c if d else e'
+    after =3D r'(a if b else (c if d else e))'
+    self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
+
   def test_ToPython(self):
     # pylint: disable=eval-used
     # Based on an example of a real metric.
 
> diff --git a/tools/perf/pmu-events/metric.py b/tools/perf/pmu-events/metric.py
> index cc451a265751..4797ed4fd817 100644
> --- a/tools/perf/pmu-events/metric.py
> +++ b/tools/perf/pmu-events/metric.py
> @@ -462,6 +462,7 @@ class _RewriteIfExpToSelect(ast.NodeTransformer):
> 
>   def visit_IfExp(self, node):
>     # pylint: disable=invalid-name
> +    self.generic_visit(node)
>     call = ast.Call(
>         func=ast.Name(id='Select', ctx=ast.Load()),
>         args=[node.body, node.test, node.orelse],
> diff --git a/tools/perf/pmu-events/metric_test.py
> b/tools/perf/pmu-events/metric_test.py
> index 4741b7b6612d..6980f452df0a 100644
> --- a/tools/perf/pmu-events/metric_test.py
> +++ b/tools/perf/pmu-events/metric_test.py
> @@ -87,6 +87,10 @@ class TestMetricExpressions(unittest.TestCase):
>     after = r'min((a + b if c > 1 else c + d), e + f)'
>     self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
> 
> +    before = r'a if b else c if d else e'
> +    after = r'(a if b else (c if d else e))'
> +    self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
> +
>   def test_ToPython(self):
>     # pylint: disable=eval-used
>     # Based on an example of a real metric.
> 
> Thanks,
> Ian
> 
> On Wed, Dec 7, 2022 at 9:47 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> >
> > Em Wed, Dec 07, 2022 at 05:42:52PM +0000, John Garry escreveu:
> > > On 07/12/2022 17:40, Arnaldo Carvalho de Melo wrote:
> > > > Em Tue, Dec 06, 2022 at 09:59:08PM -0800, Ian Rogers escreveu:
> > > > > Currently the 'MetricExpr' json value is passed from the json
> > > > > file to the pmu-events.c. This change introduces an expression
> > > > > tree that is parsed into. The parsing is done largely by using
> > > > > operator overloading and python's 'eval' function. Two advantages
> > > > > in doing this are:
> > > > John, what tag can I get from you? 😄
> > > >
> > > > - Arnaldo
> > > Sure,
> > > Reviewed-by: John Garry <john.g.garry@oracle.com>
> >
> > Thanks a lot!
> >
> > - Arnaldo

-- 

- Arnaldo

      reply	other threads:[~2022-12-12 15:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07  5:59 [PATCH v4] perf jevents: Parse metrics during conversion Ian Rogers
2022-12-07  6:10 ` Ian Rogers
2022-12-07 13:11   ` Arnaldo Carvalho de Melo
2022-12-07 17:40 ` Arnaldo Carvalho de Melo
2022-12-07 17:42   ` John Garry
2022-12-07 17:46     ` Arnaldo Carvalho de Melo
2022-12-08 17:41       ` Ian Rogers
2022-12-12 15:46         ` Arnaldo Carvalho de Melo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y5dMvhMd7kbkAUyY@kernel.org \
    --to=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=john.g.garry@oracle.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sumanthk@linux.ibm.com \
    --cc=tmricht@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).