Skip to content

Commit

Permalink
Add CSV extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzaare committed May 14, 2024
1 parent a23e94c commit 11693c3
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
[weakdeps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Chairmarks = "0ca39b1e-fe0b-4e98-acfc-b1656634c4de"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

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

[compat]
BenchmarkTools = "1.5"
Chairmarks = "1"
CoverageTools = "1"
CpuId = "0.3.1"
CSV = "0.10"
Makie = "0.21"
TypedTables = "1"
julia = "1"
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
65 changes: 64 additions & 1 deletion ext/MakieExt/plotutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,67 @@ function smart_paths(paths)
return joinpath(common...), map(joinpath, splitted_paths)
end

PerfChecker.saveplot(a...;b...) = Makie.save(a...;b...)
function PerfChecker.table_to_pie(x::Table, ::Val{:alloc}; pkg_name = "")
data = x.bytes
@info data
paths = smart_paths(x.filenames)[2] .* " — line " .* string.(x.linenumbers)
percentage = data .* 100 ./ sum(data)
@info percentage
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_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
2 changes: 2 additions & 0 deletions perf/PatternFolds/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Chairmarks = "0ca39b1e-fe0b-4e98-acfc-b1656634c4de"
CoverageTools = "c36e975a-824b-4404-a568-ef97ca766997"
PatternFolds = "c18a7f1d-76ad-4ce4-950d-5419b888513b"
PerfChecker = "6309bf6b-a531-4b08-891e-8ee981e5c424"
TypedTables = "9d95f2ec-7b3d-5a63-8d20-e2491e220bb9"
60 changes: 36 additions & 24 deletions src/PerfChecker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,51 @@ import Base.Sys: CPUinfo, CPU_NAME, cpu_info, WORD_SIZE
import CpuId: simdbytes, cpucores, cputhreads, cputhreads_per_core

struct HwInfo
cpus::Vector{CPUinfo}
machine::String
word::Int
simdbytes::Int
corecount::Tuple{Int, Int, Int}
cpus::Vector{CPUinfo}
machine::String
word::Int
simdbytes::Int
corecount::Tuple{Int, Int, Int}
end

struct CheckerResult
tables::Vector{Table}
hwinfo::Union{HwInfo,Nothing}
tags::Union{Nothing,Vector{Symbol}}
pkgs::Vector{PackageSpec}
tables::Vector{Table}
hwinfo::Union{HwInfo, Nothing}
tags::Union{Nothing, Vector{Symbol}}
pkgs::Vector{PackageSpec}
end

function Base.show(io::IO, v::PerfChecker.CheckerResult)
println(io, "Tables:")
for i in v.tables
println(io, '\t', Base.display(i))
end
println(io, "Tables:")
for i in v.tables
println(io, '\t', Base.display(i))
end

println(io, "Hardware Info:")
println(io, "CPU Information:")
println(io, '\t', v.hwinfo.cpus)
println(io, "Machine name: ", v.hwinfo.machine)
println(io, "Word Size: ", v.hwinfo.word)
println(io, "SIMD Bytes: ", v.hwinfo.simdbytes)
println(io, "Core count (physical, total and threads per core): ", v.hwinfo.corecount)
println(io, "Hardware Info:")
println(io, "CPU Information:")
println(io, '\t', v.hwinfo.cpus)
println(io, "Machine name: ", v.hwinfo.machine)
println(io, "Word Size: ", v.hwinfo.word)
println(io, "SIMD Bytes: ", v.hwinfo.simdbytes)
println(io, "Core count (physical, total and threads per core): ", v.hwinfo.corecount)

println(io, "Tags used: ", v.tags)
println(io, "Tags used: ", v.tags)

println(io, "Package versions tested (if provided): ")
println(io, Base.display(v.pkgs))
println(io, "Package versions tested (if provided): ")
println(io, Base.display(v.pkgs))
end

find_by_tags(tags::Vector{Symbol}, results::CheckerResult; exact_match = true) = findall(x -> exact_match ? (tags == x.tags) : (!isempty(x.tags tags)), results)
function find_by_tags(tags::Vector{Symbol}, results::CheckerResult; exact_match = true)
findall(x -> exact_match ? (tags == x.tags) : (!isempty(x.tags tags)), results)
end

function csv_to_table(path)
@warn "CSV module not loaded. Please load it before using this function."
end

function table_to_csv(t::Table, path::String)
@warn "CSV module not loaded. Please load it before using this function."
end

# SECTION - Exports
export @check
Expand All @@ -57,6 +67,8 @@ export table_to_pie
export checkres_to_pie
export checkres_to_scatterlines
export saveplot
export csv_to_table
export table_to_csv

# SECTION - Includes
include("versions.jl")
Expand Down

0 comments on commit 11693c3

Please sign in to comment.