diff --git a/companion/src/simulation/debugoutput.cpp b/companion/src/simulation/debugoutput.cpp index e3d384cde9..020944fed2 100644 --- a/companion/src/simulation/debugoutput.cpp +++ b/companion/src/simulation/debugoutput.cpp @@ -33,7 +33,7 @@ extern AppData g; // ensure what "g" means DebugOutput * traceCallbackInstance = 0; const int DebugOutput::m_dataBufferMaxSize = 500; // lines of text (this is not the display buffer) -const int DebugOutput::m_dataPrintFreqDefault = 10; // ms +const int DebugOutput::m_dataPrintFreqDefault = 8; // ms const quint16 DebugOutput::m_savedViewStateVersion = 1; void traceCb(const char * text) @@ -44,6 +44,8 @@ void traceCb(const char * text) } } +// TODO: move callback & filter to own thread + DebugOutput::DebugOutput(QWidget * parent, SimulatorInterface *simulator): QWidget(parent), ui(new Ui::DebugOutput), @@ -54,7 +56,7 @@ DebugOutput::DebugOutput(QWidget * parent, SimulatorInterface *simulator): m_dataPrintFreq(m_dataPrintFreqDefault), m_running(false), m_filterExclude(true), - overflowReported(false) + m_overflowReported(false) { ui->setupUi(this); @@ -96,6 +98,8 @@ DebugOutput::DebugOutput(QWidget * parent, SimulatorInterface *simulator): connect(ui->filterText, &QComboBox::currentTextChanged, this, &DebugOutput::onFilterTextChanged); connect(m_tmrDataPrint, &QTimer::timeout, this, &DebugOutput::processBytesReceived); + + start(); } DebugOutput::~DebugOutput() @@ -173,16 +177,18 @@ void DebugOutput::traceCallback(const char * text) isBlank = line.contains(blank); m_mtxDataBuffer.lock(); - if (isBlank && m_dataBuffer.size()) + if (isBlank && m_dataBuffer.size()) { m_dataBuffer[m_dataBuffer.size()-1] += line; - else - m_dataBuffer.append(text); - if (m_dataBuffer.size() > m_dataBufferMaxSize) { - m_dataBuffer.removeFirst(); - if (!overflowReported) { - overflowReported = true; - qDebug() << __FILE__ << __LINE__ << "Line buffer overflow! size >" << m_dataBufferMaxSize; + } + else { + if (m_dataBuffer.size() > m_dataBufferMaxSize) { + m_dataBuffer.removeFirst(); + if (!m_overflowReported) { + m_overflowReported = true; + qWarning() << "Line buffer overflow! size >" << m_dataBufferMaxSize; + } } + m_dataBuffer.append(text); } m_mtxDataBuffer.unlock(); } @@ -191,12 +197,13 @@ void DebugOutput::processBytesReceived() { QString text; bool fltMatch; + static quint32 cycleCount = 0; const QTextCursor savedCursor(ui->console->textCursor()); const int sbValue = ui->console->verticalScrollBar()->value(); const bool sbAtBottom = (sbValue == ui->console->verticalScrollBar()->maximum()); m_tmrDataPrint->stop(); - while (m_dataBuffer.size() > 1) { + while (m_dataBuffer.size() > 0) { m_mtxDataBuffer.lock(); text = m_dataBuffer.takeFirst(); m_mtxDataBuffer.unlock(); @@ -220,6 +227,11 @@ void DebugOutput::processBytesReceived() QCoreApplication::processEvents(); } m_tmrDataPrint->start(); + + ++cycleCount; + + if (!(cycleCount % (1000 / m_dataPrintFreqDefault * 30))) + m_overflowReported = false; } /* diff --git a/companion/src/simulation/debugoutput.h b/companion/src/simulation/debugoutput.h index eb84296535..5e81e1b3b2 100644 --- a/companion/src/simulation/debugoutput.h +++ b/companion/src/simulation/debugoutput.h @@ -73,7 +73,7 @@ class DebugOutput : public QWidget int m_dataPrintFreq; bool m_running; bool m_filterExclude; - bool overflowReported; + bool m_overflowReported; const static int m_dataBufferMaxSize; const static int m_dataPrintFreqDefault; diff --git a/companion/src/simulation/simulatormainwindow.cpp b/companion/src/simulation/simulatormainwindow.cpp index 1b46f1b680..1090fd3c56 100644 --- a/companion/src/simulation/simulatormainwindow.cpp +++ b/companion/src/simulation/simulatormainwindow.cpp @@ -229,8 +229,6 @@ bool SimulatorMainWindow::setOptions(SimulatorOptions & options, bool withSave) void SimulatorMainWindow::start() { - if (m_consoleWidget) - m_consoleWidget->start(); if (m_simulatorWidget) m_simulatorWidget->start(); if (m_outputsWidget)