Skip to content

Commit 3e8d7da

Browse files
authored
swift_build_support: make build duration more readable (#61536)
`build-script` invocations print a total duration summary at the end of the build, like this: ``` Total Duration: 4558.030000000001 ``` With this change build duration summary is printed as ``` Total Duration: 487.93 seconds (8m 7s) ```
1 parent 7d8eb2f commit 3e8d7da

File tree

1 file changed

+14
-1
lines changed
  • utils/swift_build_support/swift_build_support

1 file changed

+14
-1
lines changed

utils/swift_build_support/swift_build_support/utils.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,20 @@ def log_analyzer():
9898
print(event_row.format(duration_percentage,
9999
build_event["duration"],
100100
build_event["command"]))
101-
print("Total Duration: {}".format(total_duration))
101+
102+
hours, remainder = divmod(total_duration, 3600)
103+
minutes, seconds = divmod(remainder, 60)
104+
105+
if hours > 0:
106+
formatted_duration = " ({}h {}m {}s)".format(
107+
int(hours), int(minutes), int(seconds))
108+
elif minutes > 0:
109+
formatted_duration = " ({}m {}s)".format(int(minutes), int(seconds))
110+
else:
111+
formatted_duration = ""
112+
113+
print("Total Duration: {:.2f} seconds".format(
114+
total_duration) + formatted_duration)
102115
else:
103116
print("Skip build script analyzer")
104117
print(".build_script_log file not found at {}".format(build_script_log_path))

0 commit comments

Comments
 (0)