Skip to content

Commit

Permalink
add Profile.Allocs.@pprof
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 authored and vchuravy committed Sep 10, 2024
1 parent 491a7fe commit 4ca271c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,23 @@ function pprof(alloc_profile::Profile.Allocs.AllocResults = Profile.Allocs.fetch
out
end

"""
Allocs.@pprof args...
Profiles the expression using `Allocs.@profile` and starts or restarts the `Allocs.pprof()` web UI with
default arguments. See also [`PProf.@pprof`](@ref).
# Examples
```julia
PProf.Allocs.@pprof [randn(3) for _ in 1:100000]
PProf.Allocs.@pprof sample_rate=1 randn(100)
```
"""
macro pprof(args...)
esc(quote
$Profile.Allocs.@profile $(args...)
$(@__MODULE__).pprof()
end)
end

end # module Allocs
2 changes: 1 addition & 1 deletion src/PProf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ end
@pprof ex
Profiles the expression using `@profile` and starts or restarts the `pprof()` web UI with
default arguments.
default arguments. See also [`PProf.Allocs.@pprof`](@ref).
"""
macro pprof(ex)
esc(quote
Expand Down
17 changes: 17 additions & 0 deletions test/Allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ using Test

const out = tempname()

@testset "PProf.Allocs.@pprof" begin
Profile.Allocs.clear()
rm("alloc-profile.pb.gz", force=true)
@assert !isfile("alloc-profile.pb.gz")
PProf.Allocs.@pprof sample_rate=1.0 randn(100)
@test isfile("alloc-profile.pb.gz")

Profile.Allocs.clear()
rm("alloc-profile.pb.gz", force=true)
@assert !isfile("alloc-profile.pb.gz")
PProf.Allocs.@pprof randn(100)
@test isfile("alloc-profile.pb.gz")

rm("alloc-profile.pb.gz", force=true)
end


@testset "basic profiling" begin
Profile.Allocs.clear()
Profile.Allocs.@profile sample_rate=1.0 begin
Expand Down

0 comments on commit 4ca271c

Please sign in to comment.