Skip to content

Instantly share code, notes, and snippets.

@NHDaly
Last active August 25, 2020 13:43
Show Gist options
  • Save NHDaly/c844ff3224e1fb9ca53eed30a2ffb402 to your computer and use it in GitHub Desktop.
Save NHDaly/c844ff3224e1fb9ca53eed30a2ffb402 to your computer and use it in GitHub Desktop.
using CSV
#using UnicodePlots
"""
plot_snoopl(func_csv_file, llvm_csv_file; out_csv_path="")
Print a barplot to stdout, optionally output a CSV file with the results, and return a
table with the results.
# Example
```
julia> times = plot_snoopl("func_info.csv", "llvm_timings.csv", out_csv_path="/tmp/timings.csv");
```
"""
function plot_snoopl(func_csv_file, llvm_csv_file; out_csv_path="")
func_csv = CSV.File(func_csv_file, header=false)
llvm_csv = CSV.File(llvm_csv_file, header=false)
f_names = Dict(r[1] => r[2] for r in func_csv)
llvm_names = Dict{Int,Vector{String}}()
llvm_times = Dict{Int,Int}()
llvm_instructions = Dict{Tuple{Int,String}, Int}()
for (e,a,v) in llvm_csv
i = e::Int
if a === "name"
name = v::String
if name in keys(f_names)
jl_name = f_names[name]
else
@warn "Couldn't find $name"
jl_name = name
end
push!(get!(llvm_names, i, []), jl_name)
elseif a === "time_ns"
time = parse(Int, v)
llvm_times[i] = time
elseif startswith(a, "before/instructions:")
llvm_name = a[length("before/instructions:")+1:end]
llvm_instructions[(i,llvm_name)] = parse(Int, v)
else
error("Unexpected Attribute name: $a")
end
end
# Sort the arrays of funcs per LLVM Module by number of instructions
for (k,v) in llvm_names
sort!(v, by=last, rev=true)
end
# Construct a barplot, sorted by LLVM_OPT time
times = sort([
# We use get() to support modules that have no names for some reason...
get(llvm_names, i, String[]) =>
llvm_times[i]/1e9 for i in keys(llvm_times)
], by=last)
#display(barplot(string.(first.(times)), collect(last.(times))))
tt = CSV.Tables.table([row[j] for row in times, j in 1:2], header=[Symbol("Methods and Instruction Counts"), Symbol("Time (secs)")])
if !isempty(out_csv_path)
CSV.write(out_csv_path, tt)
end
tt
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment