Linux Perf Users
 help / color / mirror / Atom feed
From: Nazar Kazakov <nazar.kazakov@codethink.co.uk>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	James Clark <james.clark@linaro.org>,
	Sandipan Das <sandipan.das@amd.com>,
	Chun-Tse Shao <ctshao@google.com>,
	John Garry <john.g.garry@oracle.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/3] perf jevents: Add more components to the metric sorting order
Date: Wed, 15 Jul 2026 12:22:03 +0100	[thread overview]
Message-ID: <0cb89290ad307e4c1d020997a24a9662@codethink.co.uk> (raw)
In-Reply-To: <20260707034019.241762-2-irogers@google.com>

On 2026-07-07 04:40, Ian Rogers wrote:
> Nazar Kazakov reported non-deterministic builds due to the metrics
> being reordered in the jevents.py output. The metrics were largely
> only being sorted by name, add in the expressions and descriptions.
> 
> Reported-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk>
> Closes: 
> https://lore.kernel.org/linux-perf-users/20260706175624.692736-1-nazar.kazakov@codethink.co.uk/
> Fixes: 40769665b63d ("perf jevents: Parse metrics during conversion")
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/pmu-events/jevents.py | 5 +++--
>  tools/perf/pmu-events/metric.py  | 6 +++++-
>  2 files changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/pmu-events/jevents.py 
> b/tools/perf/pmu-events/jevents.py
> index 376dc2d24162..3c6cfeefbd5d 100755
> --- a/tools/perf/pmu-events/jevents.py
> +++ b/tools/perf/pmu-events/jevents.py
> @@ -570,13 +570,14 @@ static const struct pmu_table_entry 
> {_pending_events_tblname}[] = {{
>  def print_pending_metrics() -> None:
>    """Optionally close metrics table."""
> 
> -  def metric_cmp_key(j: JsonEvent) -> Tuple[bool, str, str]:
> +  def metric_cmp_key(j: JsonEvent) -> Tuple[str, str, str, str]:
>      def fix_none(s: Optional[str]) -> str:
>        if s is None:
>          return ''
>        return s
> 
> -    return (j.desc is not None, fix_none(j.pmu), 
> fix_none(j.metric_name))
> +    return (fix_none(j.pmu), fix_none(j.metric_name), 
> j.metric_expr.ToPerfJson(),
> +            fix_none(j.desc))
> 
>    global _pending_metrics
>    if not _pending_metrics:
> diff --git a/tools/perf/pmu-events/metric.py 
> b/tools/perf/pmu-events/metric.py
> index a91ccb5977f0..11c7162825f4 100644
> --- a/tools/perf/pmu-events/metric.py
> +++ b/tools/perf/pmu-events/metric.py
> @@ -623,7 +623,11 @@ class Metric:
> 
>    def __lt__(self, other):
>      """Sort order."""
> -    return self.name < other.name
> +    if self.name != other.name:
> +      return self.name < other.name
> +    if not self.expr.Equals(other.expr):
> +      return self.expr.ToPerfJson() < other.expr.ToPerfJson()
> +    return self.description < other.description
> 
>    def AddToMetricGroup(self, group):
>      """Callback used when being added to a MetricGroup."""

Tested-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk>

This fixes the non-reproducibility indeed, thank you!
I haven't tested mypy patches as I've just cherry-picked this one.

Thanks,
Nazar Kazakov

  parent reply	other threads:[~2026-07-15 11:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07  3:40 [PATCH v1 0/3] perf jevents: Deterministic build fix and mypy cleanliness Ian Rogers
2026-07-07  3:40 ` [PATCH v1 1/3] perf jevents: Add more components to the metric sorting order Ian Rogers
2026-07-07  3:58   ` sashiko-bot
2026-07-15 11:22   ` Nazar Kazakov [this message]
2026-07-15 17:49     ` Ian Rogers
2026-07-07  3:40 ` [PATCH v1 2/3] perf jevents: Add python type annotations Ian Rogers
2026-07-16 16:56   ` Namhyung Kim
2026-07-16 17:25     ` Ian Rogers
2026-07-16 18:23       ` Namhyung Kim
2026-07-16 21:36         ` Ian Rogers
2026-07-07  3:40 ` [PATCH v1 3/3] perf jevents metric: " Ian Rogers
2026-07-14 16:39 ` [PATCH v1 0/3] perf jevents: Deterministic build fix and mypy cleanliness Ian Rogers

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=0cb89290ad307e4c1d020997a24a9662@codethink.co.uk \
    --to=nazar.kazakov@codethink.co.uk \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ctshao@google.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=john.g.garry@oracle.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sandipan.das@amd.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