From mboxrd@z Thu Jan 1 00:00:00 1970 From: Arnaldo Carvalho de Melo Subject: Re: [PATCH 1/2] perf expr: Add d_ratio operation Date: Wed, 10 Jun 2020 11:19:49 -0300 Message-ID: <20200610141949.GN24868@kernel.org> References: <20200610051717.170457-1-irogers@google.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline In-Reply-To: <20200610051717.170457-1-irogers@google.com> Sender: linux-kernel-owner@vger.kernel.org To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andi Kleen , Jin Yao , John Garry , Paul Clarke , Kajol Jain , linux-kernel@vger.kernel.org, Stephane Eranian , linux-perf-users@vger.kernel.org List-Id: linux-perf-users.vger.kernel.org Em Tue, Jun 09, 2020 at 10:17:15PM -0700, Ian Rogers escreveu: > This simplifies computing ratios in json expressions. Appling to my local branch, Jiri, can I have your acked-by? - Arnaldo > Signed-off-by: Ian Rogers > --- > tools/perf/util/expr.l | 1 + > tools/perf/util/expr.y | 14 ++++++++++++-- > 2 files changed, 13 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l > index f397bf8b1a48..298d86660a96 100644 > --- a/tools/perf/util/expr.l > +++ b/tools/perf/util/expr.l > @@ -100,6 +100,7 @@ symbol ({spec}|{sym})+ > } > } > > +d_ratio { return D_RATIO; } > max { return MAX; } > min { return MIN; } > if { return IF; } > diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y > index bf3e898e3055..fe145344bb39 100644 > --- a/tools/perf/util/expr.y > +++ b/tools/perf/util/expr.y > @@ -10,6 +10,14 @@ > #include "smt.h" > #include > > +static double d_ratio(double val0, double val1) > +{ > + if (val1 == 0) { > + return 0; > + } > + return val0 / val1; > +} > + > %} > > %define api.pure full > @@ -28,7 +36,7 @@ > %token NUMBER > %token ID > %destructor { free ($$); } > -%token MIN MAX IF ELSE SMT_ON > +%token MIN MAX IF ELSE SMT_ON D_RATIO > %left MIN MAX IF > %left '|' > %left '^' > @@ -64,7 +72,8 @@ other: ID > } > | > MIN | MAX | IF | ELSE | SMT_ON | NUMBER | '|' | '^' | '&' | '-' | '+' | '*' | '/' | '%' | '(' | ')' | ',' > - > +| > +D_RATIO > > all_expr: if_expr { *final_val = $1; } > ; > @@ -105,6 +114,7 @@ expr: NUMBER > | MIN '(' expr ',' expr ')' { $$ = $3 < $5 ? $3 : $5; } > | MAX '(' expr ',' expr ')' { $$ = $3 > $5 ? $3 : $5; } > | SMT_ON { $$ = smt_on() > 0; } > + | D_RATIO '(' expr ',' expr ')' { $$ = d_ratio($3,$5); } > ; > > %% > -- > 2.27.0.278.ge193c7cf3a9-goog > -- - Arnaldo