From b34e2f05938a0af11d7c49510512490fc41e1af4 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 22 Sep 2021 16:17:08 +0200 Subject: python: Fix dropped-sample calculation in benchmark_rate.py This fixes a subtle bug, where a variable to cache the timestamp of an error gets bound to the metadata instead of creating a copy thereof. Without this fix, the calculation of dropped samples would always be 0, because the difference in timestamps would incorrectly be always zero. This fix will now make a copy of the timestamp. Shoutout to GitHub user bhorsfield for finding this issue. --- host/examples/python/benchmark_rate.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'host/examples/python') diff --git a/host/examples/python/benchmark_rate.py b/host/examples/python/benchmark_rate.py index a2ef1047b..35230599f 100755 --- a/host/examples/python/benchmark_rate.py +++ b/host/examples/python/benchmark_rate.py @@ -210,16 +210,18 @@ def benchmark_rx_rate(usrp, rx_streamer, random, timer_elapsed_event, rx_statist # Reset the overflow flag if had_an_overflow: had_an_overflow = False - num_rx_dropped += uhd.types.TimeSpec( - metadata.time_spec.get_real_secs() - last_overflow.get_real_secs() - ).to_ticks(rate) + num_rx_dropped += (metadata.time_spec - last_overflow).to_ticks(rate) elif metadata.error_code == uhd.types.RXMetadataErrorCode.overflow: had_an_overflow = True - last_overflow = metadata.time_spec + # Need to make sure that last_overflow is a new TimeSpec object, not + # a reference to metadata.time_spec, or it would not be useful + # further up. + last_overflow = uhd.types.TimeSpec( + metadata.time_spec.get_full_secs(), + metadata.time_spec.get_frac_secs()) # If we had a sequence error, record it if metadata.out_of_sequence: num_rx_seqerr += 1 - logger.warning("Detected RX sequence error.") # Otherwise just count the overrun else: num_rx_overruns += 1 -- cgit v1.2.3