timer: pick a single unit based on max duration.
This commit is contained in:
@@ -120,9 +120,9 @@ def test_timer_write():
|
||||
|
||||
output = text_buffer.getvalue().splitlines()
|
||||
assert "timer" in output[0]
|
||||
assert "1.0000s" in output[0]
|
||||
assert "1.000s" in output[0]
|
||||
assert "total" in output[1]
|
||||
assert "3.0000s" in output[1]
|
||||
assert "3.000s" in output[1]
|
||||
|
||||
deserialized = json.loads(json_buffer.getvalue())
|
||||
assert deserialized == {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
from collections import OrderedDict, namedtuple
|
||||
from contextlib import contextmanager
|
||||
|
||||
from llnl.util.lang import pretty_seconds
|
||||
from llnl.util.lang import pretty_seconds_formatter
|
||||
|
||||
import spack.util.spack_json as sjson
|
||||
|
||||
@@ -139,12 +139,16 @@ def write_json(self, out=sys.stdout):
|
||||
|
||||
def write_tty(self, out=sys.stdout):
|
||||
"""Write a human-readable summary of timings"""
|
||||
# Individual timers ordered by registration
|
||||
formatted = [(p, f"{self.duration(p):.4f}s") for p in self.phases]
|
||||
|
||||
# Total time
|
||||
formatted.append(("total", f"{self.duration():.4f}s"))
|
||||
times = [self.duration(p) for p in self.phases]
|
||||
|
||||
# Get a consistent unit for the time
|
||||
pretty_seconds = pretty_seconds_formatter(max(times))
|
||||
|
||||
# Tuples of (phase, time) including total.
|
||||
formatted = list(zip(self.phases, times))
|
||||
formatted.append(("total", self.duration()))
|
||||
|
||||
# Write to out
|
||||
for name, duration in formatted:
|
||||
out.write(f" {name:10s} {duration:>10s}\n")
|
||||
out.write(f" {name:10s} {pretty_seconds(duration):>10s}\n")
|
||||
|
||||
Reference in New Issue
Block a user