Skip to content

Commit c159756

Browse files
use TimerOutputs
1 parent ee05c44 commit c159756

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BinaryBuilder"
22
uuid = "12aac903-9f7c-5d81-afc2-d9565ea332ae"
3-
authors = ["Elliot Saba <staticfloat@gmail.com>"]
43
version = "0.6.5"
4+
authors = ["Elliot Saba <staticfloat@gmail.com>"]
55

66
[deps]
77
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
@@ -29,6 +29,7 @@ SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
2929
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
3030
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"
3131
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
32+
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
3233
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
3334
ghr_jll = "07c12ed4-43bc-5495-8a2a-d5838ef8d533"
3435

@@ -51,6 +52,7 @@ RegistryTools = "2.1"
5152
SHA = "0.7, 1"
5253
Scratch = "1.0"
5354
TOML = "1"
55+
TimerOutputs = "0.5"
5456
ghr_jll = "0.13, 0.14, 0.17"
5557
julia = "1.7"
5658

src/Auditor.jl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ using Base.BinaryPlatforms
55
using Pkg
66
using ObjectFile
77

8-
using BinaryBuilderBase: march
8+
using BinaryBuilderBase: march, BBB_TIMER
9+
using TimerOutputs: @timeit
910

1011
export audit, collect_files, collapse_symlinks
1112

@@ -31,16 +32,21 @@ This prevents concurrent patchelf operations on the same file.
3132
function with_patchelf_lock(f, path::AbstractString)
3233
# Normalize the path to ensure consistent locking
3334
path = realpath(path)
34-
35+
filename = basename(path)
36+
3537
# Get or create the lock for this file
3638
file_lock = Base.@lock PATCHELF_FILE_LOCKS_LOCK begin
3739
get!(PATCHELF_FILE_LOCKS, path) do
3840
ReentrantLock()
3941
end
4042
end
41-
42-
# Execute with the file-specific lock held
43-
Base.@lock file_lock f()
43+
44+
# Execute with the file-specific lock held, timing both the lock wait and the inner operation
45+
@timeit BBB_TIMER "patchelf $(filename) (incl. lock)" begin
46+
Base.@lock file_lock begin
47+
@timeit BBB_TIMER "patchelf $(filename)" f()
48+
end
49+
end
4450
end
4551

