]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: activity: interrupt the show profile dump more often
authorWilly Tarreau <w@1wt.eu>
Thu, 21 Nov 2024 11:02:35 +0000 (12:02 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 21 Nov 2024 18:58:06 +0000 (19:58 +0100)
The calls to resolv_sym_name() can be a bit expensive. Forcing to
yield more often is better for the latency and will avoid the
watchdog reporting warnings.

Note that it's still called in the sort at the end, but that one
cannot be avoided. At best we could try to rely on the list of libs
but that's not trivial and not always present.

src/activity.c

index 67a43fa59e59567d6f87b227a0f4d0768e6ea163..72e58a02269c3ce703ca45ca97aeecc25a1fc4a6 100644 (file)
@@ -934,6 +934,7 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
        const char *str;
        int max_lines;
        int i, j, max;
+       int dumped;
 
        chunk_reset(&trash);
 
@@ -997,11 +998,17 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
        if (!max_lines)
                max_lines = SCHED_ACT_HASH_BUCKETS;
 
+       dumped = 0;
        for (i = ctx->linenum; i < max_lines; i++) {
                if (!tmp_activity[i].calls)
                        continue; // skip aggregated or empty entries
 
                ctx->linenum = i;
+
+               /* resolve_sym_name() may be slow, better dump a few entries at a time */
+               if (dumped >= 10)
+                       return 0;
+
                chunk_reset(name_buffer);
                caller = HA_ATOMIC_LOAD(&tmp_activity[i].caller);
 
@@ -1034,6 +1041,7 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
                        /* failed, try again */
                        return 0;
                }
+               dumped++;
        }
 
        if (applet_putchk(appctx, &trash) == -1) {
@@ -1069,12 +1077,18 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
        if (!max_lines)
                max_lines = MEMPROF_HASH_BUCKETS + 1;
 
+       dumped = 0;
        for (i = ctx->linenum; i < max_lines; i++) {
                struct memprof_stats *entry = &tmp_memstats[i];
 
                ctx->linenum = i;
                if (!entry->alloc_calls && !entry->free_calls)
                        continue;
+
+               /* resolve_sym_name() may be slow, better dump a few entries at a time */
+               if (dumped >= 10)
+                       return 0;
+
                chunk_appendf(&trash, "%11llu %11llu %14llu %14llu| %16p ",
                              entry->alloc_calls, entry->free_calls,
                              entry->alloc_tot, entry->free_tot,
@@ -1107,6 +1121,8 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
 
                if (applet_putchk(appctx, &trash) == -1)
                        return 0;
+
+               dumped++;
        }
 
        if (applet_putchk(appctx, &trash) == -1)