[llvm] [lit] Include zero-duration tests in the --time-tests histogram (PR #226132)
Manuel Carrasco via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 24 04:53:39 PDT 2026
https://github.com/mgcarrasco created https://github.com/llvm/llvm-project/pull/226132
`--time-tests` treated an elapsed time of 0 as missing, so they were omitted from the histogram. That made time-tests.py flaky when FileCheck expected every test to be listed.
The PR also avoids log(0) when every recorded time is zero.
Fixes https://github.com/llvm/llvm-project/pull/208444#issuecomment-5805067757.
>From 3f27ea579b02b1f2f11394a075c45940521f4f6f Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Thu, 24 Sep 2026 06:47:26 -0500
Subject: [PATCH] [lit] Include zero-duration tests in the --time-tests
histogram
`if t.result.elapsed` dropped tests whose elapsed time was 0.0, so
--time-tests=all could print "N of M" with M smaller than the number of
tests that ran (seen as a flake in time-tests.py). Treat only None as
"not timed". If every recorded time is zero, use 0.55 as a dummy max so
the histogram can still be built without log(0).
---
llvm/utils/lit/lit/main.py | 4 +-
llvm/utils/lit/lit/util.py | 3 +-
llvm/utils/lit/tests/unit/Histogram.py | 55 ++++++++++++++++++++++++++
3 files changed, 60 insertions(+), 2 deletions(-)
create mode 100644 llvm/utils/lit/tests/unit/Histogram.py
diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py
index 801bdf6808d521..0e6bee691d400d 100755
--- a/llvm/utils/lit/lit/main.py
+++ b/llvm/utils/lit/lit/main.py
@@ -320,7 +320,9 @@ def execute_in_tmp_dir(run, lit_config):
def print_histogram(tests, slowest_limit):
test_times = [
- (t.getFullName(), t.result.elapsed) for t in tests if t.result.elapsed
+ (t.getFullName(), t.result.elapsed)
+ for t in tests
+ if t.result.elapsed is not None
]
if test_times:
lit.util.printHistogram(test_times, slowest_limit, title="Tests")
diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py
index 5a565fd84c7d95..4cf93ede92d67e 100644
--- a/llvm/utils/lit/lit/util.py
+++ b/llvm/utils/lit/lit/util.py
@@ -172,7 +172,8 @@ def printHistogram(items, slowest_limit, title="Items"):
else:
slowest_count = min(slowest_limit, total)
- maxValue = max([v for _, v in items])
+ # Set a default value to prevent the log(0) error from happening.
+ maxValue = max([v for _, v in items]) or 0.55
# Select first "nice" bar height that produces more than 10 bars.
power = int(math.ceil(math.log(maxValue, 10)))
diff --git a/llvm/utils/lit/tests/unit/Histogram.py b/llvm/utils/lit/tests/unit/Histogram.py
new file mode 100644
index 00000000000000..5c9a930e51a709
--- /dev/null
+++ b/llvm/utils/lit/tests/unit/Histogram.py
@@ -0,0 +1,55 @@
+# RUN: %{python} %s
+
+"""Unit tests for lit.util.printHistogram."""
+
+import contextlib
+import io
+import unittest
+
+from lit.util import printHistogram
+
+
+class TestPrintHistogram(unittest.TestCase):
+ def test_all_zero_elapsed(self):
+ buf = io.StringIO()
+ with contextlib.redirect_stdout(buf):
+ printHistogram(
+ [
+ ("time-tests :: a.txt", 0.0),
+ ("time-tests :: b.txt", 0.0),
+ ("time-tests :: c.txt", 0.0),
+ ],
+ "all",
+ title="Tests",
+ )
+ bar = "[ ]"
+ filled = "[****************************************]"
+ self.assertEqual(
+ buf.getvalue(),
+ "Slowest Tests (3 of 3):\n"
+ "--------------------------------------------------------------------------\n"
+ "0.00s: time-tests :: c.txt\n"
+ "0.00s: time-tests :: b.txt\n"
+ "0.00s: time-tests :: a.txt\n"
+ "\n"
+ "Test Times (3):\n"
+ "--------------------------------------------------------------------------\n"
+ "[ Range ] :: [ Percentage ] :: [Count]\n"
+ "--------------------------------------------------------------------------\n"
+ f"[0.500s,0.550s) :: {bar} :: [0/3]\n"
+ f"[0.450s,0.500s) :: {bar} :: [0/3]\n"
+ f"[0.400s,0.450s) :: {bar} :: [0/3]\n"
+ f"[0.350s,0.400s) :: {bar} :: [0/3]\n"
+ f"[0.300s,0.350s) :: {bar} :: [0/3]\n"
+ f"[0.250s,0.300s) :: {bar} :: [0/3]\n"
+ f"[0.200s,0.250s) :: {bar} :: [0/3]\n"
+ f"[0.150s,0.200s) :: {bar} :: [0/3]\n"
+ f"[0.100s,0.150s) :: {bar} :: [0/3]\n"
+ f"[0.050s,0.100s) :: {bar} :: [0/3]\n"
+ f"[0.000s,0.050s) :: {filled} :: [3/3]\n"
+ "--------------------------------------------------------------------------\n",
+ )
+
+
+if __name__ == "__main__":
+ unittest.main()
More information about the llvm-commits
mailing list