From 9cd43de0fc2d5f02738787cb1722456eb01510be Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 3 Dec 2019 04:06:47 -0600 Subject: [PATCH] Encapsulate ccalls to enhance interpreter usage (#43) If Julia compiles the returned expression, we will "miss" the inference time because the compilation happens before we turn snooping on. The logic in https://github.com/JuliaLang/julia/blob/84e839227f7762b6dfa0821247cd132cf15e3581/src/toplevel.c#L793-L815 indicates that the `ccall`s could force Julia to use the compiler, so move these inside a function. --- src/SnoopCompile.jl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/SnoopCompile.jl b/src/SnoopCompile.jl index a2d35dd8c..7a841a077 100644 --- a/src/SnoopCompile.jl +++ b/src/SnoopCompile.jl @@ -23,6 +23,9 @@ if VERSION >= v"1.2.0-DEV.573" return ret end + @noinline start_timing() = ccall(:jl_set_typeinf_func, Cvoid, (Any,), typeinf_ext_timed) + @noinline stop_timing() = ccall(:jl_set_typeinf_func, Cvoid, (Any,), Core.Compiler.typeinf_ext) + function sort_timed_inf(tmin) data = __inf_timing__ if tmin > 0 @@ -47,12 +50,12 @@ if VERSION >= v"1.2.0-DEV.573" error("at most two arguments are supported") end quote - empty!($__inf_timing__) - ccall(:jl_set_typeinf_func, Cvoid, (Any,), $typeinf_ext_timed) + empty!(__inf_timing__) + start_timing() try $(esc(cmd)) finally - ccall(:jl_set_typeinf_func, Cvoid, (Any,), Core.Compiler.typeinf_ext) + stop_timing() end $sort_timed_inf($tmin) end @@ -396,6 +399,8 @@ if VERSION >= v"1.2.0-DEV.573" # (the *.ji file stores only the inferred code) precompile(typeinf_ext_timed, (Core.MethodInstance, Core.Compiler.Params)) precompile(typeinf_ext_timed, (Core.MethodInstance, UInt)) + precompile(start_timing, ()) + precompile(stop_timing, ()) nothing end end