提交 3e21a28a 编写于 作者: I Ian Rogers 提交者: Arnaldo Carvalho de Melo

perf expr: Add d_ratio operation

d_ratio avoids division by 0 yielding infinity, such as when a counter
doesn't get scheduled. An example usage is:

  {
      "BriefDescription": "DCache L1 misses",
      "MetricExpr": "d_ratio(MEM_LOAD_RETIRED.L1_MISS, MEM_LOAD_RETIRED.L1_HIT + MEM_LOAD_RETIRED.L1_MISS + MEM_LOAD_RETIRED.FB_HIT)",
      "MetricGroup": "DCache;DCache_L1",
      "MetricName": "DCache_L1_Miss",
      "ScaleUnit": "100%",
  }
Signed-off-by: NIan Rogers <irogers@google.com>
Acked-by: NJiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200610235823.52557-1-irogers@google.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 afdd63f5
...@@ -39,6 +39,8 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused) ...@@ -39,6 +39,8 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused)
ret |= test(&ctx, "1+1 if 3*4 else 0", 2); ret |= test(&ctx, "1+1 if 3*4 else 0", 2);
ret |= test(&ctx, "1.1 + 2.1", 3.2); ret |= test(&ctx, "1.1 + 2.1", 3.2);
ret |= test(&ctx, ".1 + 2.", 2.1); ret |= test(&ctx, ".1 + 2.", 2.1);
ret |= test(&ctx, "d_ratio(1, 2)", 0.5);
ret |= test(&ctx, "d_ratio(2.5, 0)", 0);
if (ret) if (ret)
return ret; return ret;
......
...@@ -100,6 +100,7 @@ symbol ({spec}|{sym})+ ...@@ -100,6 +100,7 @@ symbol ({spec}|{sym})+
} }
} }
d_ratio { return D_RATIO; }
max { return MAX; } max { return MAX; }
min { return MIN; } min { return MIN; }
if { return IF; } if { return IF; }
......
...@@ -10,6 +10,14 @@ ...@@ -10,6 +10,14 @@
#include "smt.h" #include "smt.h"
#include <string.h> #include <string.h>
static double d_ratio(double val0, double val1)
{
if (val1 == 0) {
return 0;
}
return val0 / val1;
}
%} %}
%define api.pure full %define api.pure full
...@@ -28,7 +36,7 @@ ...@@ -28,7 +36,7 @@
%token <num> NUMBER %token <num> NUMBER
%token <str> ID %token <str> ID
%destructor { free ($$); } <str> %destructor { free ($$); } <str>
%token MIN MAX IF ELSE SMT_ON %token MIN MAX IF ELSE SMT_ON D_RATIO
%left MIN MAX IF %left MIN MAX IF
%left '|' %left '|'
%left '^' %left '^'
...@@ -64,7 +72,8 @@ other: ID ...@@ -64,7 +72,8 @@ other: ID
} }
| |
MIN | MAX | IF | ELSE | SMT_ON | NUMBER | '|' | '^' | '&' | '-' | '+' | '*' | '/' | '%' | '(' | ')' | ',' MIN | MAX | IF | ELSE | SMT_ON | NUMBER | '|' | '^' | '&' | '-' | '+' | '*' | '/' | '%' | '(' | ')' | ','
|
D_RATIO
all_expr: if_expr { *final_val = $1; } all_expr: if_expr { *final_val = $1; }
; ;
...@@ -105,6 +114,7 @@ expr: NUMBER ...@@ -105,6 +114,7 @@ expr: NUMBER
| MIN '(' expr ',' expr ')' { $$ = $3 < $5 ? $3 : $5; } | MIN '(' expr ',' expr ')' { $$ = $3 < $5 ? $3 : $5; }
| MAX '(' expr ',' expr ')' { $$ = $3 > $5 ? $3 : $5; } | MAX '(' expr ',' expr ')' { $$ = $3 > $5 ? $3 : $5; }
| SMT_ON { $$ = smt_on() > 0; } | SMT_ON { $$ = smt_on() > 0; }
| D_RATIO '(' expr ',' expr ')' { $$ = d_ratio($3,$5); }
; ;
%% %%
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册