Add --stats-every <secs> option.

Periodically displays and resets stats.
Useful for unattended operation.
This commit is contained in:
Oliver Jowett 2014-09-25 20:33:50 +01:00
parent a82df07c0c
commit 10061675de

View file

@ -428,6 +428,7 @@ void showHelp(void) {
"--aggressive More CPU for more messages (two bits fixes, ...)\n" "--aggressive More CPU for more messages (two bits fixes, ...)\n"
"--mlat display raw messages in Beast ascii mode\n" "--mlat display raw messages in Beast ascii mode\n"
"--stats With --ifile print stats at exit. No other output\n" "--stats With --ifile print stats at exit. No other output\n"
"--stats-every <seconds> Show and reset stats every <seconds> seconds\n"
"--onlyaddr Show only ICAO addresses (testing purposes)\n" "--onlyaddr Show only ICAO addresses (testing purposes)\n"
"--metric Use metric units (meters, km/h, ...)\n" "--metric Use metric units (meters, km/h, ...)\n"
"--snip <level> Strip IQ file removing samples < level\n" "--snip <level> Strip IQ file removing samples < level\n"
@ -480,6 +481,77 @@ void showCopyright(void) {
while (llTime >= time(NULL)) {} while (llTime >= time(NULL)) {}
} }
#endif #endif
static void display_stats(void) {
int j;
time_t now = time(NULL);
printf("\n\n");
if (Modes.interactive)
interactiveShowData();
printf("Statistics as at %s", ctime(&now));
printf("%d ModeA/C detected\n", Modes.stat_ModeAC);
printf("%d valid Mode-S preambles\n", Modes.stat_valid_preamble);
printf("%d DF-?? fields corrected for length\n", Modes.stat_DF_Len_Corrected);
printf("%d DF-?? fields corrected for type\n", Modes.stat_DF_Type_Corrected);
printf("%d demodulated with 0 errors\n", Modes.stat_demodulated0);
printf("%d demodulated with 1 error\n", Modes.stat_demodulated1);
printf("%d demodulated with 2 errors\n", Modes.stat_demodulated2);
printf("%d demodulated with > 2 errors\n", Modes.stat_demodulated3);
printf("%d with good crc\n", Modes.stat_goodcrc);
printf("%d with bad crc\n", Modes.stat_badcrc);
printf("%d errors corrected\n", Modes.stat_fixed);
Modes.stat_ModeAC =
Modes.stat_valid_preamble =
Modes.stat_DF_Len_Corrected =
Modes.stat_DF_Type_Corrected =
Modes.stat_demodulated0 =
Modes.stat_demodulated1 =
Modes.stat_demodulated2 =
Modes.stat_demodulated3 =
Modes.stat_goodcrc =
Modes.stat_badcrc =
Modes.stat_fixed = 0;
for (j = 0; j < MODES_MAX_BITERRORS; j++) {
printf(" %d with %d bit %s\n", Modes.stat_bit_fix[j], j+1, (j==0)?"error":"errors");
Modes.stat_bit_fix[j] = 0;
}
if (Modes.phase_enhance) {
printf("%d phase enhancement attempts\n", Modes.stat_out_of_phase);
printf("%d phase enhanced demodulated with 0 errors\n", Modes.stat_ph_demodulated0);
printf("%d phase enhanced demodulated with 1 error\n", Modes.stat_ph_demodulated1);
printf("%d phase enhanced demodulated with 2 errors\n", Modes.stat_ph_demodulated2);
printf("%d phase enhanced demodulated with > 2 errors\n", Modes.stat_ph_demodulated3);
printf("%d phase enhanced with good crc\n", Modes.stat_ph_goodcrc);
printf("%d phase enhanced with bad crc\n", Modes.stat_ph_badcrc);
printf("%d phase enhanced errors corrected\n", Modes.stat_ph_fixed);
Modes.stat_out_of_phase =
Modes.stat_ph_demodulated0 =
Modes.stat_ph_demodulated1 =
Modes.stat_ph_demodulated2 =
Modes.stat_ph_demodulated3 =
Modes.stat_ph_goodcrc =
Modes.stat_ph_badcrc =
Modes.stat_ph_fixed = 0;
for (j = 0; j < MODES_MAX_BITERRORS; j++) {
printf(" %d with %d bit %s\n", Modes.stat_ph_bit_fix[j], j+1, (j==0)?"error":"errors");
Modes.stat_ph_bit_fix[j] = 0;
}
}
printf("%d total usable messages\n", Modes.stat_goodcrc + Modes.stat_ph_goodcrc + Modes.stat_fixed + Modes.stat_ph_fixed);
fflush(stdout);
}
// //
//========================================================================= //=========================================================================
// //
@ -488,6 +560,8 @@ void showCopyright(void) {
// from the net, refreshing the screen in interactive mode, and so forth // from the net, refreshing the screen in interactive mode, and so forth
// //
void backgroundTasks(void) { void backgroundTasks(void) {
static time_t next_stats;
if (Modes.net) { if (Modes.net) {
modesReadFromClients(); modesReadFromClients();
} }
@ -501,6 +575,15 @@ void backgroundTasks(void) {
if (Modes.interactive) { if (Modes.interactive) {
interactiveShowData(); interactiveShowData();
} }
if (Modes.stats > 0) {
time_t now = time(NULL);
if (now > next_stats) {
if (next_stats != 0)
display_stats();
next_stats = now + Modes.stats;
}
}
} }
// //
//========================================================================= //=========================================================================
@ -665,7 +748,9 @@ int main(int argc, char **argv) {
f++; f++;
} }
} else if (!strcmp(argv[j],"--stats")) { } else if (!strcmp(argv[j],"--stats")) {
Modes.stats = 1; Modes.stats = -1;
} else if (!strcmp(argv[j],"--stats-every") && more) {
Modes.stats = atoi(argv[++j]);
} else if (!strcmp(argv[j],"--snip") && more) { } else if (!strcmp(argv[j],"--snip") && more) {
snipMode(atoi(argv[++j])); snipMode(atoi(argv[++j]));
exit(0); exit(0);
@ -779,37 +864,7 @@ int main(int argc, char **argv) {
// If --stats were given, print statistics // If --stats were given, print statistics
if (Modes.stats) { if (Modes.stats) {
printf("\n\n"); display_stats();
if (Modes.interactive)
interactiveShowData();
printf("%d ModeA/C detected\n", Modes.stat_ModeAC);
printf("%d valid Mode-S preambles\n", Modes.stat_valid_preamble);
printf("%d DF-?? fields corrected for length\n", Modes.stat_DF_Len_Corrected);
printf("%d DF-?? fields corrected for type\n", Modes.stat_DF_Type_Corrected);
printf("%d demodulated with 0 errors\n", Modes.stat_demodulated0);
printf("%d demodulated with 1 error\n", Modes.stat_demodulated1);
printf("%d demodulated with 2 errors\n", Modes.stat_demodulated2);
printf("%d demodulated with > 2 errors\n", Modes.stat_demodulated3);
printf("%d with good crc\n", Modes.stat_goodcrc);
printf("%d with bad crc\n", Modes.stat_badcrc);
printf("%d errors corrected\n", Modes.stat_fixed);
for (j = 0; j < MODES_MAX_BITERRORS; j++) {
printf(" %d with %d bit %s\n", Modes.stat_bit_fix[j], j+1, (j==0)?"error":"errors");
}
if (Modes.phase_enhance) {
printf("%d phase enhancement attempts\n", Modes.stat_out_of_phase);
printf("%d phase enhanced demodulated with 0 errors\n", Modes.stat_ph_demodulated0);
printf("%d phase enhanced demodulated with 1 error\n", Modes.stat_ph_demodulated1);
printf("%d phase enhanced demodulated with 2 errors\n", Modes.stat_ph_demodulated2);
printf("%d phase enhanced demodulated with > 2 errors\n", Modes.stat_ph_demodulated3);
printf("%d phase enhanced with good crc\n", Modes.stat_ph_goodcrc);
printf("%d phase enhanced with bad crc\n", Modes.stat_ph_badcrc);
printf("%d phase enhanced errors corrected\n", Modes.stat_ph_fixed);
for (j = 0; j < MODES_MAX_BITERRORS; j++) {
printf(" %d with %d bit %s\n", Modes.stat_ph_bit_fix[j], j+1, (j==0)?"error":"errors");
}
}
printf("%d total usable messages\n", Modes.stat_goodcrc + Modes.stat_ph_goodcrc + Modes.stat_fixed + Modes.stat_ph_fixed);
} }
if (Modes.filename == NULL) { if (Modes.filename == NULL) {