From 94886961e324d5b6bae8e206b227c6eeb0f22c2c Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Thu, 23 Sep 2021 00:46:16 -0700 Subject: perf metric: Avoid events for an 'if' constant result For a metric like: CONST if expr else CONST if the values of CONST are identical then expr doesn't need evaluating, and events, in order to compute a result. Signed-off-by: Ian Rogers Tested-by: John Garry Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Andi Kleen Cc: Ingo Molnar Cc: Jin Yao Cc: Kajol Jain Cc: Mark Rutland Cc: Namhyung Kim Cc: Paul Clarke Cc: Peter Zijlstra Cc: Sandeep Dasgupta Cc: Stephane Eranian Link: https://lore.kernel.org/r/20210923074616.674826-14-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/expr.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tools/perf/tests/expr.c') diff --git a/tools/perf/tests/expr.c b/tools/perf/tests/expr.c index 287989321d2a..f1d8411fce12 100644 --- a/tools/perf/tests/expr.c +++ b/tools/perf/tests/expr.c @@ -143,6 +143,13 @@ int test__expr(struct test *t __maybe_unused, int subtest __maybe_unused) smt_on() ? "EVENT1" : "EVENT2", (void **)&val_ptr)); + /* The expression is a constant 1.0 without needing to evaluate EVENT1. */ + expr__ctx_clear(ctx); + TEST_ASSERT_VAL("find ids", + expr__find_ids("1.0 if EVENT1 > 100.0 else 1.0", + NULL, ctx, 0) == 0); + TEST_ASSERT_VAL("find ids", hashmap__size(ctx->ids) == 0); + expr__ctx_free(ctx); return 0; -- cgit v1.2.3