From 6ee23d772674175e5babdbb654a296e415ac20f0 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Sat, 28 Sep 2024 13:27:23 +0200 Subject: [PATCH] fixup uptime in stats startup_time was changed to monotonic without properly changing all the places it was used. change startup_time back and add startup_time_mono --- readsb.c | 3 ++- readsb.h | 1 + stats.c | 17 +++-------------- util.c | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/readsb.c b/readsb.c index 4de6bafd..bd1a3618 100644 --- a/readsb.c +++ b/readsb.c @@ -2689,7 +2689,8 @@ int main(int argc, char **argv) { // Set sane defaults configSetDefaults(); - Modes.startup_time = mono_milli_seconds(); + Modes.startup_time_mono = mono_milli_seconds(); + Modes.startup_time = mstime(); if (lzo_init() != LZO_E_OK) { diff --git a/readsb.h b/readsb.h index b58747a8..434196ed 100644 --- a/readsb.h +++ b/readsb.h @@ -855,6 +855,7 @@ struct _Modes ALIGNED struct mag_buf mag_buffers[MODES_MAG_BUFFERS]; // Converted magnitude buffers from RTL or file input int64_t startup_time; + int64_t startup_time_mono; int64_t next_stats_update; int64_t next_stats_display; int64_t next_api_update; diff --git a/stats.c b/stats.c index a2041916..a668e0a0 100644 --- a/stats.c +++ b/stats.c @@ -660,12 +660,8 @@ struct char_buffer generateStatusProm(int64_t now) { struct statsCount *sC = &(Modes.globalStatsCount); - int64_t uptime = now - Modes.startup_time; - if (now < Modes.startup_time) - uptime = 0; - p = safe_snprintf(p, end, "readsb_now %"PRIu64"\n", now); - p = safe_snprintf(p, end, "readsb_uptime %"PRIu64"\n", uptime); + p = safe_snprintf(p, end, "readsb_uptime %"PRIu64"\n", getUptime()); p = safe_snprintf(p, end, "readsb_aircraft_with_position %u\n", sC->readsb_aircraft_with_position); p = safe_snprintf(p, end, "readsb_aircraft_without_position %u\n", sC->readsb_aircraft_total - sC->readsb_aircraft_with_position); @@ -686,11 +682,7 @@ struct char_buffer generateStatusJson(int64_t now) { size_t buflen = 8192; char *buf = (char *) cmalloc(buflen), *p = buf, *end = buf + buflen; - int64_t uptime = now - Modes.startup_time; - if (now < Modes.startup_time) - uptime = 0; - - p = safe_snprintf(p, end, "{ \"now\": %.1f, \"uptime\": %.1f", now / 1000.0, uptime / 1000.0); + p = safe_snprintf(p, end, "{ \"now\": %.1f, \"uptime\": %.1f", now / 1000.0, getUptime() / 1000.0); p = appendTypeCounts(p, end); @@ -903,10 +895,7 @@ struct char_buffer generatePromFile(int64_t now) { p = safe_snprintf(p, end, "readsb_trace_chunk_memory %"PRIu64"\n", Modes.trace_chunk_size); p = safe_snprintf(p, end, "readsb_trace_cache_memory %"PRIu64"\n", Modes.trace_cache_size); } - int64_t uptime = now - Modes.startup_time; - if (now < Modes.startup_time) - uptime = 0; - p = safe_snprintf(p, end, "readsb_uptime %"PRIu64"\n", uptime); + p = safe_snprintf(p, end, "readsb_uptime %"PRIu64"\n", getUptime()); if (p >= end) fprintf(stderr, "buffer overrun stats prom\n"); diff --git a/util.c b/util.c index 23377bd6..7ae104d4 100644 --- a/util.c +++ b/util.c @@ -118,7 +118,7 @@ int64_t mono_milli_seconds() { } int64_t getUptime() { - return mono_milli_seconds() - Modes.startup_time; + return mono_milli_seconds() - Modes.startup_time_mono; } int snprintHMS(char *buf, size_t bufsize, int64_t now) {