Skip to content

Commit

Permalink
Update profiler.md for profiler macro run note
Browse files Browse the repository at this point in the history
Added a note in the profiler documentation that the profiler macros must be run from the REPL and not from a new environment.
  • Loading branch information
ubertakter authored Sep 10, 2024
1 parent 471e76f commit 00749b3
Showing 1 changed file with 4 additions and 1 deletion.
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.

0 comments on commit 00749b3

Please sign in to comment.