Skip to content

Commit 7bd8fbb

Browse files
committed
Print total duration in human time
1 parent 4bce075 commit 7bd8fbb

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/ci/stage-build.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def print_stats(self):
241241
len(label) for label in list(self.stages.keys()) + [total_duration_label[:-1]]
242242
)) + 1 + 2
243243

244-
table_width = max_label_length + 24
244+
table_width = max_label_length + 23
245245
divider = "-" * table_width
246246

247247
with StringIO() as output:
@@ -253,7 +253,7 @@ def print_stats(self):
253253
file=output)
254254

255255
print(file=output)
256-
print(f"{total_duration_label:<{max_label_length}} {total_duration:>12.2f}s",
256+
print(f"{total_duration_label:<{max_label_length}} {humantime(total_duration):>22}",
257257
file=output)
258258
print(divider, file=output, end="")
259259
LOGGER.info(f"Timer results\n{output.getvalue()}")
@@ -274,6 +274,21 @@ def change_cwd(dir: Path):
274274
os.chdir(cwd)
275275

276276

277+
def humantime(time_s: int) -> str:
278+
hours = time_s // 3600
279+
time_s = time_s % 3600
280+
minutes = time_s // 60
281+
seconds = time_s % 60
282+
283+
result = ""
284+
if hours > 0:
285+
result += f"{int(hours)}h "
286+
if minutes > 0:
287+
result += f"{int(minutes)}m "
288+
result += f"{round(seconds)}s"
289+
return result
290+
291+
277292
def move_path(src: Path, dst: Path):
278293
LOGGER.info(f"Moving `{src}` to `{dst}`")
279294
shutil.move(src, dst)

0 commit comments

Comments
 (0)