From 4e2cb40f98b6bd702e6193e231807600a3ce6dad Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sat, 31 Dec 2011 12:37:47 +0100 Subject: [PATCH] Reports the size of the allocated memory. --- state.c | 2 ++ util.c | 9 +++++++++ util.h | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/state.c b/state.c index 4d3a387a..57f4c4c1 100644 --- a/state.c +++ b/state.c @@ -1009,6 +1009,8 @@ void state_read(struct snapraid_state* state) printf("\tblock %u\n", count_block); printf("\tsymlink %u\n", count_link); } + + printf("Using %u MiB of memory.\n", (unsigned)(malloc_counter() / 1024 / 1024)); } void state_write(struct snapraid_state* state) diff --git a/util.c b/util.c index 1bbf9b10..d3666310 100644 --- a/util.c +++ b/util.c @@ -643,6 +643,13 @@ void pathslash(char* dst, size_t size) /****************************************************************************/ /* mem */ +static size_t mcounter; + +size_t malloc_counter(void) +{ + return mcounter; +} + void* malloc_nofail(size_t size) { void* ptr = malloc(size); @@ -652,6 +659,8 @@ void* malloc_nofail(size_t size) exit(EXIT_FAILURE); } + mcounter += size; + return ptr; } diff --git a/util.h b/util.h index 1b14105a..d56bf0fb 100644 --- a/util.h +++ b/util.h @@ -337,6 +337,11 @@ void pathslash(char* dst, size_t size); /****************************************************************************/ /* memory */ +/** + * Return the size of the allocated memory. + */ +size_t malloc_counter(void); + /** * Safe malloc. * If no memory is available, it aborts.