From 8cce4d79ff8e448b033aca9b4b09db3b7acf7928 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 22 Oct 2021 16:26:12 +0200 Subject: [PATCH] MINOR: memprof: report the delta between alloc and free on realloc() realloc() calls are painful to analyse because they have two non-zero columns and trying to spot a leaking one requires a bit of scripting. Let's simply append the delta at the end of the line when alloc and free are non-nul. It would be useful to backport this to 2.4 to help with bug reports. --- src/activity.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/activity.c b/src/activity.c index b1b91aced..0046f3aea 100644 --- a/src/activity.c +++ b/src/activity.c @@ -737,9 +737,16 @@ static int cli_io_handler_show_profiling(struct appctx *appctx) else chunk_appendf(&trash, "[other]"); - chunk_appendf(&trash," %s(%lld)\n", memprof_methods[entry->method], + chunk_appendf(&trash," %s(%lld)", memprof_methods[entry->method], (long long)(entry->alloc_tot - entry->free_tot) / (long long)(entry->alloc_calls + entry->free_calls)); + if (entry->alloc_tot && entry->free_tot) { + /* that's a realloc, show the total diff to help spot leaks */ + chunk_appendf(&trash," [delta=%lld]", (long long)(entry->alloc_tot - entry->free_tot)); + } + + chunk_appendf(&trash, "\n"); + if (ci_putchk(si_ic(si), &trash) == -1) { si_rx_room_blk(si); return 0;