From 7a0ca85a90e432072a5c31f81ddff06d3406aa8f Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Mon, 29 Sep 2014 23:04:58 +0100 Subject: [PATCH] Measure CPU used by the sample processing thread. --- Makefile | 2 +- dump1090.c | 10 ++++++++++ dump1090.h | 3 +++ mode_s.c | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6bfe9ee..672ada2 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ EXTRACFLAGS=-DHTMLPATH=\"$(SHAREDIR)\" endif CFLAGS=-O2 -g -Wall -W `pkg-config --cflags librtlsdr` -LIBS=`pkg-config --libs librtlsdr` -lpthread -lm +LIBS=`pkg-config --libs librtlsdr` -lpthread -lm -lrt CC=gcc diff --git a/dump1090.c b/dump1090.c index 64087f1..39898e3 100644 --- a/dump1090.c +++ b/dump1090.c @@ -507,6 +507,13 @@ static void display_stats(void) { printf("%d sample blocks processed\n", Modes.stat_blocks_processed); printf("%d sample blocks dropped\n", Modes.stat_blocks_dropped); + if (Modes.stat_blocks_processed > 0) { + long cpu_millis = (long)Modes.stat_cputime.tv_sec*1000L + Modes.stat_cputime.tv_nsec/1000000L; + long sample_millis = Modes.stat_blocks_processed * MODES_ASYNC_BUF_SAMPLES / (Modes.oversample ? 2400 : 2000); + printf("%ld ms CPU time used to process %ld ms samples, %.1f%% load\n", + cpu_millis, sample_millis, 100.0 * cpu_millis / sample_millis); + } + printf("%d ModeA/C detected\n", Modes.stat_ModeAC); printf("%d Mode-S preambles with poor correlation\n", Modes.stat_preamble_no_correlation); printf("%d Mode-S preambles with noise in the quiet period\n", Modes.stat_preamble_not_quiet); @@ -549,6 +556,9 @@ static void display_stats(void) { printf("%d total usable messages\n", Modes.stat_goodcrc + Modes.stat_ph_goodcrc + Modes.stat_fixed + Modes.stat_ph_fixed); fflush(stdout); + Modes.stat_cputime.tv_sec = 0; + Modes.stat_cputime.tv_nsec = 0; + Modes.stat_blocks_processed = Modes.stat_blocks_dropped = 0; diff --git a/dump1090.h b/dump1090.h index 97d3ef8..7b9deba 100644 --- a/dump1090.h +++ b/dump1090.h @@ -57,6 +57,7 @@ #include #include #include + #include #include "rtl-sdr.h" #include "anet.h" #else @@ -387,6 +388,8 @@ struct { // Internal state unsigned int stat_blocks_processed; unsigned int stat_blocks_dropped; + + struct timespec stat_cputime; } Modes; // The struct we use to store information about a decoded message. diff --git a/mode_s.c b/mode_s.c index 20428b6..9dcd7a2 100644 --- a/mode_s.c +++ b/mode_s.c @@ -2082,6 +2082,9 @@ void detectModeS_oversample(uint16_t *m, uint32_t mlen) { unsigned char msg[MODES_LONG_MSG_BYTES], *pMsg; uint32_t j; + struct timespec cpu_start_time, cpu_end_time; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_start_time); + memset(&mm, 0, sizeof(mm)); for (j = 0; j < mlen; j++) { @@ -2412,6 +2415,17 @@ void detectModeS_oversample(uint16_t *m, uint32_t mlen) { } } + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &cpu_end_time); + Modes.stat_cputime.tv_sec += (cpu_end_time.tv_sec - cpu_start_time.tv_sec); + Modes.stat_cputime.tv_nsec += (cpu_end_time.tv_nsec - cpu_start_time.tv_nsec); + if (Modes.stat_cputime.tv_nsec < 0) { + Modes.stat_cputime.tv_nsec += 1000000000L; + Modes.stat_cputime.tv_sec--; + } else if (Modes.stat_cputime.tv_nsec > 1000000000L) { + Modes.stat_cputime.tv_nsec -= 1000000000L; + Modes.stat_cputime.tv_sec++; + } + //Send any remaining partial raw buffers now if (Modes.rawOutUsed || Modes.beastOutUsed) {