]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker: change formatting in uptime field of "show proc"
authorWilliam Lallemand <wlallemand@haproxy.com>
Wed, 12 Jun 2019 16:21:17 +0000 (18:21 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Wed, 12 Jun 2019 17:19:57 +0000 (19:19 +0200)
Change the formatting of the uptime field in "show proc" so it's easier
to parse it. Remove the space between the day and the hour and align the
field on 15 characters.

src/mworker.c

index 728a3a149fa19d31e62977e8b6ac55b190bf11ec..cd88723536755c7d1ef37ca0b659ca0be4954599 100644 (file)
@@ -437,14 +437,18 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
        struct mworker_proc *child;
        int old = 0;
        int up = now.tv_sec - proc_self->timestamp;
+       char *uptime = NULL;
 
        if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
                return 1;
 
        chunk_reset(&trash);
 
-       chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>");
-       chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", getpid(), "master", 0, proc_self->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+       chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>");
+       memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+       chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s\n", getpid(), "master", 0, proc_self->reloads, uptime);
+       free(uptime);
+       uptime = NULL;
 
        /* displays current processes */
 
@@ -459,7 +463,10 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
                        old++;
                        continue;
                }
-               chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", child->relative_pid, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+               memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+               chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s\n", child->pid, "worker", child->relative_pid, child->reloads, uptime);
+               free(uptime);
+               uptime = NULL;
        }
 
        /* displays old processes */
@@ -476,7 +483,10 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
 
                        if (child->options & PROC_O_LEAVING) {
                                memprintf(&msg, "[was: %u]", child->relative_pid);
-                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %dd %02dh%02dm%02ds\n", child->pid, "worker", msg, child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+                               memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, "worker", msg, child->reloads, uptime);
+                               free(uptime);
+                               uptime = NULL;
                        }
                }
                free(msg);
@@ -495,7 +505,10 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
                        old++;
                        continue;
                }
-               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %dd %02dh%02dm%02ds\n", child->pid, child->id, "-", child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+               memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, child->id, "-", child->reloads, uptime);
+               free(uptime);
+               uptime = NULL;
        }
 
        if (old) {
@@ -507,7 +520,10 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
                                continue;
 
                        if (child->options & PROC_O_LEAVING) {
-                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %dd %02dh%02dm%02ds\n", child->pid, child->id, "-", child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+                               memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, child->id, "-", child->reloads, uptime);
+                               free(uptime);
+                               uptime = NULL;
                        }
                }
        }
@@ -574,6 +590,7 @@ void mworker_free_child(struct mworker_proc *child)
                                free(child->command[i]);
                                child->command[i] = NULL;
                        }
+
                }
                free(child->command);
                child->command = NULL;