diff --git a/sdrbase/dsp/datafifo.cpp b/sdrbase/dsp/datafifo.cpp index 33df067a4..224fa7f0b 100644 --- a/sdrbase/dsp/datafifo.cpp +++ b/sdrbase/dsp/datafifo.cpp @@ -35,6 +35,7 @@ void DataFifo::reset() { QMutexLocker mutexLocker(&m_mutex); m_suppressed = -1; + m_suppressedSamples = 0; m_fill = 0; m_head = 0; m_tail = 0; @@ -47,6 +48,7 @@ DataFifo::DataFifo(QObject* parent) : { setObjectName("DataFifo"); m_suppressed = -1; + m_suppressedSamples = 0; m_size = 0; m_fill = 0; m_head = 0; @@ -60,6 +62,7 @@ DataFifo::DataFifo(int size, QObject* parent) : { setObjectName("DataFifo"); m_suppressed = -1; + m_suppressedSamples = 0; create(size); } @@ -70,6 +73,7 @@ DataFifo::DataFifo(const DataFifo& other) : { setObjectName("DataFifo"); m_suppressed = -1; + m_suppressedSamples = 0; m_size = m_data.size(); m_fill = 0; m_head = 0; @@ -89,25 +93,63 @@ bool DataFifo::setSize(int size) return m_data.size() == size; } +// Rate-limit overflow messages while continuing to report every overflow. +// After an overflow, messages are suppressed for 2.5 seconds and the +// accumulated loss is reported as a single message. A 2.5 second recovery +// interval without further overflow is then required before immediate +// reporting resumes. void DataFifo::logOverflow(unsigned int total, unsigned int count) { - unsigned int samplesDropped = count - total; + const bool hasOverflow = total < count; + const unsigned int dropped = count - total; + + // m_suppressed: -1 = immediate reporting, 0+ = suppressed message count, + // -2 = recovery monitoring if (m_suppressed == -1) { - m_suppressed = 0; - m_msgRateTimer.start(); - qCritical("DataFifo::write: overflow - dropping %u samples (size=%u)", samplesDropped, m_size); + if (hasOverflow) + { + qCritical("DataFifo: overflow - dropped %u samples", dropped); + + // The current overflow was already reported, so don't count it again. + m_suppressed = 0; + m_suppressedSamples = 0; + m_msgRateTimer.start(); + } } - else if (m_msgRateTimer.elapsed() > 2500) + else if (m_suppressed == -2) { - qCritical("DataFifo::write: %u messages dropped", m_suppressed); - qCritical("DataFifo::write: overflow - dropping %u samples (size=%u)", samplesDropped, m_size); - m_suppressed = -1; + if (hasOverflow) + { + // Resume accumulation without restarting the recovery timer. + m_suppressed = 1; + m_suppressedSamples += dropped; + } + else if (m_msgRateTimer.elapsed() > 2500) + { + // No overflow for the recovery interval: resume immediate reporting. + m_suppressed = -1; + } } - else + else // m_suppressed >= 0 { - m_suppressed++; + if (m_msgRateTimer.elapsed() > 2500) + { + if (m_suppressed) + { + qCritical("DataFifo: overflow - dropped %lld samples (%u event%s)", + m_suppressedSamples, m_suppressed, m_suppressed > 1 ? "s" : ""); + } + m_suppressed = -2; + m_suppressedSamples = 0; + m_msgRateTimer.restart(); + } + else if (hasOverflow) + { + ++m_suppressed; + m_suppressedSamples += dropped; + } } } @@ -118,6 +160,7 @@ unsigned int DataFifo::write(const quint8* data, unsigned int count, DataType da if (dataType != m_currentDataType) { m_suppressed = -1; + m_suppressedSamples = 0; m_fill = 0; m_head = 0; m_tail = 0; @@ -164,6 +207,7 @@ unsigned int DataFifo::write(QByteArray::const_iterator begin, QByteArray::const if (dataType != m_currentDataType) { m_suppressed = -1; + m_suppressedSamples = 0; m_fill = 0; m_head = 0; m_tail = 0; diff --git a/sdrbase/dsp/datafifo.h b/sdrbase/dsp/datafifo.h index 3e5d70ed5..07007b150 100644 --- a/sdrbase/dsp/datafifo.h +++ b/sdrbase/dsp/datafifo.h @@ -64,6 +64,7 @@ signals: private: QElapsedTimer m_msgRateTimer; int m_suppressed; + qint64 m_suppressedSamples; QByteArray m_data; DataType m_currentDataType; QRecursiveMutex m_mutex; diff --git a/sdrbase/dsp/samplesinkfifo.cpp b/sdrbase/dsp/samplesinkfifo.cpp index 92bdfa9c2..f3661691e 100644 --- a/sdrbase/dsp/samplesinkfifo.cpp +++ b/sdrbase/dsp/samplesinkfifo.cpp @@ -37,6 +37,7 @@ void SampleSinkFifo::reset() { QMutexLocker mutexLocker(&m_mutex); m_suppressed = -1; + m_suppressedSamples = 0; m_fill = 0; m_head = 0; m_tail = 0; @@ -50,6 +51,7 @@ SampleSinkFifo::SampleSinkFifo(QObject* parent) : m_writtenSignalRateDivider(1) { m_suppressed = -1; + m_suppressedSamples = 0; m_size = 0; m_fill = 0; m_head = 0; @@ -64,6 +66,7 @@ SampleSinkFifo::SampleSinkFifo(int size, QObject* parent) : m_writtenSignalRateDivider(1) { m_suppressed = -1; + m_suppressedSamples = 0; create(size); } @@ -75,6 +78,7 @@ SampleSinkFifo::SampleSinkFifo(const SampleSinkFifo& other) : m_writtenSignalRateDivider(1) { m_suppressed = -1; + m_suppressedSamples = 0; m_size = m_data.size(); m_fill = 0; m_head = 0; @@ -100,27 +104,69 @@ void SampleSinkFifo::setWrittenSignalRateDivider(unsigned int divider) m_writtenSignalRateDivider = divider; } +// Rate-limit overflow messages while continuing to report every overflow. +// After an overflow, messages are suppressed for 2.5 seconds and the +// accumulated loss is reported as a single message. A 2.5 second recovery +// interval without further overflow is then required before immediate +// reporting resumes. void SampleSinkFifo::logOverflow(unsigned int total, unsigned int count) { - unsigned int samplesDropped = count - total; + const bool hasOverflow = total < count; + const unsigned int dropped = count - total; + + if (hasOverflow) + { + emit overflow(dropped); + } + + // m_suppressed: -1 = immediate reporting, 0+ = suppressed message count, + // -2 = recovery monitoring if (m_suppressed == -1) { - m_suppressed = 0; - m_msgRateTimer.start(); - qCritical("SampleSinkFifo::write: (%s) overflow - dropping %u samples", qPrintable(m_label), samplesDropped); - emit overflow(samplesDropped); + if (hasOverflow) + { + qCritical("SampleSinkFifo: (%s) overflow - dropped %u samples", + qPrintable(m_label), dropped); + + // The current overflow was already reported, so don't count it again. + m_suppressed = 0; + m_suppressedSamples = 0; + m_msgRateTimer.start(); + } } - else if (m_msgRateTimer.elapsed() > 2500) + else if (m_suppressed == -2) { - qCritical("SampleSinkFifo::write: (%s) %u messages dropped", qPrintable(m_label), m_suppressed); - qCritical("SampleSinkFifo::write: (%s) overflow - dropping %u samples", qPrintable(m_label), samplesDropped); - emit overflow(samplesDropped); - m_suppressed = -1; + if (hasOverflow) + { + // Resume accumulation without restarting the recovery timer. + m_suppressed = 1; + m_suppressedSamples += dropped; + } + else if (m_msgRateTimer.elapsed() > 2500) + { + // No overflow for the recovery interval: resume immediate reporting. + m_suppressed = -1; + } } - else + else // m_suppressed >= 0 { - m_suppressed++; + if (m_msgRateTimer.elapsed() > 2500) + { + if (m_suppressed) + { + qCritical("SampleSinkFifo: (%s) overflow - dropped %lld samples (%u event%s)", + qPrintable(m_label), m_suppressedSamples, m_suppressed, m_suppressed > 1 ? "s" : ""); + } + m_suppressed = -2; + m_suppressedSamples = 0; + m_msgRateTimer.restart(); + } + else if (hasOverflow) + { + ++m_suppressed; + m_suppressedSamples += dropped; + } } } @@ -140,7 +186,7 @@ unsigned int SampleSinkFifo::write(const quint8* data, unsigned int count) total = std::min(count, m_size - m_fill); - if (total < count) + if (m_suppressed != -1 || total < count) { logOverflow(total, count); } @@ -189,7 +235,7 @@ unsigned int SampleSinkFifo::write(SampleVector::const_iterator begin, SampleVec total = std::min(count, m_size - m_fill); - if (total < count) + if (m_suppressed != -1 || total < count) { logOverflow(total, count); } diff --git a/sdrbase/dsp/samplesinkfifo.h b/sdrbase/dsp/samplesinkfifo.h index 72705cebf..3c3993842 100644 --- a/sdrbase/dsp/samplesinkfifo.h +++ b/sdrbase/dsp/samplesinkfifo.h @@ -33,6 +33,7 @@ class SDRBASE_API SampleSinkFifo : public QObject { private: QElapsedTimer m_msgRateTimer; int m_suppressed; + qint64 m_suppressedSamples; SampleVector m_data; int m_total; unsigned int m_writtenSignalCount;