From f2bf0a5e4219db89aca3f383ff3c7466e0590e28 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 23 Aug 2010 14:27:24 +0200 Subject: [PATCH] Debugger: Move handling of 'Log timestamps' into outputwindow. Remove some unused leftovers from DebuggerOuputWindow. --- src/plugins/debugger/debuggeroutputwindow.cpp | 29 +++++++++++++++++++ src/plugins/debugger/debuggeroutputwindow.h | 11 ++----- src/plugins/debugger/gdb/gdbengine.cpp | 15 ++++------ 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/plugins/debugger/debuggeroutputwindow.cpp b/src/plugins/debugger/debuggeroutputwindow.cpp index cc83911adf1..1f401e35e90 100644 --- a/src/plugins/debugger/debuggeroutputwindow.cpp +++ b/src/plugins/debugger/debuggeroutputwindow.cpp @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -411,6 +412,9 @@ void DebuggerOutputWindow::showOutput(int channel, const QString &output) QTextCursor cursor = oldCursor; cursor.movePosition(QTextCursor::End); bool atEnd = oldCursor.position() == cursor.position(); + + if (theDebuggerBoolSetting(LogTimeStamps)) + m_combinedText->appendPlainText(charForChannel(LogTime) + logTimeStamp()); foreach (QString line, output.split('\n')) { // FIXME: QTextEdit asserts on really long lines... const int n = 30000; @@ -431,6 +435,8 @@ void DebuggerOutputWindow::showOutput(int channel, const QString &output) void DebuggerOutputWindow::showInput(int channel, const QString &input) { Q_UNUSED(channel) + if (theDebuggerBoolSetting(LogTimeStamps)) + m_inputText->appendPlainText(logTimeStamp()); m_inputText->appendPlainText(input); QTextCursor cursor = m_inputText->textCursor(); cursor.movePosition(QTextCursor::End); @@ -461,4 +467,27 @@ QString DebuggerOutputWindow::inputContents() const return m_inputText->toPlainText(); } +QString DebuggerOutputWindow::logTimeStamp() +{ + // Cache the last log time entry by ms. If time progresses, + // report the difference to the last time stamp in ms. + static const QString logTimeFormat(QLatin1String("hh:mm:ss.zzz")); + static QTime lastTime = QTime::currentTime(); + static QString lastTimeStamp = lastTime.toString(logTimeFormat); + + const QTime currentTime = QTime::currentTime(); + if (currentTime != lastTime) { + const int elapsedMS = lastTime.msecsTo(currentTime); + lastTime = currentTime; + lastTimeStamp = lastTime.toString(logTimeFormat); + // Append time elapsed + QString rc = lastTimeStamp; + rc += QLatin1String(" ["); + rc += QString::number(elapsedMS); + rc += QLatin1String("ms]"); + return rc; + } + return lastTimeStamp; +} + #include "debuggeroutputwindow.moc" diff --git a/src/plugins/debugger/debuggeroutputwindow.h b/src/plugins/debugger/debuggeroutputwindow.h index e203211468c..55edbb060fc 100644 --- a/src/plugins/debugger/debuggeroutputwindow.h +++ b/src/plugins/debugger/debuggeroutputwindow.h @@ -46,20 +46,15 @@ class DebuggerOutputWindow : public QWidget Q_OBJECT public: - DebuggerOutputWindow(QWidget *parent = 0); + explicit DebuggerOutputWindow(QWidget *parent = 0); - QWidget *outputWidget(QWidget *) { return this; } - QList toolBarWidgets() const { return QList(); } - - QString name() const { return windowTitle(); } - void visibilityChanged(bool /*visible*/) {} - - void bringPaneToForeground() { emit showPage(); } void setCursor(const QCursor &cursor); QString combinedContents() const; QString inputContents() const; + static QString logTimeStamp(); + public slots: void clearContents(); void showOutput(int channel, const QString &output); diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 26bd43ce6d8..7932a4611a7 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -66,6 +66,7 @@ #include "sourcefileswindow.h" #include "debuggerdialogs.h" +#include "debuggeroutputwindow.h" #include #include @@ -312,25 +313,19 @@ void GdbEngine::readDebugeeOutput(const QByteArray &data) void GdbEngine::handleResponse(const QByteArray &buff) { - static QTime lastTime; - - if (theDebuggerBoolSetting(LogTimeStamps)) - showMessage(currentTime(), LogTime); showMessage(QString::fromLocal8Bit(buff, buff.length()), LogOutput); #if 0 + static QTime lastTime; qDebug() // << "#### start response handling #### " - << currentTime() << lastTime.msecsTo(QTime::currentTime()) << "ms," << "buf:" << buff.left(1500) << "..." //<< "buf:" << buff << "size:" << buff.size(); + lastTime = QTime::currentTime(); #else //qDebug() << "buf:" << buff; #endif - - lastTime = QTime::currentTime(); - if (buff.isEmpty() || buff == "(gdb) ") return; @@ -2013,7 +2008,7 @@ void GdbEngine::setTokenBarrier() PENDING_DEBUG("\n--- token barrier ---\n"); showMessage(_("--- token barrier ---"), LogMiscInput); if (theDebuggerBoolSetting(LogTimeStamps)) - showMessage(currentTime(), LogMiscInput); + showMessage(DebuggerOutputWindow::logTimeStamp(), LogMiscInput); m_oldestAcceptableToken = currentToken(); } @@ -3369,7 +3364,7 @@ void GdbEngine::rebuildWatchModel() m_processedNames.clear(); PENDING_DEBUG("REBUILDING MODEL" << count); if (theDebuggerBoolSetting(LogTimeStamps)) - showMessage(currentTime(), LogMiscInput); + showMessage(DebuggerOutputWindow::logTimeStamp(), LogMiscInput); showMessage(_("").arg(count), LogMiscInput); showStatusMessage(tr("Finished retrieving data"), 400); watchHandler()->endCycle();