Skip to content

Profile: remove scope from profile macros #57858

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

Merged
merged 2 commits into from
Mar 25, 2025
Merged
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
6 changes: 3 additions & 3 deletions stdlib/Profile/src/Allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ end
function _prof_expr(expr, opts)
quote
$start(; $(esc(opts)))
try
Base.@__tryfinally(
$(esc(expr))
finally
,
$stop()
end
)
end
end

Expand Down
16 changes: 8 additions & 8 deletions stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ appended to an internal buffer of backtraces.
"""
macro profile(ex)
return quote
try
start_timer()
start_timer()
Base.@__tryfinally(
$(esc(ex))
finally
,
stop_timer()
end
)
end
end

Expand All @@ -78,12 +78,12 @@ it can be used to diagnose performance issues such as lock contention, IO bottle
"""
macro profile_walltime(ex)
return quote
try
start_timer(true)
start_timer(true);
Base.@__tryfinally(
$(esc(ex))
finally
,
stop_timer()
end
)
end
end

Expand Down
14 changes: 14 additions & 0 deletions stdlib/Profile/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ end
@test z == 10
end

@testset "@profile no scope" begin
@profile no_scope_57858_1 = 1
@test @isdefined no_scope_57858_1
Profile.clear()

@profile_walltime no_scope_57858_1 = 1
@test @isdefined no_scope_57858_1
Profile.clear()

Profile.Allocs.@profile no_scope_57858_2 = 1
@test @isdefined no_scope_57858_2
Profile.Allocs.clear()
end

@testset "setting sample count and delay in init" begin
n_, delay_ = Profile.init()
n_original = n_
Expand Down