From: Olivier Matz Date: Thu, 3 Aug 2017 20:29:21 +0000 (+0200) Subject: alloc stats X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=9200b3883a02cbfd36b00f75def7f746efe6fb9b;p=protos%2Flibecoli.git alloc stats --- diff --git a/lib/main.c b/lib/main.c index 25cc4ca..51b0946 100644 --- a/lib/main.c +++ b/lib/main.c @@ -42,6 +42,7 @@ static int log_level = EC_LOG_INFO; static int alloc_fail_proba = 0; static int seed = 0; +static size_t alloc_success = 0; static const char ec_short_options[] = "h" /* help */ @@ -201,6 +202,8 @@ static void *debug_malloc(size_t size, const char *file, unsigned int line) ec_log(EC_LOG_DEBUG, "%s:%d: info: malloc(%zd) -> %p\n", file, line, size, ret); + if (ret) + alloc_success++; return ret; } @@ -313,6 +316,8 @@ static void *debug_realloc(void *ptr, size_t size, const char *file, ec_log(EC_LOG_DEBUG, "%s:%d: info: realloc(%p, %zd) -> %p\n", file, line, ptr, size, ret); + if (ret) + alloc_success++; return ret; } @@ -322,6 +327,8 @@ static int debug_alloc_dump_leaks(void) int i; char **buffer; + ec_log(EC_LOG_INFO, "%zd successful allocations\n", alloc_success); + if (TAILQ_EMPTY(&debug_alloc_hdr_list)) return 0;