From 0f819772ada9469df2457162696d540bcc63e5d9 Mon Sep 17 00:00:00 2001 From: Nathan Daly Date: Thu, 5 Jan 2023 14:30:36 -0700 Subject: [PATCH] Simplify inference profiling code using SnoopCompile API itself --- Project.toml | 1 + src/ProfileEndpoints.jl | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index 2cf344c..362d32a 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ PProf = "e4faabce-9ead-11e9-39d9-4379958e3056" Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" SnoopCompile = "aa65fe97-06da-5843-b5b1-d5d13cad87d2" +SnoopCompileCore = "e2b509da-e806-4183-be48-004708413034" [compat] HTTP = "1" diff --git a/src/ProfileEndpoints.jl b/src/ProfileEndpoints.jl index 04827d2..92beded 100644 --- a/src/ProfileEndpoints.jl +++ b/src/ProfileEndpoints.jl @@ -5,7 +5,8 @@ import Profile import PProf using FlameGraphs -using SnoopCompile: InferenceTimingNode +using SnoopCompile +import SnoopCompileCore using Serialization: serialize @@ -249,19 +250,17 @@ end # if isdefined ### Type Inference ### +# WARNING: This is not thread-safe unless your julia has merged +# https://github.com/JuliaLang/julia/pull/47615. function typeinf_start_endpoint(req::HTTP.Request) - Core.Compiler.__set_measure_typeinf(true) + SnoopCompileCore.start_deep_timing() return HTTP.Response(200, "Type inference profiling started.") end function typeinf_stop_endpoint(req::HTTP.Request) - Core.Compiler.__set_measure_typeinf(true) - timings = if isdefined(Core.Compiler.Timings, :clear_and_fetch_timings) - # TODO: make a root node out of this - Core.Compiler.Timings.clear_and_fetch_timings() - else - InferenceTimingNode(Core.Compiler.Timings._timings[1]) - end + SnoopCompileCore.stop_deep_timing() + timings = SnoopCompileCore.finish_snoopi_deep() + flame_graph = flamegraph(timings) prof_name = tempname() PProf.pprof(flame_graph; out=prof_name, web=false) @@ -310,7 +309,7 @@ function __init__() precompile(_start_alloc_profile, (Float64,)) || error("precompilation of package functions is not supposed to fail") precompile(_stop_alloc_profile, ()) || error("precompilation of package functions is not supposed to fail") end - + precompile(typeinf_start_endpoint, (HTTP.Request,)) || error("precompilation of package functions is not supposed to fail") precompile(typeinf_stop_endpoint, (HTTP.Request,)) || error("precompilation of package functions is not supposed to fail") end