Skip to content

Commit

Permalink
Less redundancy in printing
Browse files Browse the repository at this point in the history
Strips out annoying `MethodInstance` and `InferenceFrameInfo` markers.
  • Loading branch information
timholy committed Jul 23, 2021
1 parent b0def13 commit df8a8a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
24 changes: 17 additions & 7 deletions src/parcel_snoopi_deep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ lookups_key(ip::Ptr{Nothing}) = UInt(ip)
Base.show(io::IO, t::InferenceTiming) = (print(io, "InferenceTiming: "); _show(io, t))
function _show(io::IO, t::InferenceTiming)
print(io, @sprintf("%8.6f", exclusive(t)), "/", @sprintf("%8.6f", inclusive(t)), " on ")
print(io, t.mi_info)
print(io, stripifi(t.mi_info))
end

function Base.show(io::IO, node::InferenceTimingNode)
Expand Down Expand Up @@ -610,7 +610,7 @@ end

function Base.show(io::IO, itrig::InferenceTrigger)
print(io, "Inference triggered to call ")
printstyled(io, MethodInstance(itrig.node); color=:yellow)
printstyled(io, stripmi(MethodInstance(itrig.node)); color=:yellow)
if !isempty(itrig.callerframes)
sf = first(itrig.callerframes)
print(io, " from ")
Expand All @@ -619,7 +619,7 @@ function Base.show(io::IO, itrig::InferenceTrigger)
caller = itrig.callerframes[end].linfo
if isa(caller, MethodInstance)
length(itrig.callerframes) == 1 ? print(io, " with specialization ") : print(io, " inlined into ")
printstyled(io, caller; color=:blue)
printstyled(io, stripmi(caller); color=:blue)
if length(itrig.callerframes) > 1
sf = itrig.callerframes[end]
print(io, " (", sf.file, ':', sf.line, ')')
Expand Down Expand Up @@ -912,7 +912,7 @@ function AbstractTrees.printnode(io::IO, node::TriggerNode)
if node.itrig === nothing
print(io, "root")
else
print(io, MethodInstance(node.itrig.node))
print(io, stripmi(MethodInstance(node.itrig.node)))
end
end

Expand Down Expand Up @@ -1244,7 +1244,7 @@ function show_suggest(io::IO, categories, rtcallee, sf)
end
if isempty(categories) || categories [FromTestDirect, FromTestCallee, CallerVararg, CalleeVararg, CallerInlineable]
printstyled(io, "Unspecialized or unknown"; color=:cyan)
print(io, " for ", rtcallee, " consider `stacktrace(itrig)` or `ascend(itrig)` to investigate more deeply")
print(io, " for ", stripmi(rtcallee), " consider `stacktrace(itrig)` or `ascend(itrig)` to investigate more deeply")
showcaller = false
end
end
Expand All @@ -1254,9 +1254,9 @@ function show_suggest(io::IO, categories, rtcallee, sf)
end
if showannotate
if CallerVararg categories
print(io, ", ignore or perhaps annotate ", sf, " with type ", rtcallee)
print(io, ", ignore or perhaps annotate ", sf, " with result type of ", stripmi(rtcallee))
else
print(io, ", perhaps annotate ", sf, " with type ", rtcallee)
print(io, ", perhaps annotate ", sf, " with result type of ", stripmi(rtcallee))
end
print(io, "\nIf a noninferrable argument is a type or function, Julia's specialization heuristics may be responsible.")
end
Expand Down Expand Up @@ -1646,6 +1646,16 @@ end

Base.show(io::IO, node::SuggestNode) = print_tree(io, node)

function strip_prefix(io::IO, obj, prefix)
print(io, obj)
str = String(take!(io))
return startswith(str, prefix) ? str[length(prefix)+1:end] : str
end
strip_prefix(obj, prefix) = strip_prefix(IOBuffer(), obj, prefix)

stripmi(args...) = strip_prefix(args..., "MethodInstance for ")
stripifi(args...) = strip_prefix(args..., "InferenceFrameInfo for ")

## Flamegraph creation

"""
Expand Down
12 changes: 6 additions & 6 deletions test/snoopi_deep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fdouble(x) = 2x
io = IOBuffer()
show(io, itrig)
str = String(take!(io))
@test occursin(r"MethodInstance for .*myplus.*\(::UInt8, ::Float16\)", str)
@test occursin(r".*myplus.*\(::UInt8, ::Float16\)", str)
@test occursin("from g", str)
@test occursin(r"with specialization .*::Vector\{Float64\}", str)
mis = callerinstance.(itrigs)
Expand Down Expand Up @@ -174,9 +174,9 @@ fdouble(x) = 2x
itrig = only(itrigs)
show(io, itrig)
str = String(take!(io))
@test occursin(r"to call MethodInstance for .*callee.*\(::UInt8\)", str)
@test occursin(r"to call .*callee.*\(::UInt8\)", str)
@test occursin("from caller", str)
@test occursin(r"inlined into MethodInstance for .*callercaller.*\(::Vector{Vector{Any}}\)", str)
@test occursin(r"inlined into .*callercaller.*\(::Vector{Vector{Any}}\)", str)
s = suggest(itrig)
@test !isignorable(s)
print(io, s)
Expand Down Expand Up @@ -254,9 +254,9 @@ fdouble(x) = 2x
@test isempty(staleinstances(tinf))
itrigs = inference_triggers(tinf)
itrig = only(itrigs)
@test occursin(r"with specialization MethodInstance for .*mymap!.*\(::.*fdouble.*, ::Vector{Any}, ::Vector{Any}\)", string(itrig))
@test occursin(r"with specialization MethodInstance for .*mymap.*\(::.*fdouble.*, ::Vector{Any}\)", string(callingframe(itrig)))
@test occursin(r"with specialization MethodInstance for .*callmymap.*\(::Vector{Any}\)", string(skiphigherorder(itrig)))
@test occursin(r"with specialization .*mymap!.*\(::.*fdouble.*, ::Vector{Any}, ::Vector{Any}\)", string(itrig))
@test occursin(r"with specialization .*mymap.*\(::.*fdouble.*, ::Vector{Any}\)", string(callingframe(itrig)))
@test occursin(r"with specialization .*callmymap.*\(::Vector{Any}\)", string(skiphigherorder(itrig)))
# Ensure we don't skip non-higher order calls
callfdouble(c) = fdouble(c[1])
callfdouble(Any[1])
Expand Down

0 comments on commit df8a8a6

Please sign in to comment.