Skip to content

Commit

Permalink
Simplify inference profiling code using SnoopCompile API itself
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Jan 5, 2023
1 parent 34f506a commit 86e3a24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 9 additions & 10 deletions src/ProfileEndpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Profile
import PProf

using FlameGraphs
using SnoopCompile: InferenceTimingNode
using SnoopCompile
import SnoopCompileCore

using Serialization: serialize

Expand Down Expand Up @@ -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_snoopi_deep()
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_snoopi_deep()
timings = SnoopCompileCore.finish_snoopi_deep()

flame_graph = flamegraph(timings)
prof_name = tempname()
PProf.pprof(flame_graph; out=prof_name, web=false)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86e3a24

Please sign in to comment.