Skip to content

Commit

Permalink
add option to configure continuous state writing interval
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedehopf committed Mar 5, 2024
1 parent 77e275e commit 844aae2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions help.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ static struct argp_option optionsReadsb[] = {
{"write-prom", OptPromFile, "<filepath>", 0, "Periodically write prometheus output to <filepath>", 1},
{"write-globe-history", OptGlobeHistoryDir, "<dir>", 0, "Extended Globe History", 1},
{"write-state", OptStateDir, "<dir>", 0, "Write state to disk to have traces after a restart", 1},
{"write-state-every", OptStateInterval, "<seconds>", 0, "Continuously write state to disk every X seconds (default: 3600)", 1},
{"write-state-only-on-exit", OptStateOnlyOnExit, 0, 0, "Don't continously update state.", 1},
{"heatmap-dir", OptHeatmapDir, "<dir>", 0, "Change the directory where heatmaps are saved (default is in globe history dir)", 1},
{"heatmap", OptHeatmap, "<interval in seconds>", 0, "Make Heatmap, each aircraft at most every interval seconds (creates historydir/heatmap.bin and exit after that)", 1},
Expand Down
12 changes: 10 additions & 2 deletions readsb.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ static void configSetDefaults(void) {
Modes.netIngest = 0;
Modes.uuidFile = strdup("/usr/local/share/adsbexchange/adsbx-uuid");
Modes.json_trace_interval = 20 * 1000;
Modes.state_write_interval = 1 * HOURS;
Modes.heatmap_current_interval = -15;
Modes.heatmap_interval = 60 * SECONDS;
Modes.json_reliable = -13;
Expand Down Expand Up @@ -1555,6 +1556,14 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
case OptStateOnlyOnExit:
Modes.state_only_on_exit = 1;
break;
case OptStateInterval:
Modes.state_write_interval = (int64_t) (atof(arg) * 1.0 * SECONDS);
if (Modes.state_write_interval < 59 * SECONDS) {
fprintf(stderr, "ERROR: --write-state-every less than 60 seconds (specified: %s)\n", arg);
exit(1);
Modes.state_write_interval = 1 * HOURS;
}
break;
case OptStateDir:
sfree(Modes.state_parent_dir);
Modes.state_parent_dir = strdup(arg);
Expand Down Expand Up @@ -2337,8 +2346,7 @@ static void miscStuff(int64_t now) {
//fprintf(stderr, "save_blob: %02x\n", blob);
notask_save_blob(blob);
blob = (blob + 1) % STATE_BLOBS;
next_blob = now + 60 * MINUTES / STATE_BLOBS;

next_blob = now + Modes.state_write_interval / STATE_BLOBS;
return;
}
}
Expand Down
2 changes: 2 additions & 0 deletions readsb.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ struct _Modes
int8_t dump_reduce; // only dump beast that would be sent out according to reduce_interval
int8_t state_only_on_exit;
int8_t free_aircraft;
int64_t state_write_interval;
char *prom_file;
int64_t heatmap_current_interval;
int64_t heatmap_interval; // don't change data type
Expand Down Expand Up @@ -1168,6 +1169,7 @@ enum {
OptPromFile,
OptGlobeHistoryDir,
OptStateDir,
OptStateInterval,
OptStateOnlyOnExit,
OptHeatmap,
OptHeatmapDir,
Expand Down

0 comments on commit 844aae2

Please sign in to comment.