Skip to content

Commit

Permalink
fixup uptime in stats
Browse files Browse the repository at this point in the history
startup_time was changed to monotonic without properly changing all the
places it was used.
change startup_time back and add startup_time_mono
  • Loading branch information
wiedehopf committed Sep 28, 2024
1 parent 85b9187 commit 6ee23d7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
3 changes: 2 additions & 1 deletion readsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions readsb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 3 additions & 14 deletions stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6ee23d7

Please sign in to comment.