pfitzseb / ProfileCanvas.jl

MIT License
87 stars 6 forks source link

ProfileCanvas CI version

This package is intended as a drop-in replacement for ProfileView.jl and ProfileSVG.jl.

It exposes the HTML canvas based profile viewer UI used by the Julia extension for VS Code in the REPL and environments that can display HTML (like Pluto notebooks). Performance should be significantly better than SVG-based solutions, especially for very large traces.

Usage

using ProfileCanvas
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

@profview profile_test(1)  # run once to trigger compilation (ignore this one)
@profview profile_test(10)

On Julia 1.8 and newer you can also use profiler memory allocations with @profview_allocs/view_allocs:

@profview_allocs profile_test(10)

The controls are mouse wheel to scroll, and click on a cell to base the zoom on it. The end result depends on the julia version, but it might be something like this:

when run from the REPL and

in a Pluto notebook.

Color coding

The profiling data is color-coded to provide insights about the performance of your code: