linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	James Clark <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/2] perf list: Display the PMU name associated with a perf metric in json
Date: Tue, 13 May 2025 17:25:42 -0300	[thread overview]
Message-ID: <aCOqxtOqVHF1XRN_@x1> (raw)
In-Reply-To: <20250512184700.11691-1-irogers@google.com>

On Mon, May 12, 2025 at 11:46:59AM -0700, Ian Rogers wrote:
> The perf stat --cputype option can be used to filter which metrics
> will be applied, for this reason the json metrics have an associated
> PMU. List this PMU name in the perf list output in json mode so that
> tooling may access it.
> 
> An example of the new field is:
> ```
> {
>         "MetricGroup": "Backend",
>         "MetricName": "tma_core_bound",
>         "MetricExpr": "max(0, tma_backend_bound - tma_memory_bound)",
>         "MetricThreshold": "tma_core_bound > 0.1 & tma_backend_bound > 0.2",
>         "ScaleUnit": "100%",
>         "BriefDescription": "This metric represents fraction of slots where ...
>         "PublicDescription": "This metric represents fraction of slots where ...
>         "Unit": "cpu_core"
> },
> ```

Tried testing this but the Intel system I have (14700k) while hybrid
doesn't have this "unit"  field in its JSON files :-)

Anyway, applying the patches.

- Arnaldo
 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/builtin-list.c      | 12 ++++++++++--
>  tools/perf/util/metricgroup.c  |  5 ++++-
>  tools/perf/util/print-events.h |  3 ++-
>  3 files changed, 16 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c
> index fed482adb039..e9b595d75df2 100644
> --- a/tools/perf/builtin-list.c
> +++ b/tools/perf/builtin-list.c
> @@ -197,7 +197,8 @@ static void default_print_metric(void *ps,
>  				const char *long_desc,
>  				const char *expr,
>  				const char *threshold,
> -				const char *unit __maybe_unused)
> +				const char *unit __maybe_unused,
> +				const char *pmu_name __maybe_unused)
>  {
>  	struct print_state *print_state = ps;
>  	FILE *fp = print_state->fp;
> @@ -433,7 +434,8 @@ static void json_print_event(void *ps, const char *topic, const char *pmu_name,
>  static void json_print_metric(void *ps __maybe_unused, const char *group,
>  			      const char *name, const char *desc,
>  			      const char *long_desc, const char *expr,
> -			      const char *threshold, const char *unit)
> +			      const char *threshold, const char *unit,
> +			      const char *pmu_name)
>  {
>  	struct json_print_state *print_state = ps;
>  	bool need_sep = false;
> @@ -483,6 +485,12 @@ static void json_print_metric(void *ps __maybe_unused, const char *group,
>  				   long_desc);
>  		need_sep = true;
>  	}
> +	if (pmu_name) {
> +		fix_escape_fprintf(fp, &buf, "%s\t\"Unit\": \"%S\"",
> +				   need_sep ? ",\n" : "",
> +				   pmu_name);
> +		need_sep = true;
> +	}
>  	fprintf(fp, "%s}", need_sep ? "\n" : "");
>  	strbuf_release(&buf);
>  }
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index 126a631686b0..43d35f956a33 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -396,6 +396,7 @@ struct mep {
>  	const char *metric_expr;
>  	const char *metric_threshold;
>  	const char *metric_unit;
> +	const char *pmu_name;
>  };
>  
>  static int mep_cmp(struct rb_node *rb_node, const void *entry)
> @@ -476,6 +477,7 @@ static int metricgroup__add_to_mep_groups(const struct pmu_metric *pm,
>  			me->metric_expr = pm->metric_expr;
>  			me->metric_threshold = pm->metric_threshold;
>  			me->metric_unit = pm->unit;
> +			me->pmu_name = pm->pmu;
>  		}
>  	}
>  	free(omg);
> @@ -551,7 +553,8 @@ void metricgroup__print(const struct print_callbacks *print_cb, void *print_stat
>  				me->metric_long_desc,
>  				me->metric_expr,
>  				me->metric_threshold,
> -				me->metric_unit);
> +				me->metric_unit,
> +				me->pmu_name);
>  		next = rb_next(node);
>  		rblist__remove_node(&groups, node);
>  	}
> diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h
> index 445efa1636c1..8f19c2bea64a 100644
> --- a/tools/perf/util/print-events.h
> +++ b/tools/perf/util/print-events.h
> @@ -25,7 +25,8 @@ struct print_callbacks {
>  			const char *long_desc,
>  			const char *expr,
>  			const char *threshold,
> -			const char *unit);
> +			const char *unit,
> +			const char *pmu_name);
>  	bool (*skip_duplicate_pmus)(void *print_state);
>  };
>  
> -- 
> 2.49.0.1045.g170613ef41-goog

      parent reply	other threads:[~2025-05-13 20:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12 18:46 [PATCH v1 1/2] perf list: Display the PMU name associated with a perf metric in json Ian Rogers
2025-05-12 18:47 ` [PATCH v1 2/2] perf test: Hybrid improvements for metric value validation test Ian Rogers
2025-05-12 20:30   ` Falcon, Thomas
2025-05-12 21:52     ` Ian Rogers
2025-05-13 17:26       ` Ian Rogers
2025-05-13 19:07         ` Ian Rogers
2025-05-13 20:25 ` Arnaldo Carvalho de Melo [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aCOqxtOqVHF1XRN_@x1 \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=weilin.wang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).