# ProfileSVG

ProfileSVG allows you to export profiling data as an SVG file. It can be used to display profiling results in Jupyter/IJulia notebooks, Juno 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.

### 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.