]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: activity: support aggregating by caller also for memprofile
authorWilly Tarreau <w@1wt.eu>
Wed, 11 Mar 2026 17:03:26 +0000 (18:03 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2026 17:06:38 +0000 (18:06 +0100)
"show profiling" supports "aggr" for tasks but it was ignored for
memory. Now that we're having many more entries, it makes sense to
have it to ignore the call path and merge similar operations.

src/activity.c

index c6d8f1795d6f95bdef8323b16873f9bb675c3fa3..f03626ce62d740ee1ade875e325896e74953f5b8 100644 (file)
@@ -1228,6 +1228,31 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
        else
                qsort(tmp_memstats, MEMPROF_HASH_BUCKETS+1, sizeof(tmp_memstats[0]), cmp_memprof_stats);
 
+       if (ctx->aggr) {
+               /* merge entries for the same caller and reset the exec_ctx */
+               for (i = j = 0; i < MEMPROF_HASH_BUCKETS; i++) {
+                       if ((tmp_memstats[i].alloc_calls | tmp_memstats[i].free_calls) == 0)
+                               continue;
+                       for (j = i + 1; j < MEMPROF_HASH_BUCKETS; j++) {
+                               if ((tmp_memstats[j].alloc_calls | tmp_memstats[j].free_calls) == 0)
+                                       continue;
+                               if (tmp_memstats[j].caller != tmp_memstats[i].caller ||
+                                   tmp_memstats[j].method != tmp_memstats[i].method ||
+                                   tmp_memstats[j].info   != tmp_memstats[i].info)
+                                       continue;
+                               tmp_memstats[i].locked_calls  += tmp_memstats[j].locked_calls;
+                               tmp_memstats[i].alloc_calls   += tmp_memstats[j].alloc_calls;
+                               tmp_memstats[i].free_calls    += tmp_memstats[j].free_calls;
+                               tmp_memstats[i].alloc_tot     += tmp_memstats[j].alloc_tot;
+                               tmp_memstats[i].free_tot      += tmp_memstats[j].free_tot;
+                               /* don't dump the ctx */
+                               tmp_memstats[i].exec_ctx.type = 0;
+                               /* don't dump the merged entry */
+                               tmp_memstats[j].alloc_calls = tmp_memstats[j].free_calls = 0;
+                       }
+               }
+       }
+
  memstats_resume:
        if (!ctx->linenum)
                chunk_appendf(&trash,