[libcxx-commits] [libcxx] [libc++] Fix SPEC benchmarks not producing a .lnt result file (PR #207450)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jul 3 12:32:06 PDT 2026


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/207450

>From f1e39493342f2ce2030071538e966186babe8dac Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 3 Jul 2026 15:04:10 -0400
Subject: [PATCH 1/2] [libc++] Fix SPEC benchmarks not producing a .lnt result
 file

The refactoring in 471e8f7f94e7 removed the output of a .lnt file, which
is necessary for interoperation with consolidate-benchmarks.
---
 libcxx/test/benchmarks/spec.gen.py |  2 +-
 libcxx/utils/run-spec-benchmark    | 18 ++++++++++++++----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/libcxx/test/benchmarks/spec.gen.py b/libcxx/test/benchmarks/spec.gen.py
index 13e374adf1587..0eeb2192d47f0 100644
--- a/libcxx/test/benchmarks/spec.gen.py
+++ b/libcxx/test/benchmarks/spec.gen.py
@@ -34,4 +34,4 @@
 
 for benchmark in spec_benchmarks:
     print(f'#--- {benchmark}.sh.test')
-    print(f'RUN: %{{python}} %{{libcxx-dir}}/utils/run-spec-benchmark --spec-dir %{{spec_dir}} --temp-dir %{{temp}} --benchmark {benchmark} --clean -- %{{cxx}} %{{compile_flags}} %{{flags}} %{{link_flags}}')
+    print(f'RUN: %{{python}} %{{libcxx-dir}}/utils/run-spec-benchmark --spec-dir %{{spec_dir}} --temp-dir %{{temp}} --benchmark {benchmark} --output %{{temp}}/results.lnt --clean -- %{{cxx}} %{{compile_flags}} %{{flags}} %{{link_flags}}')
diff --git a/libcxx/utils/run-spec-benchmark b/libcxx/utils/run-spec-benchmark
index 7a4fb565d34ef..c9b91598ce3c6 100755
--- a/libcxx/utils/run-spec-benchmark
+++ b/libcxx/utils/run-spec-benchmark
@@ -42,6 +42,12 @@ def main():
         action="store_true",
         help="Clean up build artifacts after running. Useful to save disk space when running multiple benchmarks.",
     )
+    parser.add_argument(
+        "--output",
+        type=str,
+        default=None,
+        help="Path to write the LNT-format results to. Defaults to stdout.",
+    )
     parser.add_argument(
         "compiler_and_flags",
         nargs="+",
@@ -122,16 +128,20 @@ default:
             print(f"SPEC benchmark {args.benchmark} had a compilation or runtime error.", file=sys.stderr)
             sys.exit(1)
 
-    # Parse results into LNT format and print to stdout.
+    # Parse results into LNT format. Write them to the requested output file (or stdout by default).
+    # We only get here after the build and run succeeded, so a failed benchmark produces no output file.
     benchmark_name = args.benchmark.replace(".", "_")
     spec_results = subprocess.run([str(utils_dir / "parse-spec-results"), "--output-format=lnt"] + csv_files,
                                    capture_output=True, text=True, check=True)
-    sys.stdout.write(spec_results.stdout)
-
     time_results = subprocess.run([str(utils_dir / "parse-time-output"), str(time_output), f"--benchmark={benchmark_name}",
                                     "--extract", "instructions", "max_rss", "cycles", "peak_memory"],
                                     capture_output=True, text=True, check=True)
-    sys.stdout.write(time_results.stdout)
+
+    lnt_results = spec_results.stdout + time_results.stdout
+    if args.output:
+        pathlib.Path(args.output).write_text(lnt_results)
+    else:
+        sys.stdout.write(lnt_results)
 
     # Clean up build artifacts since they can be very large.
     if args.clean:

>From acfe8e1fe25407cf2b93af8f863d6a5458e22b1c Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Fri, 3 Jul 2026 15:31:24 -0400
Subject: [PATCH 2/2] Less brittle against missing trailing newlines

---
 libcxx/utils/run-spec-benchmark | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/utils/run-spec-benchmark b/libcxx/utils/run-spec-benchmark
index c9b91598ce3c6..06f17ef02cf12 100755
--- a/libcxx/utils/run-spec-benchmark
+++ b/libcxx/utils/run-spec-benchmark
@@ -137,7 +137,8 @@ default:
                                     "--extract", "instructions", "max_rss", "cycles", "peak_memory"],
                                     capture_output=True, text=True, check=True)
 
-    lnt_results = spec_results.stdout + time_results.stdout
+    lines = spec_results.stdout.splitlines() + time_results.stdout.splitlines()
+    lnt_results = "".join(f"{line}\n" for line in lines)
     if args.output:
         pathlib.Path(args.output).write_text(lnt_results)
     else:



More information about the libcxx-commits mailing list