Skip to content

Commit

Permalink
add function to get total live bytes (JuliaLang#33094)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Dec 12, 2019
1 parent 305b103 commit 3382125
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ end
# total time spend in garbage collection, in nanoseconds
gc_time_ns() = ccall(:jl_gc_total_hrtime, UInt64, ())

"""
Base.gc_live_bytes()
Return the total size (in bytes) of objects currently in memory.
This is computed as the total size of live objects after
the last garbage collection, plus the number of bytes allocated
since then.
"""
function gc_live_bytes()
num = gc_num()
Int(ccall(:jl_gc_live_bytes, Int64, ())) + num.allocd + num.deferred_alloc
end

# print elapsed time, return expression value
const _mem_units = ["byte", "KiB", "MiB", "GiB", "TiB", "PiB"]
const _cnt_units = ["", " k", " M", " G", " T", " P"]
Expand Down
5 changes: 5 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,11 @@ void jl_gc_sync_total_bytes(void)
jl_gc_get_total_bytes(&last_gc_total_bytes);
}

JL_DLLEXPORT int64_t jl_gc_live_bytes(void)
{
return live_bytes;
}

static void jl_gc_premark(jl_ptls_t ptls2)
{
arraylist_t *remset = ptls2->heap.remset;
Expand Down

0 comments on commit 3382125

Please sign in to comment.