Skip to content

Commit ed58b07

Browse files
authored
add Profile.Allocs.@pprof (#92)
1 parent 916be01 commit ed58b07

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/Allocs.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,23 @@ function pprof(alloc_profile::Profile.Allocs.AllocResults = Profile.Allocs.fetch
223223
out
224224
end
225225

226+
"""
227+
Allocs.@pprof args...
228+
229+
Profiles the expression using `Allocs.@profile` and starts or restarts the `Allocs.pprof()` web UI with
230+
default arguments. See also [`PProf.@pprof`](@ref).
231+
232+
# Examples
233+
```julia
234+
PProf.Allocs.@pprof [randn(3) for _ in 1:100000]
235+
PProf.Allocs.@pprof sample_rate=1 randn(100)
236+
```
237+
"""
238+
macro pprof(args...)
239+
esc(quote
240+
$Profile.Allocs.@profile $(args...)
241+
$(@__MODULE__).pprof()
242+
end)
243+
end
244+
226245
end # module Allocs

src/PProf.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ end
399399
@pprof ex
400400
401401
Profiles the expression using `@profile` and starts or restarts the `pprof()` web UI with
402-
default arguments.
402+
default arguments. See also [`PProf.Allocs.@pprof`](@ref).
403403
"""
404404
macro pprof(ex)
405405
esc(quote

test/Allocs.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ using Test
99

1010
const out = tempname()
1111

12+
@testset "PProf.Allocs.@pprof" begin
13+
Profile.Allocs.clear()
14+
rm("alloc-profile.pb.gz", force=true)
15+
@assert !isfile("alloc-profile.pb.gz")
16+
PProf.Allocs.@pprof sample_rate=1.0 randn(100)
17+
@test isfile("alloc-profile.pb.gz")
18+
19+
Profile.Allocs.clear()
20+
rm("alloc-profile.pb.gz", force=true)
21+
@assert !isfile("alloc-profile.pb.gz")
22+
PProf.Allocs.@pprof randn(100)
23+
@test isfile("alloc-profile.pb.gz")
24+
25+
rm("alloc-profile.pb.gz", force=true)
26+
end
27+
28+
1229
@testset "basic profiling" begin
1330
Profile.Allocs.clear()
1431
Profile.Allocs.@profile sample_rate=1.0 begin

0 commit comments

Comments
 (0)