Skip to content

Instantly share code, notes, and snippets.

@staticfloat
Last active September 14, 2021 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staticfloat/a123f71ac19c2b4885adbb8aff2f3328 to your computer and use it in GitHub Desktop.
Save staticfloat/a123f71ac19c2b4885adbb8aff2f3328 to your computer and use it in GitHub Desktop.
rr dump analyzer script
using UnicodePlots, Printf
# Dump file generated by `rr dump`
dump_file = ARGS[1]
if !isfile(dump_file)
error("Invalid dump file $(dump_file)")
end
@info("Parsing $(dump_file)....")
events = Dict{String,String}[];
for m in eachmatch(r"^{\W+([^}]+)\W+}$"m, String(read(open(dump_file))))
data = split(m.captures[1])
# Parse out simple report language
tags = Dict{String,String}()
for start_idx in 1:length(data)
if !occursin(":", data[start_idx])
continue
end
end_idx = start_idx
if occursin("`", data[start_idx])
while !occursin("'", data[end_idx])
end_idx += 1
end
end
stv = split(join(data[start_idx:end_idx], " "), ":")
tags[stv[1]] = join(stv[2:end], ":")
end
push!(events, tags)
end
function count_reduce(f::Function, events)
counts = Dict{Any,Int}()
for e in events
r = f(e)
if r !== nothing
if !haskey(counts, r)
counts[r] = 0
end
counts[r] += 1
end
end
return sort([k => v for (k, v) in counts], by=((k, v),) -> v, rev=true)
end
# Print out summary statistics:
event_types = count_reduce(events) do e
return get(e, "event", nothing)
end
@info("Parsed $(length(events)) events")
@info("Top twenty `rr` events by frequency:")
barplot(collect.(collect(zip(event_types[1:20]...)))...)
for idx in 1:10
k, v = event_types[idx]
println("$k => $v")
end
# Analyze event duration
begin
@info("Distribution of event durations")
event_times = map(events) do e
parse(Float64, e["real_time"])
end
event_durations = diff(event_times);
display(histogram(event_durations))
@info("Printing the top 10 events by duration:")
sorted_idxs = sortperm(event_durations, rev=true)[1:10]
for idx in sorted_idxs
@info(@sprintf("Event #%d: (%.3fs) %s", idx, event_durations[idx], events[idx]["event"]))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment