]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: activity: make "show profiling" support a few arguments
authorWilly Tarreau <w@1wt.eu>
Wed, 5 May 2021 15:48:13 +0000 (17:48 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 5 May 2021 17:09:19 +0000 (19:09 +0200)
These ones allow to limit the output to only certain sections and/or
a number of lines per dump.

doc/management.txt
src/activity.c

index a16a86de72c77caf1039d0cd129292ebe17675f3..cdb527598174f82f3f016ed8a0f1309c3d78ae2d 100644 (file)
@@ -2480,11 +2480,20 @@ show pools
   as the SIGQUIT when running in foreground except that it does not flush
   the pools.
 
-show profiling
+show profiling [{all | status | tasks | memory}] [max_lines]
   Dumps the current profiling settings, one per line, as well as the command
   needed to change them. When tasks profiling is enabled, some per-function
   statistics collected by the scheduler will also be emitted, with a summary
-  covering the number of calls, total/avg CPU time and total/avg latency.
+  covering the number of calls, total/avg CPU time and total/avg latency. When
+  memory profiling is enabled, some information such as the number of
+  allocations/releases and their sizes will be reported. It is possible to
+  limit the dump to only the profiling status, the tasks, or the memory
+  profiling by specifying the respective keywords; by default all profiling
+  information are dumped. It is also possible to limit the number of lines
+  of output of each category by specifying a numeric limit. Please note that
+  profiling is essentially aimed at developers since it gives hints about
+  where CPU cycles or memory are wasted in the code. There is nothing useful
+  to monitor there.
 
 show resolvers [<resolvers section id>]
   Dump statistics for the given resolvers section, or all resolvers sections
index a210362dcd7d0ede981bcd817a0244501f343b70..0cb48361bf577823237d395d35d5534f8ffa4922 100644 (file)
@@ -552,6 +552,40 @@ static int cli_io_handler_show_profiling(struct appctx *appctx)
        return 1;
 }
 
+/* parse a "show profiling" command. It returns 1 on failure, 0 if it starts to dump. */
+static int cli_parse_show_profiling(char **args, char *payload, struct appctx *appctx, void *private)
+{
+       if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
+               return 1;
+
+       if (strcmp(args[2], "all") == 0) {
+               appctx->ctx.cli.i0 = 0; // will cycle through 0,1,2; default
+               args++;
+       }
+       else if (strcmp(args[2], "status") == 0) {
+               appctx->ctx.cli.i0 = 4; // will visit status only
+               args++;
+       }
+       else if (strcmp(args[2], "tasks") == 0) {
+               appctx->ctx.cli.i0 = 5; // will visit tasks only
+               args++;
+       }
+       else if (strcmp(args[2], "memory") == 0) {
+               appctx->ctx.cli.i0 = 6; // will visit memory only
+               args++;
+       }
+       else if (*args[2] && !isdigit((unsigned char)*args[2]))
+               return cli_err(appctx, "Expects either 'all', 'status', 'tasks' or 'memory'.\n");
+
+       if (*args[2]) {
+               /* Second arg may set a limit to number of entries to dump; default is
+                * not set and means no limit.
+                */
+               appctx->ctx.cli.o0 = atoi(args[2]);
+       }
+       return 0;
+}
+
 /* This function scans all threads' run queues and collects statistics about
  * running tasks. It returns 0 if the output buffer is full and it needs to be
  * called again, otherwise non-zero.
@@ -704,7 +738,7 @@ INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
 
 /* register cli keywords */
 static struct cli_kw_list cli_kws = {{ },{
-       { { "show", "profiling", NULL }, "show profiling : show CPU profiling options",   NULL, cli_io_handler_show_profiling, NULL },
+       { { "show", "profiling", NULL }, "show profiling : show CPU profiling options",   cli_parse_show_profiling, cli_io_handler_show_profiling, NULL },
        { { "show", "tasks", NULL },     "show tasks     : show running tasks",           NULL, cli_io_handler_show_tasks,     NULL },
        { { "set",  "profiling", NULL }, "set  profiling : enable/disable resource profiling", cli_parse_set_profiling,  NULL },
        {{},}