Skip to content

Commit 86e3a24

Browse files
committed
Simplify inference profiling code using SnoopCompile API itself
1 parent 34f506a commit 86e3a24

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ PProf = "e4faabce-9ead-11e9-39d9-4379958e3056"
1010
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
1111
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
1212
SnoopCompile = "aa65fe97-06da-5843-b5b1-d5d13cad87d2"
13+
SnoopCompileCore = "e2b509da-e806-4183-be48-004708413034"
1314

1415
[compat]
1516
HTTP = "1"

src/ProfileEndpoints.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import Profile
55
import PProf
66

77
using FlameGraphs
8-
using SnoopCompile: InferenceTimingNode
8+
using SnoopCompile
9+
import SnoopCompileCore
910

1011
using Serialization: serialize
1112

@@ -249,19 +250,17 @@ end # if isdefined
249250
### Type Inference
250251
###
251252

253+
# WARNING: This is not thread-safe unless your julia has merged
254+
# https://github.com/JuliaLang/julia/pull/47615.
252255
function typeinf_start_endpoint(req::HTTP.Request)
253-
Core.Compiler.__set_measure_typeinf(true)
256+
SnoopCompileCore.start_snoopi_deep()
254257
return HTTP.Response(200, "Type inference profiling started.")
255258
end
256259

257260
function typeinf_stop_endpoint(req::HTTP.Request)
258-
Core.Compiler.__set_measure_typeinf(true)
259-
timings = if isdefined(Core.Compiler.Timings, :clear_and_fetch_timings)
260-
# TODO: make a root node out of this
261-
Core.Compiler.Timings.clear_and_fetch_timings()
262-
else
263-
InferenceTimingNode(Core.Compiler.Timings._timings[1])
264-
end
261+
SnoopCompileCore.stop_snoopi_deep()
262+
timings = SnoopCompileCore.finish_snoopi_deep()
263+
265264
flame_graph = flamegraph(timings)
266265
prof_name = tempname()
267266
PProf.pprof(flame_graph; out=prof_name, web=false)
@@ -310,7 +309,7 @@ function __init__()
310309
precompile(_start_alloc_profile, (Float64,)) || error("precompilation of package functions is not supposed to fail")
311310
precompile(_stop_alloc_profile, ()) || error("precompilation of package functions is not supposed to fail")
312311
end
313-
312+
314313
precompile(typeinf_start_endpoint, (HTTP.Request,)) || error("precompilation of package functions is not supposed to fail")
315314
precompile(typeinf_stop_endpoint, (HTTP.Request,)) || error("precompilation of package functions is not supposed to fail")
316315
end

0 commit comments

Comments
 (0)