Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt SnoopPrecompile & snoopi_deep to work for new julia API. #313

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions SnoopCompileCore/src/snoopi_deep.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const have_clear_and_fetch_timings = isdefined(Core.Compiler, :Timings) && isdefined(Core.Compiler.Timings, :clear_and_fetch_timings)

using Core.Compiler.Timings: ROOT, ROOTmi, InferenceFrameInfo, Timing

struct InferenceTiming
mi_info::Core.Compiler.Timings.InferenceFrameInfo
inclusive_time::Float64
Expand Down Expand Up @@ -70,17 +74,34 @@ function addchildren!(parent::InferenceTimingNode, t::Core.Compiler.Timings.Timi
end
end

function start_deep_timing()
Core.Compiler.Timings.reset_timings()
Core.Compiler.__set_measure_typeinf(true)
end
function stop_deep_timing()
Core.Compiler.__set_measure_typeinf(false)
Core.Compiler.Timings.close_current_timer()
end

function finish_snoopi_deep()
return InferenceTimingNode(Core.Compiler.Timings._timings[1])
if have_clear_and_fetch_timings
function start_deep_timing()
Core.Compiler.__set_measure_typeinf(true)
end
function stop_deep_timing()
Core.Compiler.__set_measure_typeinf(false)
end
function finish_snoopi_deep()
# Construct a dummy Timing for ROOT(), for backwards compatibility with the old API.
root = Timing(
InferenceFrameInfo(ROOTmi, 0x0, Any[], Any[Core.Const(ROOT)], 1),
0x0)
root.children = Core.Compiler.Timings.clear_and_fetch_timings()

return InferenceTimingNode(root)
Comment on lines +84 to +91
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timholy: In JuliaLang/julia#47615, we changed the API to return a vector of inference trees, rather than a single inference tree with the dummy "ROOT" node.

We think this is a more sensical API, since there really wasn't a single tree of type inference, there were many, and it also made it easier to get the thread safety correct.

However, of course this breaks the old API. So for now, I'm proposing we just do this, and shove it back into a dummy ROOT node to make a single tree 😅

Then we can investigate changes to the API in the future if we want to clean things up to all operate on vectors of trees, or just leave it like this forever. :)

Does that sound good to you?

end
else
function start_deep_timing()
Core.Compiler.Timings.reset_timings()
Core.Compiler.__set_measure_typeinf(true)
end
function stop_deep_timing()
Core.Compiler.__set_measure_typeinf(false)
Core.Compiler.Timings.close_current_timer()
end
function finish_snoopi_deep()
return InferenceTimingNode(Core.Compiler.Timings._timings[1])
end
end

function _snoopi_deep(cmd::Expr)
Expand Down
32 changes: 23 additions & 9 deletions SnoopPrecompile/src/SnoopPrecompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export @precompile_all_calls, @precompile_setup
const verbose = Ref(false) # if true, prints all the precompiles
const have_inference_tracking = isdefined(Core.Compiler, :__set_measure_typeinf)
const have_force_compile = isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("#@force_compile"))
const have_clear_and_fetch_timings = isdefined(Core.Compiler, :Timings) && isdefined(Core.Compiler.Timings, :clear_and_fetch_timings)

function precompile_roots(roots)
@assert have_inference_tracking
Expand Down Expand Up @@ -59,16 +60,29 @@ macro precompile_all_calls(ex::Expr)
end
end
if have_inference_tracking
ex = quote
Core.Compiler.Timings.reset_timings()
Core.Compiler.__set_measure_typeinf(true)
try
$ex
finally
Core.Compiler.__set_measure_typeinf(false)
Core.Compiler.Timings.close_current_timer()
if have_clear_and_fetch_timings
# use new thread-safe timings API if it's available in this version of Julia
ex = quote
Core.Compiler.__set_measure_typeinf(true)
try
$ex
finally
Core.Compiler.__set_measure_typeinf(false)
end
$SnoopPrecompile.precompile_roots(Core.Compiler.Timings.clear_and_fetch_timings())
end
else
ex = quote
Core.Compiler.Timings.reset_timings()
Core.Compiler.__set_measure_typeinf(true)
try
$ex
finally
Core.Compiler.__set_measure_typeinf(false)
Core.Compiler.Timings.close_current_timer()
end
$SnoopPrecompile.precompile_roots(Core.Compiler.Timings._timings[1].children)
end
$SnoopPrecompile.precompile_roots(Core.Compiler.Timings._timings[1].children)
end
end
return esc(quote
Expand Down