Skip to content

Commit

Permalink
Implement blacklist removal in snoopi parcel (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored and timholy committed Jan 15, 2020
1 parent 6ad1d8c commit 6c96ca6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/parcel_snoopi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ function handle_kwbody(topmod::Module, m::Method, paramrepr, tt, fstr="fbody")
return nothing
end


function parcel(tinf::AbstractVector{Tuple{Float64,Core.MethodInstance}}; subst=Vector{Pair{String, String}}(), blacklist=String[])
pc = Dict{Symbol, Vector{String}}() # output
modgens = Dict{Module, Vector{Method}}() # methods with generators in a module
Expand Down Expand Up @@ -227,6 +226,10 @@ function parcel(tinf::AbstractVector{Tuple{Float64,Core.MethodInstance}}; subst=
# Use special care with keyword functions, anonymous functions
p = tt.parameters[1] # the portion of the signature related to the function itself
paramrepr = map(T->reprcontext(topmod, T), Iterators.drop(tt.parameters, 1)) # all the rest of the args

# blacklist remover
pc[topmodname] = blacklist_remover!(pc[topmodname], blacklist)

if any(str->occursin('#', str), paramrepr)
@debug "Skipping $tt due to argument types having anonymous bindings"
continue
Expand Down Expand Up @@ -297,3 +300,25 @@ function parcel(tinf::AbstractVector{Tuple{Float64,Core.MethodInstance}}; subst=
end
return pc
end

"""
Search and removes blacklist from pcI
# Examples
```julia
blacklist = ["hi","bye"]
pcI = ["good","bad","hi","bye","no"]
SnoopCompile.blacklist_remover!(pcI, blacklist)
```
"""
function blacklist_remover!(pcI, blacklist)
idx = Int[]
for (iLine, line) in enumerate(pcI)
if any(occursin.(blacklist, line))
push!(idx, iLine)
end
end
deleteat!(pcI, idx)
return pcI
end
5 changes: 5 additions & 0 deletions test/snoopi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ uncompiled(x) = x + 1
pc = SnoopCompile.parcel(tinf)
FK = pc[:FuncKinds]
@test any(str->match(r"isdefined.*#inner#", str) !== nothing, FK)

# blacklist_remover
blacklist = ["hi", "bye"]
pcI = ["good", "bad", "hi", "bye", "no"]
@test SnoopCompile.blacklist_remover!(pcI, blacklist) == ["good", "bad", "no"]
end

@testset "Lots of methods" begin
Expand Down

0 comments on commit 6c96ca6

Please sign in to comment.