diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2010-11-03 02:53:41 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2010-11-19 00:51:03 (GMT) |
commit | 1a8bf28261facf1e97cecf842fcbfff48b383984 (patch) | |
tree | dd3d8e7fdc32d65a6f00b26a642ae9847e31075e /src/declarative/debugger | |
parent | 458c237ea807330de8b15cb2b6e99f564bb7fd66 (diff) | |
download | Qt-1a8bf28261facf1e97cecf842fcbfff48b383984.zip Qt-1a8bf28261facf1e97cecf842fcbfff48b383984.tar.gz Qt-1a8bf28261facf1e97cecf842fcbfff48b383984.tar.bz2 |
Add support for a record-then-send debug process.
Diffstat (limited to 'src/declarative/debugger')
-rw-r--r-- | src/declarative/debugger/qdeclarativedebugtrace.cpp | 55 | ||||
-rw-r--r-- | src/declarative/debugger/qdeclarativedebugtrace_p.h | 7 |
2 files changed, 53 insertions, 9 deletions
diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp index 03e2d56..5edc3b6 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace.cpp +++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp @@ -43,11 +43,13 @@ #include <QtCore/qdatastream.h> #include <QtCore/qurl.h> +#include <QtCore/qtimer.h> Q_GLOBAL_STATIC(QDeclarativeDebugTrace, traceInstance); QDeclarativeDebugTrace::QDeclarativeDebugTrace() -: QDeclarativeDebugService(QLatin1String("CanvasFrameRate")) +: QDeclarativeDebugService(QLatin1String("CanvasFrameRate")), + m_enabled(false), m_deferredSend(true) { m_timer.start(); } @@ -78,45 +80,80 @@ void QDeclarativeDebugTrace::endRange(RangeType t) void QDeclarativeDebugTrace::addEventImpl(EventType event) { - if (status() != Enabled) + if (status() != Enabled || !m_enabled) return; QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); ds << m_timer.elapsed() << (int)Event << (int)event; - sendMessage(data); + processMessage(data); } void QDeclarativeDebugTrace::startRangeImpl(RangeType range) { - if (status() != Enabled) + if (status() != Enabled || !m_enabled) return; QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); ds << m_timer.elapsed() << (int)RangeStart << (int)range; - sendMessage(data); + processMessage(data); } void QDeclarativeDebugTrace::rangeDataImpl(RangeType range, const QUrl &u) { - if (status() != Enabled) + if (status() != Enabled || !m_enabled) return; QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); ds << m_timer.elapsed() << (int)RangeData << (int)range << (QString)u.toString(); - sendMessage(data); + processMessage(data); } void QDeclarativeDebugTrace::endRangeImpl(RangeType range) { - if (status() != Enabled) + if (status() != Enabled || !m_enabled) return; QByteArray data; QDataStream ds(&data, QIODevice::WriteOnly); ds << m_timer.elapsed() << (int)RangeEnd << (int)range; - sendMessage(data); + processMessage(data); } +/* + Either send the message directly, or queue up + a list of messages to send later (via sendMessages) +*/ +void QDeclarativeDebugTrace::processMessage(const QByteArray &message) +{ + if (m_deferredSend) + m_data.append(message); + else + sendMessage(message); +} + +/* + Send the messages queued up by processMessage +*/ +void QDeclarativeDebugTrace::sendMessages() +{ + if (m_deferredSend) { + //### this is a suboptimal way to send batched messages + for (int i = 0; i < m_data.count(); ++i) + sendMessage(m_data.at(i)); + m_data.clear(); + } +} + +void QDeclarativeDebugTrace::messageReceived(const QByteArray &message) +{ + QByteArray rwData = message; + QDataStream stream(&rwData, QIODevice::ReadOnly); + + stream >> m_enabled; + + if (!m_enabled) + sendMessages(); +} diff --git a/src/declarative/debugger/qdeclarativedebugtrace_p.h b/src/declarative/debugger/qdeclarativedebugtrace_p.h index d6fe0b0..c7c61bd 100644 --- a/src/declarative/debugger/qdeclarativedebugtrace_p.h +++ b/src/declarative/debugger/qdeclarativedebugtrace_p.h @@ -86,12 +86,19 @@ public: static void endRange(RangeType); QDeclarativeDebugTrace(); +protected: + virtual void messageReceived(const QByteArray &); private: void addEventImpl(EventType); void startRangeImpl(RangeType); void rangeDataImpl(RangeType, const QUrl &); void endRangeImpl(RangeType); + void processMessage(const QByteArray &); + void sendMessages(); QPerformanceTimer m_timer; + bool m_enabled; + bool m_deferredSend; + QList<QByteArray> m_data; }; QT_END_NAMESPACE |