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

add PProf.Allocs.@pprof #92

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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
Loading