]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: memprof: also report the totals and delta alloc-free
authorWilly Tarreau <w@1wt.eu>
Tue, 11 May 2021 12:06:24 +0000 (14:06 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 May 2021 12:21:18 +0000 (14:21 +0200)
Already had to perform too many additions by external scripts, it's
time to add the totals and delay alloc-free as a last line in the
output of the "show memory profiling".

src/activity.c

index 6913a5c1941ad4877fea04174fd5f4e8ec084354..9d697e717a90d3f601151da2060be4a4d27ef221 100644 (file)
@@ -512,6 +512,8 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
        struct sched_activity tmp_activity[256] __attribute__((aligned(64)));
 #if USE_MEMORY_PROFILING
        struct memprof_stats tmp_memstats[MEMPROF_HASH_BUCKETS + 1];
+       unsigned long long tot_alloc_calls, tot_free_calls;
+       unsigned long long tot_alloc_bytes, tot_free_bytes;
 #endif
        struct stream_interface *si = appctx->owner;
        struct buffer *name_buffer = get_trash_chunk();
@@ -652,6 +654,27 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
                return 0;
        }
 
+       tot_alloc_calls = tot_free_calls = tot_alloc_bytes = tot_free_bytes = 0;
+       for (i = 0; i < max_lines; i++) {
+               tot_alloc_calls += tmp_memstats[i].alloc_calls;
+               tot_free_calls  += tmp_memstats[i].free_calls;
+               tot_alloc_bytes += tmp_memstats[i].alloc_tot;
+               tot_free_bytes  += tmp_memstats[i].free_tot;
+       }
+
+       chunk_appendf(&trash,
+                     "-----------------------|-----------------------------|\n"
+                     "%11llu %11llu %14llu %14llu| <- Total; Delta_calls=%lld; Delta_bytes=%lld\n",
+                     tot_alloc_calls, tot_free_calls,
+                     tot_alloc_bytes, tot_free_bytes,
+                     tot_alloc_calls - tot_free_calls,
+                     tot_alloc_bytes - tot_free_bytes);
+
+       if (ci_putchk(si_ic(si), &trash) == -1) {
+               si_rx_room_blk(si);
+               return 0;
+       }
+
        appctx->ctx.cli.i1 = 0; // reset first line to dump
        if ((appctx->ctx.cli.i0 & 4) == 0)
                appctx->ctx.cli.i0++; // next step