tests/xtimer_drift: Compute drift and jitter

- drift is the total difference from the expected time
 - jitter is the difference only since the last printout
This commit is contained in:
Joakim Nohlgård 2016-02-16 09:25:10 +01:00
parent 857df0a93a
commit 68a91426fb

View File

@ -89,6 +89,7 @@ void *worker_thread(void *arg)
(void) arg; (void) arg;
unsigned int loop_counter = 0; unsigned int loop_counter = 0;
uint32_t start = 0; uint32_t start = 0;
uint32_t last = 0;
printf("Starting thread %" PRIkernel_pid "\n", thread_getpid()); printf("Starting thread %" PRIkernel_pid "\n", thread_getpid());
@ -98,6 +99,9 @@ void *worker_thread(void *arg)
uint32_t now = xtimer_now(); uint32_t now = xtimer_now();
if (start == 0) { if (start == 0) {
start = now; start = now;
last = start;
++loop_counter;
continue;
} }
uint32_t us, sec; uint32_t us, sec;
@ -108,9 +112,12 @@ void *worker_thread(void *arg)
hr = sec / 3600; hr = sec / 3600;
if ((loop_counter % TEST_HZ) == 0) { if ((loop_counter % TEST_HZ) == 0) {
uint32_t expected = start + loop_counter * TEST_INTERVAL; uint32_t expected = start + loop_counter * TEST_INTERVAL;
int32_t diff = now - expected; int32_t drift = now - expected;
printf("now=%" PRIu32 ".%06" PRIu32 " (%u hours %u min), diff=%" PRId32 "\n", expected = last + TEST_HZ * TEST_INTERVAL;
sec, us, hr, min, diff); int32_t jitter = now - expected;
printf("now=%" PRIu32 ".%06" PRIu32 " (%u hours %u min), drift=%" PRId32 ", jitter=%" PRId32 "\n",
sec, us, hr, min, drift, jitter);
last = now;
} }
++loop_counter; ++loop_counter;
} }