Skip to content

Commit bda9970

Browse files
committed
Add filtermod for triggers
1 parent 9e38ccc commit bda9970

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/parcel_snoopi_deep.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,14 @@ Return the MethodInstance `mi` of the caller in the selected stackframe in `itri
644644
"""
645645
callerinstance(itrig::InferenceTrigger) = itrig.callerframes[end].linfo
646646

647+
function callermodule(itrig::InferenceTrigger)
648+
if !isempty(itrig.callerframes)
649+
m = callerinstance(itrig).def
650+
return isa(m, Module) ? m : m.module
651+
end
652+
return nothing
653+
end
654+
647655
# Select the next (caller) frame that's a Julia (as opposed to C) frame; returns the stackframe and its index in bt, or nothing
648656
function next_julia_frame(bt, idx, Δ=1; methodinstanceonly::Bool=true, methodonly::Bool=true)
649657
while 1 <= idx+Δ <= length(bt)
@@ -856,6 +864,8 @@ Cthulhu.specTypes(itrig::InferenceTrigger) = Cthulhu.specTypes(Cthulhu.instance(
856864
Cthulhu.backedges(itrig::InferenceTrigger) = (itrig.callerframes,)
857865
Cthulhu.nextnode(itrig::InferenceTrigger, edge) = (ret = callingframe(itrig); return isempty(ret.callerframes) ? nothing : ret)
858866

867+
filtermod(mod::Module, itrigs::AbstractVector{InferenceTrigger}) = filter(==(mod) callermodule, itrigs)
868+
859869
### inference trigger trees
860870
# good for organizing into "events"
861871

@@ -1010,6 +1020,10 @@ function accumulate_by_source(itrigs::AbstractVector{InferenceTrigger})
10101020
return sort([LocationTrigger(loc, itrigs_loc) for ((loc, _), itrigs_loc) in cs]; by=loctrig->length(loctrig.itrigs))
10111021
end
10121022

1023+
filtermod(mod::Module, loctrigs::AbstractVector{LocationTrigger}) = filter(loctrigs) do loctrig
1024+
any(==(mod) callermodule, loctrig.itrigs)
1025+
end
1026+
10131027
function linetable_match(linetable::Vector{Core.LineInfoNode}, sffile::String, sffunc::String, sfline::Int)
10141028
idxs = Int[]
10151029
for (idx, line) in enumerate(linetable)

test/snoopi_deep.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ fdouble(x) = 2x
124124
@test occursin("myplus", string(MethodInstance(itrigs[2].node).def.name))
125125
itrigs = inference_triggers(tinf)
126126
itrig = only(itrigs)
127+
@test filtermod(@__MODULE__, itrigs) == [itrig]
128+
@test isempty(filtermod(Base, itrigs))
127129
io = IOBuffer()
128130
show(io, itrig)
129131
str = String(take!(io))
@@ -191,6 +193,8 @@ fdouble(x) = 2x
191193
loctrigs = accumulate_by_source(itrigs)
192194
show(io, loctrigs)
193195
@test any(str->occursin("4 callees from 2 callers", str), split(String(take!(io)), '\n'))
196+
@test filtermod(Base, loctrigs) == loctrigs
197+
@test isempty(filtermod(@__MODULE__, loctrigs))
194198

195199
# Multiple callees on the same line
196200
fline(x) = 2*x[]

0 commit comments

Comments
 (0)