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

move time_imports and trace_* macros to Base but remain owned by InteractiveUtils #56276

Merged
merged 2 commits into from
Oct 22, 2024
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
35 changes: 35 additions & 0 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,38 @@ macro timed(ex)
)
end
end

# Exported, documented, and tested in InteractiveUtils
# here so it's possible to time/trace all imports, including InteractiveUtils and its deps
macro time_imports(ex)
quote
try
Base.Threads.atomic_add!(Base.TIMING_IMPORTS, 1)
$(esc(ex))
finally
Base.Threads.atomic_sub!(Base.TIMING_IMPORTS, 1)
end
end
end

macro trace_compile(ex)
quote
try
ccall(:jl_force_trace_compile_timing_enable, Cvoid, ())
$(esc(ex))
finally
ccall(:jl_force_trace_compile_timing_disable, Cvoid, ())
end
end
end

macro trace_dispatch(ex)
quote
try
ccall(:jl_force_trace_dispatch_enable, Cvoid, ())
$(esc(ex))
finally
ccall(:jl_force_trace_dispatch_disable, Cvoid, ())
end
end
end
37 changes: 4 additions & 33 deletions stdlib/InteractiveUtils/src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

import Base: typesof, insert!, replace_ref_begin_end!, infer_effects

# defined in Base so it's possible to time all imports, including InteractiveUtils and its deps
# via. `Base.@time_imports` etc.
import Base: @time_imports, @trace_compile, @trace_dispatch

separate_kwargs(args...; kwargs...) = (args, values(kwargs))

"""
Expand Down Expand Up @@ -245,39 +249,6 @@ macro code_lowered(ex0...)
end
end

macro time_imports(ex)
quote
try
Base.Threads.atomic_add!(Base.TIMING_IMPORTS, 1)
$(esc(ex))
finally
Base.Threads.atomic_sub!(Base.TIMING_IMPORTS, 1)
end
end
end

macro trace_compile(ex)
quote
try
ccall(:jl_force_trace_compile_timing_enable, Cvoid, ())
$(esc(ex))
finally
ccall(:jl_force_trace_compile_timing_disable, Cvoid, ())
end
end
end

macro trace_dispatch(ex)
quote
try
ccall(:jl_force_trace_dispatch_enable, Cvoid, ())
$(esc(ex))
finally
ccall(:jl_force_trace_dispatch_disable, Cvoid, ())
end
end
end

"""
@functionloc

Expand Down