From bfc4b742afb104b3fc818d434a39beb3d6ab8a1e Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Fri, 27 Jan 2017 12:33:43 +0000 Subject: [PATCH] Move {start,end}_cpu_timing into util.c --- dump1090.c | 15 --------------- util.c | 19 ++++++++++++++++++- util.h | 6 ++++++ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/dump1090.c b/dump1090.c index 64302ec..2f80541 100644 --- a/dump1090.c +++ b/dump1090.c @@ -96,21 +96,6 @@ static void sigtermHandler(int dummy) { log_with_timestamp("Caught SIGTERM, shutting down..\n"); } -static void start_cpu_timing(struct timespec *start_time) -{ - clock_gettime(CLOCK_THREAD_CPUTIME_ID, start_time); -} - -static void end_cpu_timing(const struct timespec *start_time, struct timespec *add_to) -{ - struct timespec end_time; - clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end_time); - add_to->tv_sec += (end_time.tv_sec - start_time->tv_sec - 1); - add_to->tv_nsec += (1000000000L + end_time.tv_nsec - start_time->tv_nsec); - add_to->tv_sec += add_to->tv_nsec / 1000000000L; - add_to->tv_nsec = add_to->tv_nsec % 1000000000L; -} - void receiverPositionChanged(float lat, float lon, float alt) { log_with_timestamp("Autodetected receiver location: %.5f, %.5f at %.0fm AMSL", lat, lon, alt); diff --git a/util.c b/util.c index b66f7e1..5168851 100644 --- a/util.c +++ b/util.c @@ -47,7 +47,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "util.h" +#include "dump1090.h" #include #include @@ -79,3 +79,20 @@ void normalize_timespec(struct timespec *ts) ts->tv_nsec = (ts->tv_nsec + 1000000000 * adjust) % 1000000000; } } + +/* record current CPU time in start_time */ +void start_cpu_timing(struct timespec *start_time) +{ + clock_gettime(CLOCK_THREAD_CPUTIME_ID, start_time); +} + +/* add difference between start_time and the current CPU time to add_to */ +void end_cpu_timing(const struct timespec *start_time, struct timespec *add_to) +{ + struct timespec end_time; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end_time); + add_to->tv_sec += (end_time.tv_sec - start_time->tv_sec - 1); + add_to->tv_nsec += (1000000000L + end_time.tv_nsec - start_time->tv_nsec); + add_to->tv_sec += add_to->tv_nsec / 1000000000L; + add_to->tv_nsec = add_to->tv_nsec % 1000000000L; +} diff --git a/util.h b/util.h index 41ccbb1..51405b4 100644 --- a/util.h +++ b/util.h @@ -36,4 +36,10 @@ int64_t receiveclock_ns_elapsed(uint64_t t1, uint64_t t2); struct timespec; void normalize_timespec(struct timespec *ts); +/* record current CPU time in start_time */ +void start_cpu_timing(struct timespec *start_time); + +/* add difference between start_time and the current CPU time to add_to */ +void end_cpu_timing(const struct timespec *start_time, struct timespec *add_to); + #endif