perf expr: Add d_ratio operation
Ian Rogers
reviewerPATCH 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
@@ -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
@@ -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
Ian Rogers
reviewerPATCH 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
@@ -111,6 +111,8 @@ else { return ELSE; } "|" { return '|'; } "^" { return '^'; } "&" { return '&'; } +"<" { return '<'; } +">" { return '>'; } "-" { return '-'; } "+" { return '+'; } "*" { return '*'; }
tools/perf/util/expr.y +4 -1
@@ -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
Arnaldo Carvalho de Melo
maintainerRe: [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
Signed-off-by Ian Rogers <[email protected]>--- 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@@ -111,6 +111,8 @@ else { return ELSE; } "|" { return '|'; } "^" { return '^'; } "&" { return '&'; } +"<" { return '<'; } +">" { return '>'; } "-" { return '-'; } "+" { return '+'; } "*" { return '*'; }tools/perf/util/expr.y +4
-1@@ -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
Arnaldo Carvalho de Melo
maintainerEm 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
Signed-off-by Ian Rogers <[email protected]>--- 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@@ -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@@ -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
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
Signed-off-by Ian Rogers <[email protected]>--- 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@@ -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@@ -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
Arnaldo Carvalho de Melo
maintainerEm 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.csame 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,
jirkaQuoted 68 lines
Signed-off-by Ian Rogers <[email protected]>--- 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@@ -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@@ -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
Ian Rogers
reviewerQuoted 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,
jirkaQuoted 64 lines
Signed-off-by Ian Rogers <[email protected]>--- 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@@ -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@@ -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