From 7bd8fbbd28f38669bc83cb734e2ffef44f3de9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 1 Feb 2023 17:50:38 +0100 Subject: [PATCH] Print total duration in human time --- src/ci/stage-build.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ci/stage-build.py b/src/ci/stage-build.py index 7421ea3f6597..775478bcbab4 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)