Re: [PATCH v1 1/3] perf jevents: Add more components to the metric sorting order
From: Ian Rogers
Date: Wed Jul 15 2026 - 13:50:10 EST
On Wed, Jul 15, 2026 at 4:22 AM Nazar Kazakov
<nazar.kazakov@xxxxxxxxxxxxxxx> wrote:
>
> 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@xxxxxxxxxxxxxxx>
> > Closes:
> > https://lore.kernel.org/linux-perf-users/20260706175624.692736-1-nazar.kazakov@xxxxxxxxxxxxxxx/
> > Fixes: 40769665b63d ("perf jevents: Parse metrics during conversion")
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> > ---
> > 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@xxxxxxxxxxxxxxx>
>
> This fixes the non-reproducibility indeed, thank you!
> I haven't tested mypy patches as I've just cherry-picked this one.
Great, thanks!
Ian
> Thanks,
> Nazar Kazakov