From 3a4073799db9cf314b57eb20bb8f8fc085a76631 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 11 Apr 2018 16:33:13 -0700 Subject: examples: Avoid calculating dropped samples for negative offsets There are cases when the first sample after an overrun has an earlier timestamp than the timestamp of the error package. In this case, benchmark_rate would incorrectly determine the number of dropped samples, causing it to display a very large number. This is not a fix of the negative offset issue, but will avoid displaying overly pessimistic numbers dropped samples. An error message is still displayed when this happens, which aids in debugging this situation. --- host/examples/benchmark_rate.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'host/examples') diff --git a/host/examples/benchmark_rate.cpp b/host/examples/benchmark_rate.cpp index 3b5439510..88be83a7b 100644 --- a/host/examples/benchmark_rate.cpp +++ b/host/examples/benchmark_rate.cpp @@ -118,7 +118,16 @@ void benchmark_rx_rate( case uhd::rx_metadata_t::ERROR_CODE_NONE: if (had_an_overflow) { had_an_overflow = false; - num_dropped_samps += (md.time_spec - last_time).to_ticks(rate); + const long dropped_samps = + (md.time_spec - last_time).to_ticks(rate); + if (dropped_samps < 0) { + std::cerr + << "[" << NOW() << "] Timestamp after overrun recovery " + "ahead of error timestamp! Unable to calculate " + "number of dropped samples." + "(Delta: " << dropped_samps << " ticks)\n"; + } + num_dropped_samps += std::max(1, dropped_samps); } if ((burst_timer_elapsed or stop_called) and md.end_of_burst) { return; -- cgit v1.2.3