Skip to content

Instantly share code, notes, and snippets.

@vchuravy
Created March 18, 2023 19:42
Show Gist options
  • Save vchuravy/c2012c8cef577cc6f828fdc5b02e959a to your computer and use it in GitHub Desktop.
Save vchuravy/c2012c8cef577cc6f828fdc5b02e959a to your computer and use it in GitHub Desktop.
Analyze code loads
using JSON3
jitdump = open(JSON3.read, "/home/vchuravy/Downloads/jitdump.json")
pmap = readlines("/home/vchuravy/Downloads/process_map.txt")
struct AddrRange
start::UInt
fin::UInt
end
function AddrRange(s::AbstractString)
start, fin = split(s, '-')
start = parse(UInt, start, base=16)
fin = parse(UInt, fin, base=16)
return AddrRange(start, fin)
end
struct Mapping
addr::AddrRange
mode::String
file::Union{Nothing, String}
end
mappings = Mapping[]
for line in pmap
entry = split(line)
if length(entry) == 6
addr_range, mode, _, _, _, file = entry
else
addr_range, mode, _, _, _ = entry
file = nothing
end
push!(mappings, Mapping(AddrRange(addr_range), mode, file))
end
sort!(mappings, by=m->m.addr.start)
Base.in(addr::UInt, range::AddrRange) = range.start <= addr < range.fin
hist = Dict{Mapping, Vector{Dict}}()
for load in jitdump[:CodeLoads]
addr = UInt(load["CodeAddr"])
idx = findfirst(m->in(addr, m.addr), mappings)
if idx === nothing
@info "Load not part of mappings" load
end
map = mappings[idx]
loads = get!(hist, map) do
Dict[]
end
push!(loads, load)
end
@show sum(length, values(hist))
@show length(jitdump[:CodeLoads])
@show collect(keys(hist))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment