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.
This commit is contained in:
Willy Tarreau 2021-05-08 07:40:52 +02:00
parent 2745620240
commit d37e26eaa6

View File

@ -4293,7 +4293,7 @@ static int stats_dump_typed_info_fields(struct buffer *out,
*/
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 @@ int stats_fill_info(struct field *info, int len, uint flags)
}
#endif
tv_remain(&start_date, &now, &up);
if (len < INF_TOTAL_FIELDS)
return 0;
@ -4324,9 +4326,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", 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);