MINOR: stats: use tv_remain() to precisely compute the uptime
We'll have to support reporting sub-second uptimes, so let's use the
appropriate function which will automatically adjust the tv_usec field.
In addition to this, it will also report a more accurate uptime thanks
to considering the sub-second part in the result.
diff --git a/src/stats.c b/src/stats.c
index a352a9b..4b58f66 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -4293,7 +4293,7 @@
*/
int stats_fill_info(struct field *info, int len, uint flags)
{
- unsigned int up = (now.tv_sec - start_date.tv_sec);
+ struct timeval up;
struct buffer *out = get_trash_chunk();
#ifdef USE_OPENSSL
@@ -4307,6 +4307,8 @@
}
#endif
+ tv_remain(&start_date, &now, &up);
+
if (len < INF_TOTAL_FIELDS)
return 0;
@@ -4324,9 +4326,9 @@
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", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
+ 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));
- info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up);
+ info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up.tv_sec);
info[INF_START_TIME_SEC] = 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);