pfitzseb / ProfileCanvas.jl

MIT License
88 stars 6 forks source link

Add support for inference flame graphs #25

Open charleskawczynski opened 2 years ago

charleskawczynski commented 2 years ago

It would be nice if ProfileCanvas could handle flame graphs created from SnoopCompile with @snoopi_deep:

function profile_test(n)
    for i = 1:n
        A = randn(100,100,20)
        m = maximum(A)
        Am = mapslices(sum, A; dims=2)
        B = A[:,:,5]
        Bsort = mapslices(sort, B; dims=1)
        b = rand(100)
        C = B.*b
    end
end

using SnoopCompile
import Profile
Profile.clear_malloc_data()
Profile.clear()
tinf = @snoopi_deep begin
    profile_test(10)
end

@show tinf

using FlameGraphs
fg = flamegraph(tinf)
using ProfileCanvas
ProfileCanvas.view(fg)

This breaks with

ProfileCanvas.view(fg)
ERROR: MethodError: no method matching getdict(::Vector{LeftChildRightSiblingTrees.Node{FlameGraphs.NodeData}})
Closest candidates are:
  getdict(::Vector{UInt64}) at /Applications/Julia-1.8.app/Contents/Resources/julia/share/julia/stdlib/v1.8/Profile/src/Profile.jl:419
Stacktrace:
 [1] #view#6
   @ ~/.julia/packages/ProfileCanvas/qoJ8w/src/ProfileCanvas.jl:143 [inlined]
 [2] view(data::LeftChildRightSiblingTrees.Node{FlameGraphs.NodeData})
   @ ProfileCanvas ~/.julia/packages/ProfileCanvas/qoJ8w/src/ProfileCanvas.jl:129
 [3] top-level scope
   @ REPL[22]:1