Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update profiler.md for profiler macro run note #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/src/userguide/profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Julia comes with it's own [sampling profiler](https://docs.julialang.org/en/v1/stdlib/Profile/) to measure the CPU time spent in functions or the number and size of allocations. There are [various packages](https://github.com/timholy/FlameGraphs.jl) to visualize these profile traces.

The VS Code extension comes with helpful macros `@profview` and `@profview_allocs` to run these profilers, and its own profile viewer. Profiling the example function from the [ProfileView.jl readme](https://github.com/timholy/ProfileView.jl)

```julia
function profile_test(n)
for i = 1:n
Expand All @@ -21,6 +22,8 @@ end
# pure runtime
@profview profile_test(10)
```
**NOTE:** You must run the `@profview` or `@profview_allocs` macros (and associated function call) in the REPL *in* VS Code. If the REPL terminal window is already open, then you can simply type `@profview profile_test(10)`. Otherwise you can select `Julia: Execute active file in REPL`.

shows a flame graph and inline annotations:
![profiler 1](../images/profiler1.png)

Expand All @@ -44,4 +47,4 @@ The allocation profiler works similarly, but shows you the number of allocations

The menu just above the flame graph allows you to toggle between number and size of allocations.

Note that the optional argument `sample_rate` can be used to adjust the number of samples collected. A sample rate of 1.0 will record everything; 0.0 will record nothing. Use this carefully, as a large value can slow down your code significantly. The default value is 0.0001; if you know that allocations are happening but don't see useful information, increase this value gradually.
Note that the optional argument `sample_rate` can be used to adjust the number of samples collected. A sample rate of 1.0 will record everything; 0.0 will record nothing. Use this carefully, as a large value can slow down your code significantly. The default value is 0.0001; if you know that allocations are happening but don't see useful information, increase this value gradually.
Loading