about summary refs log tree commit diff
path: root/src/ci
diff options
context:
space:
mode:
authorJakub Beránek <berykubik@gmail.com>2023-02-01 17:50:38 +0100
committerJakub Beránek <berykubik@gmail.com>2023-02-01 17:50:38 +0100
commit7bd8fbbd28f38669bc83cb734e2ffef44f3de9ae (patch)
tree1f3cfac775f83a6e02abd1bb15b0c25cd2464342 /src/ci
parent4bce0751492a3e08ac6f4998e06b4dfa72943cc2 (diff)
downloadrust-7bd8fbbd28f38669bc83cb734e2ffef44f3de9ae.tar.gz
rust-7bd8fbbd28f38669bc83cb734e2ffef44f3de9ae.zip
Print total duration in human time
Diffstat (limited to 'src/ci')
-rw-r--r--src/ci/stage-build.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/ci/stage-build.py b/src/ci/stage-build.py
index 7421ea3f659..775478bcbab 100644
--- a/src/ci/stage-build.py
+++ b/src/ci/stage-build.py
@@ -241,7 +241,7 @@ class Timer:
             len(label) for label in list(self.stages.keys()) + [total_duration_label[:-1]]
         )) + 1 + 2
 
-        table_width = max_label_length + 24
+        table_width = max_label_length + 23
         divider = "-" * table_width
 
         with StringIO() as output:
@@ -253,7 +253,7 @@ class Timer:
                       file=output)
 
             print(file=output)
-            print(f"{total_duration_label:<{max_label_length}} {total_duration:>12.2f}s",
+            print(f"{total_duration_label:<{max_label_length}} {humantime(total_duration):>22}",
                   file=output)
             print(divider, file=output, end="")
             LOGGER.info(f"Timer results\n{output.getvalue()}")
@@ -274,6 +274,21 @@ def change_cwd(dir: Path):
         os.chdir(cwd)
 
 
+def humantime(time_s: int) -> str:
+    hours = time_s // 3600
+    time_s = time_s % 3600
+    minutes = time_s // 60
+    seconds = time_s % 60
+
+    result = ""
+    if hours > 0:
+        result += f"{int(hours)}h "
+    if minutes > 0:
+        result += f"{int(minutes)}m "
+    result += f"{round(seconds)}s"
+    return result
+
+
 def move_path(src: Path, dst: Path):
     LOGGER.info(f"Moving `{src}` to `{dst}`")
     shutil.move(src, dst)