Skip to content

Commit f611a3e

Browse files
authored
[AutoBuild] Add timings of different steps (#1115)
1 parent 62a34bc commit f611a3e

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BinaryBuilder"
22
uuid = "12aac903-9f7c-5d81-afc2-d9565ea332ae"
33
authors = ["Elliot Saba <[email protected]>"]
4-
version = "0.4.3"
4+
version = "0.4.4"
55

66
[deps]
77
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"

src/AutoBuild.jl

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,39 @@ import PkgLicenses
99
const DEFAULT_JULIA_VERSION_SPEC = "1.0"
1010
const PKG_VERSIONS = Base.VERSION >= v"1.7-" ? Pkg.Versions : Pkg.Types
1111

12+
mutable struct BuildTimer
13+
begin_setup::Float64
14+
end_setup::Float64
15+
begin_build::Float64
16+
end_build::Float64
17+
begin_audit::Float64
18+
end_audit::Float64
19+
begin_package::Float64
20+
end_package::Float64
21+
BuildTimer() = new(NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN)
22+
end
23+
24+
function Base.show(io::IO, t::BuildTimer)
25+
function rnd(a, b)
26+
min, sec = divrem(b - a, 60)
27+
out = ""
28+
if min 1
29+
out *= string(Int(min), "m ")
30+
end
31+
out *= string(round(sec; digits=2), "s")
32+
return out
33+
end
34+
# Sanity check: make sure all fields are non-NaN: if that's not the case, just skip.
35+
if all(.!(isnan.(getfield.((t,), fieldnames(BuildTimer)))))
36+
print(io, "Timings: ",
37+
"setup: ", rnd(t.begin_setup, t.end_setup), ", ",
38+
"build: ", rnd(t.begin_build, t.end_build), ", ",
39+
"audit: ", rnd(t.begin_audit, t.end_audit), ", ",
40+
"packaging: ", rnd(t.begin_package, t.end_package),
41+
)
42+
end
43+
end
44+
1245
const BUILD_HELP = (
1346
"""
1447
Usage: build_tarballs.jl [target1,target2,...] [--help]
@@ -663,6 +696,9 @@ function autobuild(dir::AbstractString,
663696
try mkpath(out_path) catch; end
664697

665698
for platform in sort(collect(platforms), by = triplet)
699+
timer = BuildTimer()
700+
timer.begin_setup = time()
701+
666702
# We build in a platform-specific directory
667703
build_path = joinpath(dir, "build", triplet(platform))
668704
mkpath(build_path)
@@ -745,8 +781,12 @@ function autobuild(dir::AbstractString,
745781
# teeing to stdout
746782
run(ur, `/bin/bash -l -c $(get_compilers_versions(; compilers...))`, io;
747783
verbose = verbose, tee_stream = devnull)
784+
timer.end_setup = time()
748785
# Run the build script
749-
run(ur, `/bin/bash -l -c $(trapper_wrapper)`, io; verbose=verbose)
786+
timer.begin_build = time()
787+
res = run(ur, `/bin/bash -l -c $(trapper_wrapper)`, io; verbose=verbose)
788+
timer.end_build = time()
789+
res
750790
end
751791
if !did_succeed
752792
if debug
@@ -758,6 +798,7 @@ function autobuild(dir::AbstractString,
758798
end
759799

760800
# Run an audit of the prefix to ensure it is properly relocatable
801+
timer.begin_audit = time()
761802
if !skip_audit
762803
audit_result = audit(dest_prefix, src_name;
763804
platform=platform, verbose=verbose,
@@ -772,6 +813,7 @@ function autobuild(dir::AbstractString,
772813
error(strip(msg))
773814
end
774815
end
816+
timer.end_audit = time()
775817

776818
# Finally, error out if something isn't satisfied
777819
unsatisfied_so_die = false
@@ -828,6 +870,7 @@ function autobuild(dir::AbstractString,
828870
compress_dir(logdir(dest_prefix; subdir=src_name); verbose)
829871

830872
# Once we're built up, go ahead and package this dest_prefix out
873+
timer.begin_package = time()
831874
tarball_path, tarball_hash, git_hash = package(
832875
dest_prefix,
833876
joinpath(out_path, src_name),
@@ -836,6 +879,7 @@ function autobuild(dir::AbstractString,
836879
verbose=verbose,
837880
force=true,
838881
)
882+
timer.end_package = time()
839883

840884
build_output_meta[platform] = (
841885
tarball_path,
@@ -855,6 +899,7 @@ function autobuild(dir::AbstractString,
855899
if isempty(readdir(build_path))
856900
rm(build_path; recursive=true)
857901
end
902+
verbose && @info timer
858903
end
859904

860905
# Return our product hashes

0 commit comments

Comments
 (0)