diff options
author | Eli Barzilay <eli@racket-lang.org> | 2015-07-09 00:49:31 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2015-07-09 00:49:31 +0300 |
commit | 67f8e2523ed2bac0a89011b01225b43908ae18ec (patch) | |
tree | d612fc694231bdad2aea73fdfd4a900cdb697bea /misc.c | |
parent | 005d9f57acd6e23e2a5727d272bb7553e150d602 (diff) | |
download | bdwgc-67f8e2523ed2bac0a89011b01225b43908ae18ec.tar.gz |
Add API function to calculate total memory in use by all GC blocks
(Apply part of commit db2b9f1 from 'racket_gc' branch.)
* include/gc.h (GC_get_memory_use): New API function declaration.
* misc.c (get_size, GC_get_memory_use): New function.
Diffstat (limited to 'misc.c')
-rw-r--r-- | misc.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -2014,6 +2014,25 @@ GC_API void * GC_CALL GC_do_blocking(GC_fn_type fn, void * client_data) } #endif /* !NO_DEBUGGING */ +static void get_size(struct hblk *h, word lptr) +{ + hdr *hhdr = HDR(h); + long bytes = WORDS_TO_BYTES(hhdr->hb_sz); + + bytes += HBLKSIZE-1; + bytes &= ~(HBLKSIZE-1); + + *(long *)lptr += bytes; +} +long GC_get_memory_use() +{ + long c = 0; + LOCK(); + GC_apply_to_all_blocks(get_size, (word)&c); + UNLOCK(); + return c; +} + /* Getter functions for the public Read-only variables. */ /* GC_get_gc_no() is unsynchronized and should be typically called */ |