Re: [PATCH v4 00/14] perf stat: Decouple and modularize display formatting

From: Ian Rogers

Date: Thu Jul 16 2026 - 20:23:30 EST


On Thu, Jul 16, 2026 at 3:49 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> On Thu, Jul 16, 2026 at 12:02:49AM -0700, Ian Rogers wrote:
> > This patch set decouples and modularizes `perf stat` metric and event
> > counter display processing into a unified traversal engine supporting
> > pluggable, format-specific callbacks for standard (STD), CSV, and JSON
> > outputs via the new `--new` flag.
>
> Thanks for working on this!
>
> I'm not sure the goal is to produce the exactly same output or not.
> If so, we need to verify that by comparing outputs before and after.
> Probably you can use perf stat record and report.
>
> If not, please show the output here.
>
> Actually I cannot say I like the name of the flag, but it's ok if we
> want to keep it for a short period time and eventually get rid of it.

I don't like the flag name either :-) I wanted the output generated
with `--new` to pass all the existing perf stat tests, which requires
the output to be as close as possible. Only the json output changes
things as the order of results matters less with json. The csv and std
printing buffer events and metrics to make sure the output matches
without relying on a particular printing an event, then printing a
metric, etc. order from the caller. My hope in doing things this way
was that we could land `--new`, another patch can make it the default,
another patch series can delete the old code and another patch can
remove the flag. Once we are happy with the --new version of the code
we can change what CSV and std output looks like without worrying
about the existing stat output code, etc.

Thanks,
Ian

> Thanks,
> Namhyung
>
> >
> > Changes in v4:
> > - Squash all multi-metric column padding, zero-skip logic, and formatting
> > fixes directly into their introducing commits for a perfectly bisectable,
> > pristine Git history.
> > - Avoid newlines before signed-off-by, assisted-by, and acked-by tags,
> > organizing all contributor tags into a single, contiguous block for strict
> > checkpatch and LKML compliance.
> > - Introduce strict, grid-based column padding to perfectly align multi-metric
> > events (e.g. TopdownL1) across both standard and metric-only CSV rows, guaranteeing
> > perfect 6-comma and 7-comma parsing compliance by external DataFrame engines.
> > - Refactor the PMU and hybrid metric event printer to propagate identical zero-counter
> > skipping semantics in alignment with the legacy abs_printout path.
> > - Re-run all STD, JSON, and CSV linter test suites to achieve 100% passing status.
> >
> > Ian Rogers (14):
> > perf stat: Introduce core generic print traversal engine and header
> > stubs
> > perf stat: Implement standard console (STD) formatting callbacks
> > perf stat: Extend STD output linter to test basic New API checks
> > perf stat: Extend STD output linter to test core aggregation checks
> > perf stat: Extend STD output linter to test advanced PMU checks
> > perf stat: Extend STD output linter to test metric-only checks
> > perf stat: Implement CSV formatting callbacks
> > perf stat: Extend CSV output linter to test core aggregation checks
> > perf stat: Extend CSV output linter to test advanced PMU and
> > metric-only checks
> > perf stat: Implement streaming JSON formatting callbacks
> > perf stat: Extend JSON output linter to test core aggregation checks
> > perf stat: Extend JSON output linter to test advanced PMU and
> > metric-only checks
> > perf stat: Add --new support to PMU metrics Python validator
> > perf stat: Extend PMU metrics value linter to validate --new outputs
> >
> > tools/perf/builtin-stat.c | 96 +-
> > .../tests/shell/lib/perf_metric_validation.py | 12 +-
> > tools/perf/tests/shell/stat+csv_output.sh | 19 +
> > tools/perf/tests/shell/stat+json_output.sh | 74 +-
> > tools/perf/tests/shell/stat+std_output.sh | 18 +
> > tools/perf/tests/shell/stat_metrics_values.sh | 22 +-
> > tools/perf/util/Build | 4 +
> > tools/perf/util/stat-display.c | 12 +-
> > tools/perf/util/stat-print-csv.c | 677 ++++++++++++++
> > tools/perf/util/stat-print-json.c | 339 +++++++
> > tools/perf/util/stat-print-std.c | 854 ++++++++++++++++++
> > tools/perf/util/stat-print.c | 500 ++++++++++
> > tools/perf/util/stat-print.h | 137 +++
> > tools/perf/util/stat.h | 6 +
> > 14 files changed, 2688 insertions(+), 82 deletions(-)
> > create mode 100644 tools/perf/util/stat-print-csv.c
> > create mode 100644 tools/perf/util/stat-print-json.c
> > create mode 100644 tools/perf/util/stat-print-std.c
> > create mode 100644 tools/perf/util/stat-print.c
> > create mode 100644 tools/perf/util/stat-print.h
> >
> > --
> > 2.55.0.141.g00534a21ce-goog
> >