4652
# Helper function to run a command and print to `io` its invocation and full
@@ -148,7 +154,7 @@ function audit(prefix::Prefix, src_name::AbstractString = "";
148154
# for Windows, for which however we have to set autofix=false:
149155
# https://github.com/JuliaPackaging/Yggdrasil/pull/922.
150156
all_ok[] &= ensure_executability(oh; verbose, silent)
151-
157+
152158
# If this is a dynamic object, do the dynamic checks
153159
if isdynamic(oh)
154160
# Check that the libgfortran version matches

src/AutoBuild.jl

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ export build_tarballs, autobuild, build, get_meta_json
22
import GitHub: gh_get_json, DEFAULT_API
33
import SHA: sha256, sha1
44
using TOML, Dates, UUIDs
5+
using TimerOutputs: @timeit, print_timer
6+
using BinaryBuilderBase: BBB_TIMER, reset_bbb_timer!
57
using RegistryTools
68
import LibGit2
79
import PkgLicenses
@@ -193,6 +195,7 @@ function build_tarballs(ARGS, src_name, src_version, sources, script,
193195
compression_format::String="gzip",
194196
kwargs...)
195197
@nospecialize
198+
reset_bbb_timer!()
196199
# See if someone has passed in `--help`, and if so, give them the
197200
# assistance they so clearly long for
198201
if "--help" in ARGS
@@ -441,6 +444,8 @@ function build_tarballs(ARGS, src_name, src_version, sources, script,
441444
upload_to_github_releases(deploy_bin_repo, tag, products_dir; verbose=verbose)
442445
end
443446

447+
print_timer(BBB_TIMER; sortby=:firstexec)
448+
println()
444449
return build_output_meta
445450
end
446451

@@ -836,13 +841,14 @@ function autobuild(dir::AbstractString,
836841
end
837842

838843
# We must prepare our sources. Download them, hash them, etc...
839-
source_files = download_source.(sources; verbose=verbose)
844+
source_files = @timeit BBB_TIMER "Downloading sources" download_source.(sources; verbose=verbose)
840845

841846
# Our build products will go into ./products
842847
out_path = joinpath(dir, "products")
843848
try mkpath(out_path) catch; end
844849

845850
for platform in sort(collect(platforms), by = triplet)
851+
@timeit BBB_TIMER "Building for $(triplet(platform))" begin
846852
timer = BuildTimer()
847853
timer.begin_setup = time()
848854

@@ -928,7 +934,7 @@ function autobuild(dir::AbstractString,
928934
"""
929935

930936
dest_prefix = Prefix(BinaryBuilderBase.destdir(prefix.path, concrete_platform))
931-
did_succeed = with_logfile(dest_prefix, "$(src_name).log"; subdir=src_name) do io
937+
did_succeed = @timeit BBB_TIMER "Running build script" with_logfile(dest_prefix, "$(src_name).log"; subdir=src_name) do io
932938
# Let's start the presentations with BinaryBuilder.jl
933939
write(io, "BinaryBuilder.jl version: $(get_bb_version())\n\n")
934940
# Get the list of compilers...
@@ -959,6 +965,7 @@ function autobuild(dir::AbstractString,
959965
# Run an audit of the prefix to ensure it is properly relocatable
960966
timer.begin_audit = time()
961967
if !skip_audit
968+
@timeit BBB_TIMER "Auditing build artifacts" begin
962969
audit_result = audit(dest_prefix, src_name;
963970
platform=platform, verbose=verbose,
964971
has_csl = any(getname.(dependencies) .== "CompilerSupportLibraries_jll"),
@@ -971,6 +978,7 @@ function autobuild(dir::AbstractString,
971978
""", '\n' => ' ')
972979
error(strip(msg))
973980
end
981+
end # @timeit audit
974982
end
975983
timer.end_audit = time()
976984

@@ -1075,6 +1083,7 @@ function autobuild(dir::AbstractString,
10751083
rm(build_path; recursive=true)
10761084
end
10771085
verbose && @info "$(timer)"
1086+
end # @timeit platform
10781087
end
10791088

10801089
# Return our product hashes
@@ -1473,11 +1482,11 @@ function build_jll_package(src_name::String,
14731482
libgfortran_version_mapping = BinaryPlatforms.libgfortran_version_mapping
14741483
cxxstring_abi_mapping = BinaryPlatforms.cxxstring_abi_mapping
14751484
libstdcxx_version_mapping = BinaryPlatforms.libstdcxx_version_mapping
1476-
1485+
14771486
# Helper function to collapse dictionary of mappings down into a regex of
14781487
# named capture groups joined by "|" operators
14791488
c(mapping) = string("(",join(["(?<$k>$v)" for (k, v) in mapping], "|"), ")")
1480-
1489+
14811490
# We're going to build a mondo regex here to parse everything:
14821491
triplet_regex = Regex(string(
14831492
"^",
@@ -1494,7 +1503,7 @@ function build_jll_package(src_name::String,
14941503
"(?<tags>(?:-[^-]+\\+[^-]+)*)?",
14951504
"\$",
14961505
))
1497-
1506+
14981507
m = match(triplet_regex, triplet)
14991508
if m !== nothing
15001509
# Helper function to find the single named field within the giant regex
@@ -1517,7 +1526,7 @@ function build_jll_package(src_name::String,
15171526
end
15181527
end
15191528
end
1520-
1529+
15211530
# Extract the information we're interested in:
15221531
arch = get_field(m, arch_mapping)
15231532
os = get_field(m, os_mapping)
@@ -1534,7 +1543,7 @@ function build_jll_package(src_name::String,
15341543
return map(v -> Symbol(v[1]) => v[2], split.(tag_fields, "+"))
15351544
end
15361545
tags = split_tags(m["tags"])
1537-
1546+
15381547
# Special parsing of os version number, if any exists
15391548
function extract_os_version(os_name, pattern)
15401549
m_osvn = match(pattern, m[os_name])
@@ -1553,7 +1562,7 @@ function build_jll_package(src_name::String,
15531562
if os == "openbsd"
15541563
os_version = extract_os_version("openbsd", r".*openbsd([\d.]+)"sa)
15551564
end
1556-
1565+
15571566
return Platform(
15581567
arch, os;
15591568
validate_strict,

0 commit comments

Comments
 (0)