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

Allow reentrant Inference profiling. #47260

Closed
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
2 changes: 1 addition & 1 deletion base/compiler/ssair/irinterp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ function _ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IR
end

function ir_abstract_constant_propagation(interp::AbstractInterpreter, irsv::IRInterpretationState)
if __measure_typeinf__[]
if __measure_typeinf()
inf_frame = Timings.InferenceFrameInfo(irsv.mi, irsv.world, Any[], Any[], length(irsv.ir.argtypes))
Timings.enter_new_timer(inf_frame)
v = _ir_abstract_constant_propagation(interp, irsv)
Expand Down
20 changes: 12 additions & 8 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,23 @@ end
return nothing
end

end # module Timings
# Whether or not inference Timing is enabled.
mutable struct TimingInvocations
Core.Compiler.@atomic count::Int
end
const __measuring_typeinf = TimingInvocations(0)

"""
Core.Compiler.__set_measure_typeinf(onoff::Bool)
end # module Timings

If set to `true`, record per-method-instance timings within type inference in the Compiler.
"""
__set_measure_typeinf(onoff::Bool) = __measure_typeinf__[] = onoff
const __measure_typeinf__ = fill(false)
__start_measuring_typeinf() = @atomic Timings.__measuring_typeinf.count += 1
__stop_measuring_typeinf() = @atomic Timings.__measuring_typeinf.count -= 1
__measure_typeinf() = @atomic(Timings.__measuring_typeinf.count) > 0
# DEPRECATED:
__set_measure_typeinf(onoff::Bool) = onoff ? __start_measuring_typeinf() : __stop_measuring_typeinf()

# Wrapper around _typeinf that optionally records the exclusive time for each invocation.
function typeinf(interp::AbstractInterpreter, frame::InferenceState)
if __measure_typeinf__[]
if __measure_typeinf()
Timings.enter_new_timer(frame)
v = _typeinf(interp, frame)
Timings.exit_current_timer(frame)
Expand Down