Re: [PATCH v1 07/22] perf expr: Add #target_cpu literal

From: Namhyung Kim

Date: Mon Nov 03 2025 - 23:56:42 EST


On Fri, Oct 24, 2025 at 10:58:42AM -0700, Ian Rogers wrote:
> For CPU nanoseconds a lot of the stat-shadow metrics use either
> task-clock or cpu-clock, the latter being used when
> target__has_cpu. Add a #target_cpu literal so that json metrics can
> perform the same test.

Do we have documentation for the literals and metric expressions in
general? I think it's getting complex and we should provide one.

Thanks,
Namhyung

>
> Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> ---
> tools/perf/util/expr.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c
> index 7fda0ff89c16..4df56f2b283d 100644
> --- a/tools/perf/util/expr.c
> +++ b/tools/perf/util/expr.c
> @@ -409,6 +409,9 @@ double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx
> } else if (!strcmp("#core_wide", literal)) {
> result = core_wide(ctx->system_wide, ctx->user_requested_cpu_list)
> ? 1.0 : 0.0;
> + } else if (!strcmp("#target_cpu", literal)) {
> + result = (ctx->system_wide || ctx->user_requested_cpu_list)
> + ? 1.0 : 0.0;
> } else {
> pr_err("Unrecognized literal '%s'", literal);
> }
> --
> 2.51.1.821.gb6fe4d2222-goog
>