[Simulator] Debug console output listener now starts immediately upon creation; Fix debug console not printing last line in buffer; Shorten debug output print time by 2ms; Don't check buffer if not appending line; Report buffer overflow errors every 30s (if still needed).

This commit is contained in:
Max Paperno
2017-02-17 04:24:17 -05:00
parent 25ea90817a
commit 357ffd0b92
3 changed files with 24 additions and 14 deletions
+23 -11
View File
@@ -33,7 +33,7 @@ extern AppData g; // ensure what "g" means
DebugOutput * traceCallbackInstance = 0; DebugOutput * traceCallbackInstance = 0;
const int DebugOutput::m_dataBufferMaxSize = 500; // lines of text (this is not the display buffer) 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; const quint16 DebugOutput::m_savedViewStateVersion = 1;
void traceCb(const char * text) 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): DebugOutput::DebugOutput(QWidget * parent, SimulatorInterface *simulator):
QWidget(parent), QWidget(parent),
ui(new Ui::DebugOutput), ui(new Ui::DebugOutput),
@@ -54,7 +56,7 @@ DebugOutput::DebugOutput(QWidget * parent, SimulatorInterface *simulator):
m_dataPrintFreq(m_dataPrintFreqDefault), m_dataPrintFreq(m_dataPrintFreqDefault),
m_running(false), m_running(false),
m_filterExclude(true), m_filterExclude(true),
overflowReported(false) m_overflowReported(false)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -96,6 +98,8 @@ DebugOutput::DebugOutput(QWidget * parent, SimulatorInterface *simulator):
connect(ui->filterText, &QComboBox::currentTextChanged, this, &DebugOutput::onFilterTextChanged); connect(ui->filterText, &QComboBox::currentTextChanged, this, &DebugOutput::onFilterTextChanged);
connect(m_tmrDataPrint, &QTimer::timeout, this, &DebugOutput::processBytesReceived); connect(m_tmrDataPrint, &QTimer::timeout, this, &DebugOutput::processBytesReceived);
start();
} }
DebugOutput::~DebugOutput() DebugOutput::~DebugOutput()
@@ -173,16 +177,18 @@ void DebugOutput::traceCallback(const char * text)
isBlank = line.contains(blank); isBlank = line.contains(blank);
m_mtxDataBuffer.lock(); m_mtxDataBuffer.lock();
if (isBlank && m_dataBuffer.size()) if (isBlank && m_dataBuffer.size()) {
m_dataBuffer[m_dataBuffer.size()-1] += line; m_dataBuffer[m_dataBuffer.size()-1] += line;
else }
m_dataBuffer.append(text); else {
if (m_dataBuffer.size() > m_dataBufferMaxSize) { if (m_dataBuffer.size() > m_dataBufferMaxSize) {
m_dataBuffer.removeFirst(); m_dataBuffer.removeFirst();
if (!overflowReported) { if (!m_overflowReported) {
overflowReported = true; m_overflowReported = true;
qDebug() << __FILE__ << __LINE__ << "Line buffer overflow! size >" << m_dataBufferMaxSize; qWarning() << "Line buffer overflow! size >" << m_dataBufferMaxSize;
}
} }
m_dataBuffer.append(text);
} }
m_mtxDataBuffer.unlock(); m_mtxDataBuffer.unlock();
} }
@@ -191,12 +197,13 @@ void DebugOutput::processBytesReceived()
{ {
QString text; QString text;
bool fltMatch; bool fltMatch;
static quint32 cycleCount = 0;
const QTextCursor savedCursor(ui->console->textCursor()); const QTextCursor savedCursor(ui->console->textCursor());
const int sbValue = ui->console->verticalScrollBar()->value(); const int sbValue = ui->console->verticalScrollBar()->value();
const bool sbAtBottom = (sbValue == ui->console->verticalScrollBar()->maximum()); const bool sbAtBottom = (sbValue == ui->console->verticalScrollBar()->maximum());
m_tmrDataPrint->stop(); m_tmrDataPrint->stop();
while (m_dataBuffer.size() > 1) { while (m_dataBuffer.size() > 0) {
m_mtxDataBuffer.lock(); m_mtxDataBuffer.lock();
text = m_dataBuffer.takeFirst(); text = m_dataBuffer.takeFirst();
m_mtxDataBuffer.unlock(); m_mtxDataBuffer.unlock();
@@ -220,6 +227,11 @@ void DebugOutput::processBytesReceived()
QCoreApplication::processEvents(); QCoreApplication::processEvents();
} }
m_tmrDataPrint->start(); m_tmrDataPrint->start();
++cycleCount;
if (!(cycleCount % (1000 / m_dataPrintFreqDefault * 30)))
m_overflowReported = false;
} }
/* /*
+1 -1
View File
@@ -73,7 +73,7 @@ class DebugOutput : public QWidget
int m_dataPrintFreq; int m_dataPrintFreq;
bool m_running; bool m_running;
bool m_filterExclude; bool m_filterExclude;
bool overflowReported; bool m_overflowReported;
const static int m_dataBufferMaxSize; const static int m_dataBufferMaxSize;
const static int m_dataPrintFreqDefault; const static int m_dataPrintFreqDefault;
@@ -229,8 +229,6 @@ bool SimulatorMainWindow::setOptions(SimulatorOptions & options, bool withSave)
void SimulatorMainWindow::start() void SimulatorMainWindow::start()
{ {
if (m_consoleWidget)
m_consoleWidget->start();
if (m_simulatorWidget) if (m_simulatorWidget)
m_simulatorWidget->start(); m_simulatorWidget->start();
if (m_outputsWidget) if (m_outputsWidget)