From 7694c1f524def2dfa69525d30b100af191093a38 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 3 Mar 2023 01:27:20 -0600 Subject: [PATCH] Switch to SnoopPrecompile (#209) --- Project.toml | 4 +++- src/ProfileView.jl | 38 +++++++++++++++++++++++++++++++++++--- src/precompile.jl | 33 --------------------------------- 3 files changed, 38 insertions(+), 37 deletions(-) delete mode 100644 src/precompile.jl diff --git a/Project.toml b/Project.toml index 37bb2e2..95d470a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ProfileView" uuid = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7" author = ["Tim Holy "] -version = "1.5.2" +version = "1.6.0" [deps] Cairo = "159f3aea-2a34-519c-b102-8c37f9878175" @@ -17,6 +17,7 @@ IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" MethodAnalysis = "85b6ec6f-f7df-4429-9514-a64bcd9ee824" Preferences = "21216c6a-2e73-6563-6e65-726566657250" Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" +SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] @@ -30,6 +31,7 @@ GtkObservables = "1" IntervalSets = "0.2, 0.3, 0.4, 0.5, 0.6, 0.7" MethodAnalysis = "0.4" Preferences = "1.2" +SnoopPrecompile = "1" julia = "1.6" [extras] diff --git a/src/ProfileView.jl b/src/ProfileView.jl index 3df9a8f..a3364a7 100644 --- a/src/ProfileView.jl +++ b/src/ProfileView.jl @@ -506,9 +506,41 @@ end discardfirstcol(A) = A[:,2:end] discardfirstcol(A::IndirectArray) = IndirectArray(A.index[:,2:end], A.values) -if ccall(:jl_generating_output, Cint, ()) == 1 - include("precompile.jl") - _precompile_() +using SnoopPrecompile + +let + @precompile_setup begin + stackframe(func, file, line; C=false) = StackFrame(Symbol(func), Symbol(file), line, nothing, C, false, 0) + + backtraces = UInt64[0, 4, 3, 2, 1, # order: calles then caller + 0, 6, 5, 1, + 0, 8, 7, + 0, 4, 3, 2, 1, + 0] + if isdefined(Profile, :add_fake_meta) + backtraces = Profile.add_fake_meta(backtraces) + end + lidict = Dict{UInt64,StackFrame}(1=>stackframe(:f1, :file1, 1), + 2=>stackframe(:f2, :file1, 5), + 3=>stackframe(:f3, :file2, 1), + 4=>stackframe(:f2, :file1, 15), + 5=>stackframe(:f4, :file1, 20), + 6=>stackframe(:f5, :file3, 1), + 7=>stackframe(:f1, :file1, 2), + 8=>stackframe(:f6, :file3, 10)) + @precompile_all_calls begin + g = flamegraph(backtraces; lidict=lidict) + gdict = Dict(tabname_allthreads => Dict(tabname_alltasks => g)) + win, c, fdraw = viewgui(FlameGraphs.default_colors, gdict) + for obs in c.preserved + if isa(obs, Observable) || isa(obs, Observables.ObserverFunction) + precompile(obs) + end + end + precompile(fdraw) + closeall() # necessary to prevent serialization of stale references (including the internal `empty!`) + end + end end end diff --git a/src/precompile.jl b/src/precompile.jl deleted file mode 100644 index d1f8ccd..0000000 --- a/src/precompile.jl +++ /dev/null @@ -1,33 +0,0 @@ -function _precompile_() - stackframe(func, file, line; C=false) = StackFrame(Symbol(func), Symbol(file), line, nothing, C, false, 0) - backtraces = UInt64[0, 4, 3, 2, 1, # order: calles then caller - 0, 6, 5, 1, - 0, 8, 7, - 0, 4, 3, 2, 1, - 0] - if isdefined(Profile, :add_fake_meta) - backtraces = Profile.add_fake_meta(backtraces) - end - lidict = Dict{UInt64,StackFrame}(1=>stackframe(:f1, :file1, 1), - 2=>stackframe(:f2, :file1, 5), - 3=>stackframe(:f3, :file2, 1), - 4=>stackframe(:f2, :file1, 15), - 5=>stackframe(:f4, :file1, 20), - 6=>stackframe(:f5, :file3, 1), - 7=>stackframe(:f1, :file1, 2), - 8=>stackframe(:f6, :file3, 10)) - g = flamegraph(backtraces; lidict=lidict) - gdict = Dict(tabname_allthreads => Dict(tabname_alltasks => g)) - win, c, fdraw = viewgui(FlameGraphs.default_colors, gdict) - for obs in c.preserved - if isa(obs, Observable) || isa(obs, Observables.ObserverFunction) - precompile(obs) - end - end - precompile(fdraw) - closeall() # necessary to prevent serialization of stale references (including the internal `empty!`) - precompile(viewprof_func, (FlameColors, GtkObservables.Canvas{GtkObservables.UserUnit}, FlameGraphs.LeftChildRightSiblingTrees.Node{FlameGraphs.NodeData}, Int)) - precompile(Tuple{typeof(save_as_cb),Ptr{GObject},Tuple{Gtk.GtkCanvas, Vector{UInt64}, Dict{UInt64, Vector{StackFrame}}}}) # time: 0.008177923 - precompile(Tuple{typeof(save_as_cb),Ptr{GObject},Tuple{Gtk.GtkCanvas, Nothing, Nothing}}) - precompile(warntype_last, ()) -end