Skip to contentSkip to conversation

perf expr: Add d_ratio operation

PATCH Superseded Ian Rogers 3 participants 7 messages Jun 10, 2020 – Jun 11, 2020 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/2 perf expr: Add d_ratio operation

This simplifies computing ratios in json expressions.

---
 tools/perf/util/expr.l |  1 +
 tools/perf/util/expr.y | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
tools/perf/util/expr.l +1 -0
index f397bf8b1a48..298d86660a96 100644
@@ -100,6 +100,7 @@ symbol		({spec}|{sym})+
 		}
 	}
 
+d_ratio		{ return D_RATIO; }
 max		{ return MAX; }
 min		{ return MIN; }
 if		{ return IF; }
tools/perf/util/expr.y +12 -2
index bf3e898e3055..fe145344bb39 100644
@@ -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); }
 	;
 
 %%
Signature · 1 line
2.27.0.278.ge193c7cf3a9-goog
author reviewer
#1 lore raw

PATCH 2/2 perf expr: Add < and > operators

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

---
 tools/perf/util/expr.l | 2 ++
 tools/perf/util/expr.y | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/expr.l +2 -0
index 298d86660a96..13e5e3c75f56 100644
@@ -111,6 +111,8 @@ else		{ return ELSE; }
 "|"		{ return '|'; }
 "^"		{ return '^'; }
 "&"		{ return '&'; }
+"<"		{ return '<'; }
+">"		{ return '>'; }
 "-"		{ return '-'; }
 "+"		{ return '+'; }
 "*"		{ return '*'; }
tools/perf/util/expr.y +4 -1
index fe145344bb39..5fcb98800f9c 100644
@@ -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; }
Signature · 1 line
2.27.0.278.ge193c7cf3a9-goog
#2 lore raw

Re: [PATCH 2/2] perf expr: Add < and > operators

Em Tue, Jun 09, 2020 at 10:17:16PM -0700, Ian Rogers escreveu:

Quoted 1 line

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

Ditto.

- Arnaldo

Quoted 52 lines
---
 tools/perf/util/expr.l | 2 ++
 tools/perf/util/expr.y | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/perf/util/expr.l +2 -0
index 298d86660a96..13e5e3c75f56 100644
@@ -111,6 +111,8 @@ else		{ return ELSE; }
 "|"		{ return '|'; }
 "^"		{ return '^'; }
 "&"		{ return '&'; }
+"<"		{ return '<'; }
+">"		{ return '>'; }
 "-"		{ return '-'; }
 "+"		{ return '+'; }
 "*"		{ return '*'; }
tools/perf/util/expr.y +4 -1
index fe145344bb39..5fcb98800f9c 100644
@@ -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; }
Signature · 1 line
2.27.0.278.ge193c7cf3a9-goog
Signature · 1 line
- Arnaldo
#3 lore raw
In reply to Ian Rogers

Em Tue, Jun 09, 2020 at 10:17:15PM -0700, Ian Rogers escreveu:

Quoted 1 line

This simplifies computing ratios in json expressions.

Appling to my local branch, Jiri, can I have your acked-by?

- Arnaldo

Quoted 67 lines
---
 tools/perf/util/expr.l |  1 +
 tools/perf/util/expr.y | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
tools/perf/util/expr.l +1 -0
index f397bf8b1a48..298d86660a96 100644
@@ -100,6 +100,7 @@ symbol		({spec}|{sym})+
 		}
 	}
 
+d_ratio		{ return D_RATIO; }
 max		{ return MAX; }
 min		{ return MIN; }
 if		{ return IF; }
tools/perf/util/expr.y +12 -2
index bf3e898e3055..fe145344bb39 100644
@@ -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); }
 	;
 
 %%
Signature · 1 line
2.27.0.278.ge193c7cf3a9-goog
Signature · 1 line
- Arnaldo
#4 lore raw
In reply to Ian Rogers
Quoted 1 line · Ian Rogers

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

Quoted 68 lines
---
 tools/perf/util/expr.l |  1 +
 tools/perf/util/expr.y | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
tools/perf/util/expr.l +1 -0
index f397bf8b1a48..298d86660a96 100644
@@ -100,6 +100,7 @@ symbol		({spec}|{sym})+
 		}
 	}
 
+d_ratio		{ return D_RATIO; }
 max		{ return MAX; }
 min		{ return MIN; }
 if		{ return IF; }
tools/perf/util/expr.y +12 -2
index bf3e898e3055..fe145344bb39 100644
@@ -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); }
 	;
 
 %%
Signature · 1 line
2.27.0.278.ge193c7cf3a9-goog
#5 lore raw

Em Wed, Jun 10, 2020 at 05:41:29PM +0200, Jiri Olsa escreveu:

Quoted 11 lines · Ian Rogers
Quoted 1 line

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

Quoted 72 lines

thanks,
jirka

Quoted 68 lines
---
 tools/perf/util/expr.l |  1 +
 tools/perf/util/expr.y | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
tools/perf/util/expr.l +1 -0
index f397bf8b1a48..298d86660a96 100644
@@ -100,6 +100,7 @@ symbol		({spec}|{sym})+
 		}
 	}
 
+d_ratio		{ return D_RATIO; }
 max		{ return MAX; }
 min		{ return MIN; }
 if		{ return IF; }
tools/perf/util/expr.y +12 -2
index bf3e898e3055..fe145344bb39 100644
@@ -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); }
 	;
 
 %%
Signature · 1 line
2.27.0.278.ge193c7cf3a9-goog
Signature · 1 line
- Arnaldo
author reviewer
#6 lore raw
Quoted 8 lines · Arnaldo Carvalho de Melo

Em Wed, Jun 10, 2020 at 05:41:29PM +0200, Jiri Olsa escreveu:

Quoted 6 lines · Ian Rogers
Quoted 1 line

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

Quoted 7 lines
Quoted 5 lines

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/[email protected]/T/#t

Thanks,
Ian

Quoted 78 lines

- Arnaldo

Quoted 67 lines

thanks,
jirka

Quoted 64 lines
---
 tools/perf/util/expr.l |  1 +
 tools/perf/util/expr.y | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)
tools/perf/util/expr.l +1 -0
index f397bf8b1a48..298d86660a96 100644
@@ -100,6 +100,7 @@ symbol          ({spec}|{sym})+
            }
    }
 
+d_ratio            { return D_RATIO; }
 max                { return MAX; }
 min                { return MIN; }
 if         { return IF; }
tools/perf/util/expr.y +12 -2
index bf3e898e3055..fe145344bb39 100644
@@ -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); }
    ;
 
Quoted 5 lines
Quoted 4 lines
tools/perf/util/expr.y +0 -1
 %%
--

2.27.0.278.ge193c7cf3a9-goog

--

- Arnaldo