From 3e19101bb58c3e9e7e370186981579891c6e91c6 Mon Sep 17 00:00:00 2001 From: Pete Vilter Date: Mon, 21 Nov 2022 19:35:10 -0500 Subject: [PATCH] make precompile work in old case --- SnoopPrecompile/src/SnoopPrecompile.jl | 29 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/SnoopPrecompile/src/SnoopPrecompile.jl b/SnoopPrecompile/src/SnoopPrecompile.jl index 1c5e1ace..1370ec69 100644 --- a/SnoopPrecompile/src/SnoopPrecompile.jl +++ b/SnoopPrecompile/src/SnoopPrecompile.jl @@ -59,14 +59,29 @@ macro precompile_all_calls(ex::Expr) end end if have_inference_tracking - ex = quote - Core.Compiler.__set_measure_typeinf(true) - try - $ex - finally - Core.Compiler.__set_measure_typeinf(false) + ex = if isdefined(Core.Compiler.Timings, :clear_and_fetch_timings) + # use new thread-safe timings API if it's available in this version of Julia + 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 + 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.clear_and_fetch_timings()) end end return esc(quote