Skip to content

Commit

Permalink
Merge pull request #12391 from KristofferC/kc/mem_printing
Browse files Browse the repository at this point in the history
tweak memory printing in @time (or, the start of a new saga)
  • Loading branch information
StefanKarpinski committed Jul 30, 2015
2 parents 22c6c5e + 51ba9d0 commit 6c34bc7
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,16 @@ function toc()
end

# print elapsed time, return expression value
const _mem_units = ["bytes", "KB", "MB", "GB", "TB", "PB"]
const _mem_units = ["byte", "KB", "MB", "GB", "TB", "PB"]
const _cnt_units = ["", " k", " M", " G", " T", " P"]
function prettyprint_getunits(value, numunits, factor)
c1 = factor
c2 = c1 * c1
if value <= c1*100 ; return (value, 1) ; end
unit = 2
while value > c2*100 && (unit < numunits)
c1 = c2
c2 *= factor
unit += 1
if value == 0 || value == 1
return (value, 1)
end
return div(value+(c1>>>1),c1), unit
unit = ceil(Int, log(value) / log(factor))
unit = min(numunits, unit)
number = value/factor^(unit-1)
return number, unit
end

function padded_nonzero_print(value,str)
Expand All @@ -116,7 +113,16 @@ function time_print(elapsedtime, bytes, gctime, allocs)
if bytes != 0 || allocs != 0
bytes, mb = prettyprint_getunits(bytes, length(_mem_units), Int64(1024))
allocs, ma = prettyprint_getunits(allocs, length(_cnt_units), Int64(1000))
@printf(" (%d%s allocation%s: %d %s", allocs, _cnt_units[ma], allocs==1 ? "" : "s", bytes, _mem_units[mb])
if ma == 1
@printf(" (%d%s allocation%s: ", allocs, _cnt_units[ma], allocs==1 ? "" : "s")
else
@printf(" (%.2f%s allocations: ", allocs, _cnt_units[ma])
end
if mb == 1
@printf("%d %s%s", bytes, _mem_units[mb], bytes==1 ? "" : "s")
else
@printf("%.3f %s", bytes, _mem_units[mb])
end
if gctime > 0
@printf(", %.2f%% gc time", 100*gctime/elapsedtime)
end
Expand Down

0 comments on commit 6c34bc7

Please sign in to comment.