Skip to content

Commit 85c83a7

Browse files
authored
some improvements to GC stat printing (#44098)
- line up `elapsed time` - print most numbers unconditionally - print minor/full collections instead of all/full collections - count `free` calls for arrays, since we count `malloc`s for them
1 parent 0bf6ce3 commit 85c83a7

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

base/timing.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function GC_Diff(new::GC_Num, old::GC_Num)
4040
# logic from `src/gc.c:jl_gc_total_bytes`
4141
old_allocd = gc_total_bytes(old)
4242
new_allocd = gc_total_bytes(new)
43-
return GC_Diff(new_allocd - old_allocd,
43+
return GC_Diff(new_allocd - old_allocd,
4444
new.malloc - old.malloc,
4545
new.realloc - old.realloc,
4646
new.poolalloc - old.poolalloc,
@@ -98,14 +98,13 @@ function prettyprint_getunits(value, numunits, factor)
9898
return number, unit
9999
end
100100

101-
function padded_nonzero_print(value, str)
102-
if value != 0
103-
blanks = " "[1:(18 - length(str))]
101+
function padded_nonzero_print(value, str, always_print = true)
102+
if always_print || value != 0
103+
blanks = " "[1:(19 - length(str))]
104104
println(str, ":", blanks, value)
105105
end
106106
end
107107

108-
109108
function format_bytes(bytes) # also used by InteractiveUtils
110109
bytes, mb = prettyprint_getunits(bytes, length(_mem_units), Int64(1024))
111110
if mb == 1
@@ -152,15 +151,17 @@ end
152151
function timev_print(elapsedtime, diff::GC_Diff, compile_time, _lpad)
153152
allocs = gc_alloc_count(diff)
154153
time_print(elapsedtime, diff.allocd, diff.total_time, allocs, compile_time, true, _lpad)
155-
print("elapsed time (ns): $elapsedtime\n")
154+
padded_nonzero_print(elapsedtime, "elapsed time (ns)")
156155
padded_nonzero_print(diff.total_time, "gc time (ns)")
157156
padded_nonzero_print(diff.allocd, "bytes allocated")
158157
padded_nonzero_print(diff.poolalloc, "pool allocs")
159158
padded_nonzero_print(diff.bigalloc, "non-pool GC allocs")
160-
padded_nonzero_print(diff.malloc, "malloc() calls")
161-
padded_nonzero_print(diff.realloc, "realloc() calls")
162-
padded_nonzero_print(diff.freecall, "free() calls")
163-
padded_nonzero_print(diff.pause, "GC pauses")
159+
padded_nonzero_print(diff.malloc, "malloc() calls", false)
160+
padded_nonzero_print(diff.realloc, "realloc() calls", false)
161+
# always print number of frees if there are mallocs
162+
padded_nonzero_print(diff.freecall, "free() calls", diff.malloc > 0)
163+
minor_collects = diff.pause - diff.full_sweep
164+
padded_nonzero_print(minor_collects, "minor collections")
164165
padded_nonzero_print(diff.full_sweep, "full collections")
165166
end
166167

src/gc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ static void jl_gc_free_array(jl_array_t *a) JL_NOTSAFEPOINT
11341134
else
11351135
free(d);
11361136
gc_num.freed += jl_array_nbytes(a);
1137+
gc_num.freecall++;
11371138
}
11381139
}
11391140

0 commit comments

Comments
 (0)