ProfileSVG
ProfileSVG allows you to export profiling data as an SVG file. It can be used to display profiling results in Jupyter/IJulia notebooks, Pluto or any other SVG viewer.
Installation
The package can be installed with the Julia package manager. Run:
import Pkg
Pkg.add("ProfileSVG")
or, from the Julia REPL, type ]
to enter the Pkg REPL mode and run:
pkg> add ProfileSVG
Usage
Displaying profiles
using ProfileSVG
@profview f(args...)
where f(args...)
is the operation you want to profile.
For example:
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
profile_test(1) # run once to compile
using Profile, ProfileSVG
@profview profile_test(10)
Then, you can get something like this:
Note that collected profiles can vary from run-to-run, so don't be alarmed if you get something different.
@profview f(args...)
is just shorthand for
Profile.clear()
@profile f(args...)
ProfileSVG.view()
If you've already collected profiling data with @profile
, or if you want to customize the output, you can call ProfileSVG.view
directly.
VS Code with Julia Extension has a profile viewing feature. On the other hand, you can also display the SVG output of ProfileSVG in the Plot Pane in VS Code. Since @profview
has a name collision with the Julia extension for VS Code, you need to explicitly specify ProfileSVG.@profview
or use ProfileSVG.view
.
Exporting to SVG file
Even if you don't use graphical front-ends such as Jupyter, you might want to export a flame graph as an SVG file as a convenient way to share the results with others. The ProfileSVG.save
function provides the exporting feature.
Profile.clear()
@profile profile_test(10);
# Save a graph that looks like the Jupyter example above
ProfileSVG.save(joinpath("assets", "prof.svg"))
Note that the exported SVG files include the script for interactive features, but some viewers (browsers) do not support the script. In particular, when loading the SVG image from an HTML <img>
element (as above), the interactive features are usually disabled.
Other tools for displaying profiles
- VS Code with Julia extension, a development environment, which supports profile visualization.
- PProf, a web-based profile GUI explorer, implemented as a wrapper around google/pprof.
- ProfileView, a GUI based on Gtk.
- ProfileVega, a Vega-Lite front-end, which supports exporting profiling data as a Vega-Lite figure.