Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ The `print_timer([io::IO = stdout], to::TimerOutput, kwargs)`, (or `show`) takes
* `sortby::Symbol` ─ sort the sections according to `:time` (default), `:ncalls`, `:allocations` or `:name`
* `linechars::Symbol` ─ use either `:unicode` (default) or `:ascii` to draw the horizontal lines in the table
* `compact::Bool` ─ hide the `avg` column (default `false`)
* `maxlevel::Integer` ─ maximum level of nested function calls printed (default `100`)

## Flattening

Expand Down
12 changes: 8 additions & 4 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ print_timer(io::IO; kwargs...) = print_timer(io, DEFAULT_TIMER; kwargs...)
print_timer(io::IO, to::TimerOutput; kwargs...) = (show(io, to; kwargs...); println(io))

Base.show(to::TimerOutput; kwargs...) = show(stdout, to; kwargs...)
function Base.show(io::IO, to::TimerOutput; allocations::Bool = true, sortby::Symbol = :time, linechars::Symbol = :unicode, compact::Bool = false, title::String = "")
function Base.show(io::IO, to::TimerOutput; allocations::Bool = true, sortby::Symbol = :time, linechars::Symbol = :unicode, compact::Bool = false, title::String = "", maxlevel::Integer = 100)
sortby in (:time, :ncalls, :allocations, :name) || throw(ArgumentError("sortby should be :time, :allocations, :ncalls or :name, got $sortby"))
linechars in (:unicode, :ascii) || throw(ArgumentError("linechars should be :unicode or :ascii, got $linechars"))

Expand Down Expand Up @@ -36,7 +36,7 @@ function Base.show(io::IO, to::TimerOutput; allocations::Bool = true, sortby::Sy

print_header(io, Δt, Δb, ∑t, ∑b, name_length, true, allocations, linechars, compact, title)
for timer in sort!(collect(values(to.inner_timers)); rev = sortby != :name, by = x -> sortf(x, sortby))
_print_timer(io, timer, ∑t, ∑b, 0, name_length, allocations, sortby, compact)
_print_timer(io, timer, ∑t, ∑b, 0, name_length, allocations, sortby, compact, maxlevel)
end
print_header(io, Δt, Δb, ∑t, ∑b, name_length, false, allocations, linechars, compact, title)
end
Expand Down Expand Up @@ -133,11 +133,15 @@ 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, ∑b::Integer, level::Integer, name_length, allocations, sortby, compact, maxlevel)
if level >= maxlevel
return
end
accum_data = to.accumulated_data
t = accum_data.time
b = accum_data.allocs

indent = level * 2
name = truncdots(to.name, name_length - indent)
print(io, " ")
nc = accum_data.ncalls
Expand All @@ -156,6 +160,6 @@ function _print_timer(io::IO, to::TimerOutput, ∑t::Integer, ∑b::Integer, ind
print(io, "\n")

for timer in sort!(collect(values(to.inner_timers)), rev = sortby != :name, by = x -> sortf(x, sortby))
_print_timer(io, timer, ∑t, ∑b, indent + 2, name_length, allocations, sortby, compact)
_print_timer(io, timer, ∑t, ∑b, level + 1, name_length, allocations, sortby, compact, maxlevel)
end
end