From be6bb413dfed861c5f317b5d7274e4d47c34aeab Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Thu, 22 Dec 2022 23:38:42 -0800 Subject: `spack solve`: use consistent units for time `spack solve` is supposed to show you times you can compare. setup, ground, solve, etc. all in a list. You're also supposed to be able to compare easily across runs. With `pretty_seconds()` (introduced in #33900), it's easy to miss the units, e.g., spot the bottleneck here: ```console > spack solve --timers tcl setup 22.125ms load 16.083ms ground 8.298ms solve 848.055us total 58.615ms ``` It's easier to see what matters if these are all in the same units, e.g.: ``` > spack solve --timers tcl setup 0.0147s load 0.0130s ground 0.0078s solve 0.0008s total 0.0463s ``` And the units won't fluctuate from run to run as you make changes. -[x] make `spack solve` timings consistent like before --- lib/spack/spack/test/util/timer.py | 4 ++-- lib/spack/spack/util/timer.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/test/util/timer.py b/lib/spack/spack/test/util/timer.py index 16c1564663..9f43526482 100644 --- a/lib/spack/spack/test/util/timer.py +++ b/lib/spack/spack/test/util/timer.py @@ -120,9 +120,9 @@ def test_timer_write(): output = text_buffer.getvalue().splitlines() assert "timer" in output[0] - assert "1.000s" in output[0] + assert "1.0000s" in output[0] assert "total" in output[1] - assert "3.000s" in output[1] + assert "3.0000s" in output[1] deserialized = json.loads(json_buffer.getvalue()) assert deserialized == { diff --git a/lib/spack/spack/util/timer.py b/lib/spack/spack/util/timer.py index 94b0531c16..83d6907c67 100644 --- a/lib/spack/spack/util/timer.py +++ b/lib/spack/spack/util/timer.py @@ -140,11 +140,11 @@ class Timer(object): def write_tty(self, out=sys.stdout): """Write a human-readable summary of timings""" # Individual timers ordered by registration - formatted = [(p, pretty_seconds(self.duration(p))) for p in self.phases] + formatted = [(p, f"{self.duration(p):.4f}s") for p in self.phases] # Total time - formatted.append(("total", pretty_seconds(self.duration()))) + formatted.append(("total", f"{self.duration():.4f}s")) # Write to out for name, duration in formatted: - out.write(" {:10s} {:>10s}\n".format(name, duration)) + out.write(f" {name:10s} {duration:>10s}\n") -- cgit v1.2.3-60-g2f50