]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: use nanoseconds, not timeval to compute uptime
authorWilly Tarreau <w@1wt.eu>
Thu, 27 Apr 2023 12:41:37 +0000 (14:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 28 Apr 2023 14:08:08 +0000 (16:08 +0200)
Now that we have the required functions, let's get rid of the timeval
in intermediary calculations.

src/stats.c

index 17fb4d416044b23131eda25c1066b922b99da44b..d673cee39660f38731393b68e1c47db31dcfb7ee 100644 (file)
@@ -4604,9 +4604,10 @@ static int stats_dump_typed_info_fields(struct buffer *out,
  */
 int stats_fill_info(struct field *info, int len, uint flags)
 {
-       struct timeval up;
        struct buffer *out = get_trash_chunk();
        uint64_t glob_out_bytes, glob_spl_bytes, glob_out_b32;
+       uint up_sec, up_usec;
+       ullong up;
        int thr;
 
 #ifdef USE_OPENSSL
@@ -4627,7 +4628,9 @@ int stats_fill_info(struct field *info, int len, uint flags)
        }
        glob_out_b32 *= 32; // values are 32-byte units
 
-       tv_remain(&start_time, &now, &up);
+       up = tv_to_ns(&now) - tv_to_ns(&start_time);
+       up_sec = ns_to_sec(up);
+       up_usec = (up / 1000U) % 1000000U;
 
        if (len < INF_TOTAL_FIELDS)
                return 0;
@@ -4646,9 +4649,9 @@ int stats_fill_info(struct field *info, int len, uint flags)
        info[INF_PID]                            = mkf_u32(FO_STATUS, pid);
 
        info[INF_UPTIME]                         = mkf_str(FN_DURATION, chunk_newstr(out));
-       chunk_appendf(out, "%ud %uh%02um%02us", (uint)up.tv_sec / 86400, ((uint)up.tv_sec % 86400) / 3600, ((uint)up.tv_sec % 3600) / 60, ((uint)up.tv_sec % 60));
+       chunk_appendf(out, "%ud %uh%02um%02us", up_sec / 86400, (up_sec % 86400) / 3600, (up_sec % 3600) / 60, (up_sec % 60));
 
-       info[INF_UPTIME_SEC]                     = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_DURATION, up.tv_sec + up.tv_usec / 1000000.0) : mkf_u32(FN_DURATION, up.tv_sec);
+       info[INF_UPTIME_SEC]                     = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_DURATION, up_sec + up_usec / 1000000.0) : mkf_u32(FN_DURATION, up_sec);
        info[INF_START_TIME_SEC]                 = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_DURATION, start_date.tv_sec + start_date.tv_usec / 1000000.0) : mkf_u32(FN_DURATION, start_date.tv_sec);
        info[INF_MEMMAX_MB]                      = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax);
        info[INF_MEMMAX_BYTES]                   = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);