[llvm] b202c00 - [lit] Include zero-duration tests in the --time-tests histogram (#226132)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 01:48:13 PDT 2026
Author: Manuel Carrasco
Date: 2026-09-25T09:48:05+01:00
New Revision: b202c00d967c22f5d4d83561024690f1de05bc01
URL: https://github.com/llvm/llvm-project/commit/b202c00d967c22f5d4d83561024690f1de05bc01
DIFF: https://github.com/llvm/llvm-project/commit/b202c00d967c22f5d4d83561024690f1de05bc01.diff
LOG: [lit] Include zero-duration tests in the --time-tests histogram (#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.
Added:
llvm/utils/lit/tests/unit/Histogram.py
Modified:
llvm/utils/lit/lit/main.py
llvm/utils/lit/lit/util.py
Removed:
################################################################################
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