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

Use : for time and showtime msg formatting #43255

Merged
merged 5 commits into from
Dec 3, 2021
Merged
Changes from 2 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: 10 additions & 8 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ function format_bytes(bytes) # also used by InteractiveUtils
end
end

function time_print(elapsedtime, bytes=0, gctime=0, allocs=0, compile_time=0, newline=false)
function time_print(elapsedtime, bytes=0, gctime=0, allocs=0, compile_time=0, newline=false, _lpad=true)
timestr = Ryu.writefixed(Float64(elapsedtime/1e9), 6)
str = sprint() do io
print(io, length(timestr) < 10 ? (" "^(10 - length(timestr))) : "")
_lpad && print(io, length(timestr) < 10 ? (" "^(10 - length(timestr))) : "")
print(io, timestr, " seconds")
parens = bytes != 0 || allocs != 0 || gctime > 0 || compile_time > 0
parens && print(io, " (")
Expand Down Expand Up @@ -149,9 +149,9 @@ function time_print(elapsedtime, bytes=0, gctime=0, allocs=0, compile_time=0, ne
nothing
end

function timev_print(elapsedtime, diff::GC_Diff, compile_time)
function timev_print(elapsedtime, diff::GC_Diff, compile_time, _lpad)
allocs = gc_alloc_count(diff)
time_print(elapsedtime, diff.allocd, diff.total_time, allocs, compile_time, true)
time_print(elapsedtime, diff.allocd, diff.total_time, allocs, compile_time, true, _lpad)
print("elapsed time (ns): $elapsedtime\n")
padded_nonzero_print(diff.total_time, "gc time (ns)")
padded_nonzero_print(diff.allocd, "bytes allocated")
Expand Down Expand Up @@ -243,8 +243,9 @@ macro time(msg, ex)
compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime)
)
local diff = GC_Diff(gc_num(), stats)
isnothing($(esc(msg))) || print($(esc(msg)), " ->")
time_print(elapsedtime, diff.allocd, diff.total_time, gc_alloc_count(diff), compile_elapsedtime, true)
local has_msg = !isnothing($(esc(msg)))
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
has_msg && print($(esc(msg)), " : ")
IanButterworth marked this conversation as resolved.
Show resolved Hide resolved
time_print(elapsedtime, diff.allocd, diff.total_time, gc_alloc_count(diff), compile_elapsedtime, true, !has_msg)
val
end
end
Expand Down Expand Up @@ -323,8 +324,9 @@ macro timev(msg, ex)
compile_elapsedtime = cumulative_compile_time_ns_after() - compile_elapsedtime)
)
local diff = GC_Diff(gc_num(), stats)
isnothing($(esc(msg))) || print($(esc(msg)), " ->")
timev_print(elapsedtime, diff, compile_elapsedtime)
local has_msg = !isnothing($(esc(msg)))
has_msg && print($(esc(msg)), ": ")
timev_print(elapsedtime, diff, compile_elapsedtime, !has_msg)
val
end
end
Expand Down