Skip to content

Commit 2baa342

Browse files
authored
Merge pull request #86 from moble/profview_allocs
Document @profview_allocs
2 parents fac504c + b4feeea commit 2baa342

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/src/images/profiler4.png

420 KB
Loading

docs/src/userguide/profiler.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Profiling code
22

3-
Julia comes with it's own [sampling profiler](https://docs.julialang.org/en/v1/stdlib/Profile/) and there are [various packages](https://github.com/timholy/FlameGraphs.jl) to visualize these profile traces.
3+
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.
44

5-
The VS Code extension comes with it's own profile viewer. Profiling the example function from the [ProfileView.jl readme](https://github.com/timholy/ProfileView.jl)
5+
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)
66
```julia
77
function profile_test(n)
88
for i = 1:n
@@ -33,3 +33,15 @@ The tooltip will tell you the number of samples collect in a certain frame as we
3333
The inline view shows you how much of the parent frame's samples originate on which line (and also the flags, as above, when hovering over the start of the inline annotation):
3434

3535
![inline](../images/profiler3.png)
36+
37+
The allocation profiler works similarly, but shows you the number of allocations or size of allocations instead of the time spent in a function:
38+
39+
```julia
40+
@profview_allocs profile_test(10) sample_rate=0.1
41+
```
42+
43+
![allocations](../images/profiler4.png)
44+
45+
The menu just above the flame graph allows you to toggle between number and size of allocations.
46+
47+
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 commit comments

Comments
 (0)