perf jevents: Add more components to the metric sorting order

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: 40769665b6 ("perf jevents: Parse metrics during conversion")
Tested-by: Nazar Kazakov <nazar.kazakov@codethink.co.uk>
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
Ian Rogers
2026-07-06 20:40:17 -07:00
committed by Namhyung Kim
parent e1f522ac43
commit 557f8b3ca8
2 changed files with 8 additions and 3 deletions

View File

@@ -574,13 +574,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:

View File

@@ -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."""