mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-01 06:46:35 +01:00
perf expr: Add has_event function
Some events are dependent on firmware/kernel enablement. Allow such events to be detected when the metric is parsed so that the metric's event parsing doesn't fail. Signed-off-by: Ian Rogers <[email protected]> Tested-by: Namhyung Kim <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Eduard Zingerman <[email protected]> Cc: Sohom Datta <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Caleb Biggers <[email protected]> Cc: Edward Baker <[email protected]> Cc: Perry Taylor <[email protected]> Cc: Samantha Alt <[email protected]> Cc: Weilin Wang <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Jing Zhang <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Kan Liang <[email protected]> Cc: Zhengjun Xing <[email protected]> Cc: John Garry <[email protected]> Cc: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
This commit is contained in:
1 parent
36cee69f57
commit
4a4a9bf907
5 files changed
+34
-1
No files matched your search
@@ -254,6 +254,10 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
|
||||
TEST_ASSERT_VAL("source count", hashmap__size(ctx->ids) == 1);
|
||||
TEST_ASSERT_VAL("source count", hashmap__find(ctx->ids, "EVENT1", &val_ptr));
|
||||
|
||||
/* has_event returns 1 when an event exists. */
|
||||
expr__add_id_val(ctx, strdup("cycles"), 2);
|
||||
ret = test(ctx, "has_event(cycles)", 1);
|
||||
|
||||
expr__ctx_free(ctx);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "cpumap.h"
|
||||
#include "cputopo.h"
|
||||
#include "debug.h"
|
||||
#include "evlist.h"
|
||||
#include "expr.h"
|
||||
#include "expr-bison.h"
|
||||
#include "expr-flex.h"
|
||||
@@ -474,3 +475,23 @@ out:
|
||||
pr_debug2("literal: %s = %f\n", literal, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Does the event 'id' parse? Determine via ctx->ids if possible. */
|
||||
double expr__has_event(const struct expr_parse_ctx *ctx, bool compute_ids, const char *id)
|
||||
{
|
||||
struct evlist *tmp;
|
||||
double ret;
|
||||
|
||||
if (hashmap__find(ctx->ids, id, /*value=*/NULL))
|
||||
return 1.0;
|
||||
|
||||
if (!compute_ids)
|
||||
return 0.0;
|
||||
|
||||
tmp = evlist__new();
|
||||
if (!tmp)
|
||||
return NAN;
|
||||
ret = parse_event(tmp, id) ? 0 : 1;
|
||||
evlist__delete(tmp);
|
||||
return ret;
|
||||
}
|
||||
@@ -54,5 +54,6 @@ int expr__find_ids(const char *expr, const char *one,
|
||||
double expr_id_data__value(const struct expr_id_data *data);
|
||||
double expr_id_data__source_count(const struct expr_id_data *data);
|
||||
double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx);
|
||||
double expr__has_event(const struct expr_parse_ctx *ctx, bool compute_ids, const char *id);
|
||||
|
||||
#endif
|
||||
@@ -113,6 +113,7 @@ min { return MIN; }
|
||||
if { return IF; }
|
||||
else { return ELSE; }
|
||||
source_count { return SOURCE_COUNT; }
|
||||
has_event { return HAS_EVENT; }
|
||||
{literal} { return literal(yyscanner, sctx); }
|
||||
{number} { return value(yyscanner); }
|
||||
{symbol} { return str(yyscanner, ID, sctx->runtime); }
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
} ids;
|
||||
}
|
||||
|
||||
%token ID NUMBER MIN MAX IF ELSE LITERAL D_RATIO SOURCE_COUNT EXPR_ERROR
|
||||
%token ID NUMBER MIN MAX IF ELSE LITERAL D_RATIO SOURCE_COUNT HAS_EVENT EXPR_ERROR
|
||||
%left MIN MAX IF
|
||||
%left '|'
|
||||
%left '^'
|
||||
@@ -199,6 +199,12 @@ expr: NUMBER
|
||||
}
|
||||
| ID { $$ = handle_id(ctx, $1, compute_ids, /*source_count=*/false); }
|
||||
| SOURCE_COUNT '(' ID ')' { $$ = handle_id(ctx, $3, compute_ids, /*source_count=*/true); }
|
||||
| HAS_EVENT '(' ID ')'
|
||||
{
|
||||
$$.val = expr__has_event(ctx, compute_ids, $3);
|
||||
$$.ids = NULL;
|
||||
free($3);
|
||||
}
|
||||
| expr '|' expr
|
||||
{
|
||||
if (is_const($1.val) && is_const($3.val)) {
|
||||
|
||||
Reference in new issue
Block a user