]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: haload: move statistics header printing to mtask_cb
authorFrederic Lecaille <flecaille@haproxy.com>
Wed, 8 Jul 2026 15:14:54 +0000 (17:14 +0200)
committerFrederic Lecaille <flecaille@haproxy.com>
Wed, 8 Jul 2026 15:35:34 +0000 (17:35 +0200)
Move the header printing logic from hld_init to mtask_cb using a static flag.
This ensures the header is displayed only when the main task starts
processing, avoiding issues where the header might be printed before other
haproxy initialization messages or unexpected early exits.

src/haload.c

index 17cefa9612b65fb876e134f42ff0a954d6ef8698..d0a644bba6a6bbad21ff0007e80542d397a712f3 100644 (file)
@@ -747,10 +747,28 @@ void update_throttle()
 /* main task */
 static struct task *mtask_cb(struct task *t, void *context, unsigned int state)
 {
+       static int header_printed;
+
        TRACE_ENTER(HLD_EV_MAIN_TASK);
 
        gettimeofday(&hld_now, NULL);
 
+       if (!header_printed) {
+               header_printed = 1;
+               if (arg_long >= 2)
+                       printf("#_____time conns tot_conn  tot_req      tot_bytes"
+                                  "    err thr cps rps Bps bps ttfb(us) ttlb(us)");
+               else if (arg_long)
+                       printf("#     time conns tot_conn  tot_req      tot_bytes"
+                                  "    err  cps  rps  Bps  bps   ttfb   ttlb");
+               else
+                       printf("#     time conns tot_conn  tot_req      tot_bytes"
+                                  "    err  cps  rps  bps   ttfb");
+               if (arg_hscd)
+                       printf(" 1xx 2xx 3xx 4xx 5xx");
+               putchar('\n');
+       }
+
        update_throttle();
        if (tick_is_expired(mtask.show_time, now_ms)) {
                hld_summary();
@@ -1809,19 +1827,6 @@ static int hld_init(void)
                goto leave;
        }
 
-       if (arg_long >= 2)
-               printf("#_____time conns tot_conn  tot_req      tot_bytes"
-                      "    err thr cps rps Bps bps ttfb(us) ttlb(us)");
-       else if (arg_long)
-               printf("#     time conns tot_conn  tot_req      tot_bytes"
-                      "    err  cps  rps  Bps  bps   ttfb   ttlb");
-       else
-               printf("#     time conns tot_conn  tot_req      tot_bytes"
-                      "    err  cps  rps  bps   ttfb");
-       if (arg_hscd)
-               printf(" 1xx 2xx 3xx 4xx 5xx");
-       putchar('\n');
-
        mtask.t->process = mtask_cb;
        mtask.t->state |= TASK_RT;
        mtask.t->expire = TICK_ETERNITY;