Skip to content

Commit

Permalink
add debug log for monitoring @requires time (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Jan 11, 2022
1 parent 010426f commit 32624d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Requires.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ end
if isprecompiling()
precompile(loadpkg, (Base.PkgId,)) || @warn "Requires failed to precompile `loadpkg`"
precompile(withpath, (Any, String)) || @warn "Requires failed to precompile `withpath`"
precompile(err, (Any, Module, String)) || @warn "Requires failed to precompile `err`"
precompile(err, (Any, Module, String, String, Int)) || @warn "Requires failed to precompile `err`"
precompile(err, (Any, Module, String, String, Nothing)) || @warn "Requires failed to precompile `err`"
precompile(parsepkg, (Expr,)) || @warn "Requires failed to precompile `parsepkg`"
precompile(listenpkg, (Any, Base.PkgId)) || @warn "Requires failed to precompile `listenpkg`"
precompile(callbacks, (Base.PkgId,)) || @warn "Requires failed to precompile `callbacks`"
Expand Down
9 changes: 6 additions & 3 deletions src/require.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ function withpath(@nospecialize(f), path::String)
end
end

function err(@nospecialize(f), listener::Module, modname::String)
function err(@nospecialize(f), listener::Module, modname::String, file::String, line)
try
f()
t = @elapsed ret = f()
@debug "Requires conditionally ran code in $t seconds: `$listener` detected `$modname`" _file = file _line = line
ret
catch exc
@warn "Error requiring `$modname` from `$listener`" exception=(exc,catch_backtrace())
end
Expand Down Expand Up @@ -90,11 +92,12 @@ macro require(pkg::Union{Symbol,Expr}, expr)
expr = isa(expr, Expr) ? replace_include(expr, __source__) : expr
expr = macroexpand(__module__, expr)
srcfile = string(__source__.file)
srcline = __source__.line
quote
if !isprecompiling()
listenpkg($pkg) do
withpath($srcfile) do
err($__module__, $modname) do
err($__module__, $modname, $srcfile, $srcline) do
$(esc(:(eval($(Expr(:quote, Expr(:block,
:(const $(Symbol(modname)) = Base.require($pkg)),
expr)))))))
Expand Down

0 comments on commit 32624d3

Please sign in to comment.