Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function Base.show(io::IO, to::TimerOutput; allocations::Bool = true, sortby::Sy
rev = !in(sortby, [:name, :firstexec])
by(x) = sortf(x, sortby)
for timer in sort!(collect(values(to.inner_timers)); rev = rev, by = by)
_print_timer(io, timer, ∑t, ∑b, 0, name_length, allocations, sortby, compact)
_print_timer(io, timer, ∑t, ∑t, ∑b, ∑b, 0, name_length, allocations, sortby, compact)
end
print_header(io, Δt, Δb, ∑t, ∑b, name_length, false, allocations, linechars, compact, title)
end
Expand Down Expand Up @@ -70,8 +70,8 @@ function print_header(io, Δt, Δb, ∑t, ∑b, name_length, header, allocations
midrule = linechars == :unicode ? "─" : "-"
topbottomrule = linechars == :unicode ? "─" : "-"
sec_ncalls = string(rpad("Section", name_length, " "), " ncalls ")
time_headers = " time %tot" * (compact ? "" : " avg")
alloc_headers = allocations ? (" alloc %tot" * (compact ? "" : " avg")) : ""
time_headers = " time %tot" * (compact ? "" : " %par avg")
alloc_headers = allocations ? (" alloc %tot" * (compact ? "" : " %par avg")) : ""
total_table_width = sum(textwidth.((sec_ncalls, time_headers, alloc_headers))) + 3

# Just hardcoded shit to make things look nice
Expand All @@ -90,15 +90,15 @@ function print_header(io, Δt, Δb, ∑t, ∑b, name_length, header, allocations
if compact
time_header = " Time "
else
time_header = " Time "
time_header = " Time "
end

time_underline = midrule^textwidth(time_header)

if compact
allocation_header = " Allocations "
else
allocation_header = " Allocations "
allocation_header = " Allocations "
end

alloc_underline = midrule^textwidth(allocation_header)
Expand Down Expand Up @@ -136,7 +136,7 @@ function print_header(io, Δt, Δb, ∑t, ∑b, name_length, header, allocations
end
end

function _print_timer(io::IO, to::TimerOutput, ∑t::Integer, ∑b::Integer, indent::Integer, name_length, allocations, sortby, compact)
function _print_timer(io::IO, to::TimerOutput, ∑t::Integer, tparent::Integer, ∑b::Integer, bparent::Integer, indent::Integer, name_length, allocations, sortby, compact)
accum_data = to.accumulated_data
t = accum_data.time
b = accum_data.allocs
Expand All @@ -148,18 +148,22 @@ function _print_timer(io::IO, to::TimerOutput, ∑t::Integer, ∑b::Integer, ind

print(io, " ", lpad(prettytime(t), 6, " "))
print(io, " ", lpad(prettypercent(t, ∑t), 5, " "))
t_par_str = indent == 0 ? " " : prettypercent(t, tparent, decimal=false)
print(io, " ", lpad(t_par_str, 3, " "))
!compact && print(io, " ", rpad(prettytime(t / nc), 6, " "))

if allocations
print(io, " ", rpad(prettymemory(b), 9, " "))
print(io, rpad(prettypercent(b, ∑b), 5, " "))
b_par_str = indent == 0 ? " " : prettypercent(b, bparent, decimal=false)
print(io, " ", b_par_str)
!compact && print(io, " ", lpad(prettymemory(b / nc), 5, " "))
end
print(io, "\n")

rev = !in(sortby, [:name, :firstexec])
by(x) = sortf(x, sortby)
for timer in sort!(collect(values(to.inner_timers)); rev = rev, by = by)
_print_timer(io, timer, ∑t, b, indent + 2, name_length, allocations, sortby, compact)
_print_timer(io, timer, ∑t, t, ∑b, b, indent + 2, name_length, allocations, sortby, compact)
end
end
10 changes: 7 additions & 3 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,21 @@ function prettymemory(b)
return lpad(str, 7, " ")
end

function prettypercent(nominator, denominator)
function prettypercent(nominator, denominator; decimal::Bool=true)
value = nominator / denominator * 100

if denominator == 0 && nominator == 0
str = " - %"
elseif denominator == 0
str = "inf %"
else
str = string(@sprintf("%.1f", value), "%")
if decimal
str = string(@sprintf("%.1f", value), "%")
else
str = string(@sprintf("%d", value), "%")
end
end
return lpad(str, 6, " ")
return lpad(str, decimal ? 6 : 4, " ")
end

function prettycount(t::Integer)
Expand Down