Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge integration of Malt.jl #41

Merged
merged 15 commits into from
May 20, 2024
13 changes: 10 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,32 @@ version = "0.2.0"
[deps]
CoverageTools = "c36e975a-824b-4404-a568-ef97ca766997"
CpuId = "adafc99b-e345-5852-983c-f28acb93d879"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Malt = "36869731-bdee-424d-aa32-cab38c994e3b"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"

[weakdeps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Chairmarks = "0ca39b1e-fe0b-4e98-acfc-b1656634c4de"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
BenchmarkToolsExt = "BenchmarkTools"
CSVExt = "CSV"
ChairmarksExt = "Chairmarks"
MakieExt = "Makie"

[compat]
BenchmarkTools = "1.5"
Chairmarks = "1.2"
CoverageTools = "1"
CSV = "0.10"
Chairmarks = "1"
CoverageTools = "1.3.1"
CpuId = "0.3.1"
Makie = "0.21"
Malt = "1.1.1"
TypedTables = "1"
julia = "1.9"

Expand Down
5 changes: 4 additions & 1 deletion ext/BenchmarkToolsExt/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ function PerfChecker.default_options(::Val{:benchmark})
)
end

PerfChecker.initpkgs(::Val{:benchmark}) = quote
using BenchmarkTools
end

function PerfChecker.check(d::Dict, block::Expr, ::Val{:benchmark})
quote
d = $d
using BenchmarkTools
return @benchmark $block samples=d[:samples] seconds=d[:seconds] evals=d[:evals] overhead=d[:overhead] gctrial=d[:gctrial] gcsample=d[:gcsample] time_tolerance=d[:time_tolerance] memory_tolerance=d[:memory_tolerance]
end
end
Expand Down
10 changes: 10 additions & 0 deletions ext/CSVExt/CSVExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module CSVExt

using CSV
import TypedTables: Table

table_to_csv(t::Table, path::String) = CSV.write(path, t)

csv_to_table(path::String) = CSV.read(path, Table)

end
5 changes: 4 additions & 1 deletion ext/ChairmarksExt/b.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ function PerfChecker.default_options(::Val{:chairmark})
)
end

PerfChecker.initpkgs(::Val{:chairmark}) = quote
using Chairmarks
end

function PerfChecker.check(d::Dict, block::Expr, ::Val{:chairmark})
quote
d = $d
using Chairmarks
return @be $block evals=d[:evals] seconds=d[:seconds] samples=d[:samples] gc=d[:gc]
end
end
Expand Down
11 changes: 11 additions & 0 deletions ext/MakieExt/MakieExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module MakieExt

using Makie
using TypedTables
using PerfChecker

include("plotutils.jl")
include("allocs.jl")
include("bench.jl")

end
65 changes: 65 additions & 0 deletions ext/MakieExt/allocs.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
function PerfChecker.table_to_pie(x::Table, ::Val{:alloc}; pkg_name = "")
data = x.bytes
paths = smart_paths(x.filenames)[2] .* " — line " .* string.(x.linenumbers)
percentage = data .* 100 ./ sum(data)
colors = make_colors(length(percentage))
str = isempty(pkg_name) ? "" : " for $pkg_name"
f, ax, _ = pie(
data;
axis = (autolimitaspect = 1,),
color = colors,
inner_radius = 2,
radius = 4,
strokecolor = :white,
strokewidth = 5
)
ax.title = "Mallocs$str"
hidedecorations!(ax)
hidespines!(ax)
Legend(f[1, 2], [PolyElement(color = c) for c in colors], paths)
return f
end

function PerfChecker.checkres_to_pie(x::PerfChecker.CheckerResult, ::Val{:alloc})
end

function PerfChecker.checkres_to_scatterlines(
x::PerfChecker.CheckerResult, ::Val{:alloc}; title = "")
di = Dict()
for i in eachindex(x.tables)
j = x.tables[i]
p = x.pkgs[i]
u = unique(j.filenames)
paths = smart_paths(u)[2]
for k in eachindex(u)
if haskey(di, paths[k])
push!(di[paths[k]], (sum(j.bytes[j.filenames .== u[k]]), p.version))
else
di[paths[k]] = [(sum(j.bytes[j.filenames .== u[k]]), p.version)]
end
end
end

versions = Dict()
for i in eachindex(x.pkgs)
versions[x.pkgs[i].version] = i
end

versionnums = [x.pkgs[i].version for i in eachindex(x.pkgs)]
f = Figure()
ax = Axis(f[1, 1])
ax.xticks = (eachindex(versionnums), string.(versionnums))
ax.xlabel = "versions"
ax.ylabel = "bytes"
colors = make_colors(length(keys(di)))
i = 1
for (keys, values) in di
xs = [values[i][1] for i in eachindex(values)]
ys = [versions[values[i][2]] for i in eachindex(values)]
scatterlines!(f[1, 1], ys, xs, label = keys, color = (colors[i], 0.6))
i += 1
end
ax.title = x.pkgs[1].name
Legend(f[1, 2], ax)
return f
end
44 changes: 44 additions & 0 deletions ext/MakieExt/bench.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function PerfChecker.checkres_to_scatterlines(
x::PerfChecker.CheckerResult, ::Val{:benchmark})
println("Hello!")
@warn "Here!"
end

function PerfChecker.checkres_to_boxplots(
x::PerfChecker.CheckerResult, ::Val{:benchmark}; kwarg = :times)
di = Dict()
data = []
#for i in eachindex(x.tables)
#j = x.tables[i]
#p = x.pkgs[i]
#g = getproperties(j[i], (kwargs,))
#g = [g[k][1] for k in eachindex(g)]
#push!((fill(i, length(g)), g))
#end

#=
w = getproperties(j[1], (:allocs,))
versions = Dict()
for i in eachindex(x.pkgs)
versions[x.pkgs[i].version] = i
end

versionnums = [x.pkgs[i].version for i in eachindex(x.pkgs)]
f = Figure()
ax = Axis(f[1, 1])
ax.xticks = (eachindex(versionnums), string.(versionnums))
ax.xlabel = "versions"
ax.ylabel = "bytes"
colors = make_colors(length(keys(di)))
i = 1
for (keys, values) in di
xs = [values[i][1] for i in eachindex(values)]
ys = [versions[values[i][2]] for i in eachindex(values)]
scatterlines!(f[1,1], ys, xs, label = keys, color = (colors[i], 0.6)); i += 1
end
ax.title = x.pkgs[1].name
Legend(f[1,2], ax)
return f
=#
return data
end
24 changes: 24 additions & 0 deletions ext/MakieExt/plotutils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function make_colors(l)
Makie.distinguishable_colors(
l, [Makie.RGB(1, 1, 1), Makie.RGB(0, 0, 0)], dropseed = true)
end

function smart_paths(paths)
split_paths = map(splitpath ∘ normpath, paths)

common = paths |> first |> dirname |> splitpath
for path in split_paths
to_pop = length(common)
for name in Iterators.zip(common, path)
name[1] == name[2] || break
to_pop -= 1
end
foreach(_ -> pop!(common), 1:to_pop)
end

for path in split_paths
foreach(_ -> popfirst!(path), 1:length(common))
end

return joinpath(common...), map(joinpath, split_paths)
end
Binary file removed images/benchmark-memory.png
Binary file not shown.
Loading
Loading