linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf expr: Add d_ratio operation
@ 2020-06-10  5:17 Ian Rogers
  2020-06-10  5:17 ` [PATCH 2/2] perf expr: Add < and > operators Ian Rogers
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ian Rogers @ 2020-06-10  5:17 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Andi Kleen, Jin Yao, John Garry, Paul Clarke, Kajol Jain,
	linux-kernel
  Cc: Stephane Eranian, linux-perf-users, Ian Rogers

This simplifies computing ratios in json expressions.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 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 <string.h>
 
+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 <num> NUMBER
 %token <str> ID
 %destructor { free ($$); } <str>
-%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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] perf expr: Add < and > operators
  2020-06-10  5:17 [PATCH 1/2] perf expr: Add d_ratio operation Ian Rogers
@ 2020-06-10  5:17 ` Ian Rogers
  2020-06-10 14:21   ` Arnaldo Carvalho de Melo
  2020-06-10 14:19 ` [PATCH 1/2] perf expr: Add d_ratio operation Arnaldo Carvalho de Melo
  2020-06-10 15:41 ` Jiri Olsa
  2 siblings, 1 reply; 7+ messages in thread
From: Ian Rogers @ 2020-06-10  5:17 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Andi Kleen, Jin Yao, John Garry, Paul Clarke, Kajol Jain,
	linux-kernel
  Cc: Stephane Eranian, linux-perf-users, Ian Rogers

These are broadly useful and necessary for Intel's top-down analysis.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/expr.l | 2 ++
 tools/perf/util/expr.y | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l
index 298d86660a96..13e5e3c75f56 100644
--- a/tools/perf/util/expr.l
+++ b/tools/perf/util/expr.l
@@ -111,6 +111,8 @@ else		{ return ELSE; }
 "|"		{ return '|'; }
 "^"		{ return '^'; }
 "&"		{ return '&'; }
+"<"		{ return '<'; }
+">"		{ return '>'; }
 "-"		{ return '-'; }
 "+"		{ return '+'; }
 "*"		{ return '*'; }
diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y
index fe145344bb39..5fcb98800f9c 100644
--- a/tools/perf/util/expr.y
+++ b/tools/perf/util/expr.y
@@ -41,6 +41,7 @@ static double d_ratio(double val0, double val1)
 %left '|'
 %left '^'
 %left '&'
+%left '<' '>'
 %left '-' '+'
 %left '*' '/' '%'
 %left NEG NOT
@@ -73,7 +74,7 @@ other: ID
 |
 MIN | MAX | IF | ELSE | SMT_ON | NUMBER | '|' | '^' | '&' | '-' | '+' | '*' | '/' | '%' | '(' | ')' | ','
 |
-D_RATIO
+'<' | '>' | D_RATIO
 
 all_expr: if_expr			{ *final_val = $1; }
 	;
@@ -94,6 +95,8 @@ expr:	  NUMBER
 	| expr '|' expr		{ $$ = (long)$1 | (long)$3; }
 	| expr '&' expr		{ $$ = (long)$1 & (long)$3; }
 	| expr '^' expr		{ $$ = (long)$1 ^ (long)$3; }
+	| expr '<' expr		{ $$ = $1 < $3; }
+	| expr '>' expr		{ $$ = $1 > $3; }
 	| expr '+' expr		{ $$ = $1 + $3; }
 	| expr '-' expr		{ $$ = $1 - $3; }
 	| expr '*' expr		{ $$ = $1 * $3; }
-- 
2.27.0.278.ge193c7cf3a9-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] perf expr: Add d_ratio operation
  2020-06-10  5:17 [PATCH 1/2] perf expr: Add d_ratio operation Ian Rogers
  2020-06-10  5:17 ` [PATCH 2/2] perf expr: Add < and > operators Ian Rogers
@ 2020-06-10 14:19 ` Arnaldo Carvalho de Melo
  2020-06-10 15:41 ` Jiri Olsa
  2 siblings, 0 replies; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-06-10 14:19 UTC (permalink / raw)
  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, Stephane Eranian,
	linux-perf-users

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 <irogers@google.com>
> ---
>  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 <string.h>
>  
> +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 <num> NUMBER
>  %token <str> ID
>  %destructor { free ($$); } <str>
> -%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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] perf expr: Add < and > operators
  2020-06-10  5:17 ` [PATCH 2/2] perf expr: Add < and > operators Ian Rogers
@ 2020-06-10 14:21   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-06-10 14:21 UTC (permalink / raw)
  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, Stephane Eranian,
	linux-perf-users

Em Tue, Jun 09, 2020 at 10:17:16PM -0700, Ian Rogers escreveu:
> These are broadly useful and necessary for Intel's top-down analysis.

Ditto.

- Arnaldo
 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/util/expr.l | 2 ++
>  tools/perf/util/expr.y | 5 ++++-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/expr.l b/tools/perf/util/expr.l
> index 298d86660a96..13e5e3c75f56 100644
> --- a/tools/perf/util/expr.l
> +++ b/tools/perf/util/expr.l
> @@ -111,6 +111,8 @@ else		{ return ELSE; }
>  "|"		{ return '|'; }
>  "^"		{ return '^'; }
>  "&"		{ return '&'; }
> +"<"		{ return '<'; }
> +">"		{ return '>'; }
>  "-"		{ return '-'; }
>  "+"		{ return '+'; }
>  "*"		{ return '*'; }
> diff --git a/tools/perf/util/expr.y b/tools/perf/util/expr.y
> index fe145344bb39..5fcb98800f9c 100644
> --- a/tools/perf/util/expr.y
> +++ b/tools/perf/util/expr.y
> @@ -41,6 +41,7 @@ static double d_ratio(double val0, double val1)
>  %left '|'
>  %left '^'
>  %left '&'
> +%left '<' '>'
>  %left '-' '+'
>  %left '*' '/' '%'
>  %left NEG NOT
> @@ -73,7 +74,7 @@ other: ID
>  |
>  MIN | MAX | IF | ELSE | SMT_ON | NUMBER | '|' | '^' | '&' | '-' | '+' | '*' | '/' | '%' | '(' | ')' | ','
>  |
> -D_RATIO
> +'<' | '>' | D_RATIO
>  
>  all_expr: if_expr			{ *final_val = $1; }
>  	;
> @@ -94,6 +95,8 @@ expr:	  NUMBER
>  	| expr '|' expr		{ $$ = (long)$1 | (long)$3; }
>  	| expr '&' expr		{ $$ = (long)$1 & (long)$3; }
>  	| expr '^' expr		{ $$ = (long)$1 ^ (long)$3; }
> +	| expr '<' expr		{ $$ = $1 < $3; }
> +	| expr '>' expr		{ $$ = $1 > $3; }
>  	| expr '+' expr		{ $$ = $1 + $3; }
>  	| expr '-' expr		{ $$ = $1 - $3; }
>  	| expr '*' expr		{ $$ = $1 * $3; }
> -- 
> 2.27.0.278.ge193c7cf3a9-goog
> 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] perf expr: Add d_ratio operation
  2020-06-10  5:17 [PATCH 1/2] perf expr: Add d_ratio operation Ian Rogers
  2020-06-10  5:17 ` [PATCH 2/2] perf expr: Add < and > operators Ian Rogers
  2020-06-10 14:19 ` [PATCH 1/2] perf expr: Add d_ratio operation Arnaldo Carvalho de Melo
@ 2020-06-10 15:41 ` Jiri Olsa
  2020-06-10 16:43   ` Arnaldo Carvalho de Melo
  2 siblings, 1 reply; 7+ messages in thread
From: Jiri Olsa @ 2020-06-10 15:41 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Namhyung Kim, Andi Kleen,
	Jin Yao, John Garry, Paul Clarke, Kajol Jain, linux-kernel,
	Stephane Eranian, linux-perf-users

On Tue, Jun 09, 2020 at 10:17:15PM -0700, Ian Rogers wrote:
> This simplifies computing ratios in json expressions.

please put in the comment some usage example and add
a test for this to tests/expr.c

same for the '<>' operators in the other patch

I'll put documentation on this together with the rest to
stat man page with my other changes, so no need to document
this, but at least bit more details in changelog ;-)

thanks,
jirka

> 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  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 <string.h>
>  
> +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 <num> NUMBER
>  %token <str> ID
>  %destructor { free ($$); } <str>
> -%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
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] perf expr: Add d_ratio operation
  2020-06-10 15:41 ` Jiri Olsa
@ 2020-06-10 16:43   ` Arnaldo Carvalho de Melo
  2020-06-11  0:00     ` Ian Rogers
  0 siblings, 1 reply; 7+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-06-10 16:43 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Namhyung Kim, Andi Kleen, Jin Yao,
	John Garry, Paul Clarke, Kajol Jain, linux-kernel,
	Stephane Eranian, linux-perf-users

Em Wed, Jun 10, 2020 at 05:41:29PM +0200, Jiri Olsa escreveu:
> On Tue, Jun 09, 2020 at 10:17:15PM -0700, Ian Rogers wrote:
> > This simplifies computing ratios in json expressions.
> 
> please put in the comment some usage example and add
> a test for this to tests/expr.c
> 
> same for the '<>' operators in the other patch
> 
> I'll put documentation on this together with the rest to
> stat man page with my other changes, so no need to document
> this, but at least bit more details in changelog ;-)

Removed those from my local branch, pushed what I have to tmp.perf/core

- Arnaldo
 
> thanks,
> jirka
> 
> > 
> > Signed-off-by: Ian Rogers <irogers@google.com>
> > ---
> >  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 <string.h>
> >  
> > +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 <num> NUMBER
> >  %token <str> ID
> >  %destructor { free ($$); } <str>
> > -%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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] perf expr: Add d_ratio operation
  2020-06-10 16:43   ` Arnaldo Carvalho de Melo
@ 2020-06-11  0:00     ` Ian Rogers
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Rogers @ 2020-06-11  0:00 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Namhyung Kim, Andi Kleen, Jin Yao,
	John Garry, Paul Clarke, Kajol Jain, LKML, Stephane Eranian,
	linux-perf-users

On Wed, Jun 10, 2020 at 9:43 AM Arnaldo Carvalho de Melo
<acme@kernel.org> wrote:
>
> Em Wed, Jun 10, 2020 at 05:41:29PM +0200, Jiri Olsa escreveu:
> > On Tue, Jun 09, 2020 at 10:17:15PM -0700, Ian Rogers wrote:
> > > This simplifies computing ratios in json expressions.
> >
> > please put in the comment some usage example and add
> > a test for this to tests/expr.c
> >
> > same for the '<>' operators in the other patch
> >
> > I'll put documentation on this together with the rest to
> > stat man page with my other changes, so no need to document
> > this, but at least bit more details in changelog ;-)
>
> Removed those from my local branch, pushed what I have to tmp.perf/core

These should be addressed in v2:
https://lore.kernel.org/lkml/20200610235823.52557-1-irogers@google.com/T/#t

Thanks,
Ian

> - Arnaldo
>
> > thanks,
> > jirka
> >
> > >
> > > Signed-off-by: Ian Rogers <irogers@google.com>
> > > ---
> > >  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 <string.h>
> > >
> > > +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 <num> NUMBER
> > >  %token <str> ID
> > >  %destructor { free ($$); } <str>
> > > -%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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-06-11  0:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-10  5:17 [PATCH 1/2] perf expr: Add d_ratio operation Ian Rogers
2020-06-10  5:17 ` [PATCH 2/2] perf expr: Add < and > operators Ian Rogers
2020-06-10 14:21   ` Arnaldo Carvalho de Melo
2020-06-10 14:19 ` [PATCH 1/2] perf expr: Add d_ratio operation Arnaldo Carvalho de Melo
2020-06-10 15:41 ` Jiri Olsa
2020-06-10 16:43   ` Arnaldo Carvalho de Melo
2020-06-11  0:00     ` Ian Rogers

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).