Humanize milliseconds if interval is less than 1s
The intervals are configurable in milliseconds so humanize should be able to display at that precision.
This commit is contained in:
parent
1832301862
commit
d90a43d948
20
service.c
20
service.c
@ -127,18 +127,22 @@ void serviceDrop(size_t index) {
|
|||||||
services.ptr[index] = services.ptr[--services.len];
|
services.ptr[index] = services.ptr[--services.len];
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *humanize(struct timespec uptime) {
|
static const char *humanize(struct timespec interval) {
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
int days = uptime.tv_sec / (24 * 60 * 60);
|
if (!interval.tv_sec) {
|
||||||
uptime.tv_sec %= (24 * 60 * 60);
|
snprintf(buf, sizeof(buf), "%dms", (int)(interval.tv_nsec / 1000000));
|
||||||
int hours = uptime.tv_sec / (60 * 60);
|
return buf;
|
||||||
uptime.tv_sec %= (60 * 60);
|
}
|
||||||
int mins = uptime.tv_sec / 60;
|
int days = interval.tv_sec / (24 * 60 * 60);
|
||||||
uptime.tv_sec %= 60;
|
interval.tv_sec %= (24 * 60 * 60);
|
||||||
|
int hours = interval.tv_sec / (60 * 60);
|
||||||
|
interval.tv_sec %= (60 * 60);
|
||||||
|
int mins = interval.tv_sec / 60;
|
||||||
|
interval.tv_sec %= 60;
|
||||||
int d, h, m, s;
|
int d, h, m, s;
|
||||||
snprintf(
|
snprintf(
|
||||||
buf, sizeof(buf), "%n%dd %n%dh %n%dm %n%ds",
|
buf, sizeof(buf), "%n%dd %n%dh %n%dm %n%ds",
|
||||||
&d, days, &h, hours, &m, mins, &s, (int)uptime.tv_sec
|
&d, days, &h, hours, &m, mins, &s, (int)interval.tv_sec
|
||||||
);
|
);
|
||||||
if (days) return &buf[d];
|
if (days) return &buf[d];
|
||||||
if (hours) return &buf[h];
|
if (hours) return &buf[h];
|
||||||
|
Loading…
Reference in New Issue
Block a user