summaryrefslogtreecommitdiffstats
path: root/src/declarative/debugger
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2010-11-05 03:27:30 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2010-11-19 00:56:45 (GMT)
commit7aebf28291288ea6e8c1d9d28f4ed752b00dca97 (patch)
tree26584dd314ac01df1ead5538919fe0db0cf962cb /src/declarative/debugger
parent3c05109ce609574f1525c465f68817d3af39397e (diff)
downloadQt-7aebf28291288ea6e8c1d9d28f4ed752b00dca97.zip
Qt-7aebf28291288ea6e8c1d9d28f4ed752b00dca97.tar.gz
Qt-7aebf28291288ea6e8c1d9d28f4ed752b00dca97.tar.bz2
Make deferred tracing less expensive (real-time cost is the same)
Diffstat (limited to 'src/declarative/debugger')
-rw-r--r--src/declarative/debugger/qdeclarativedebugtrace.cpp44
-rw-r--r--src/declarative/debugger/qdeclarativedebugtrace_p.h32
2 files changed, 47 insertions, 29 deletions
diff --git a/src/declarative/debugger/qdeclarativedebugtrace.cpp b/src/declarative/debugger/qdeclarativedebugtrace.cpp
index cd4306b..7f970bf 100644
--- a/src/declarative/debugger/qdeclarativedebugtrace.cpp
+++ b/src/declarative/debugger/qdeclarativedebugtrace.cpp
@@ -47,6 +47,20 @@
Q_GLOBAL_STATIC(QDeclarativeDebugTrace, traceInstance);
+// convert to a QByteArray that can be sent to the debug client
+// use of QDataStream can skew results if m_deferredSend == false
+// (see tst_qperformancetimer::trace() benchmark)
+QByteArray QDeclarativeDebugData::toByteArray() const
+{
+ QByteArray data;
+ //### using QDataStream is relatively expensive
+ QDataStream ds(&data, QIODevice::WriteOnly);
+ ds << time << messageType << detailType;
+ if (messageType == (int)QDeclarativeDebugTrace::RangeData)
+ ds << detailData;
+ return data;
+}
+
QDeclarativeDebugTrace::QDeclarativeDebugTrace()
: QDeclarativeDebugService(QLatin1String("CanvasFrameRate")),
m_enabled(false), m_deferredSend(true)
@@ -83,10 +97,8 @@ void QDeclarativeDebugTrace::addEventImpl(EventType event)
if (status() != Enabled || !m_enabled)
return;
- QByteArray data;
- QDataStream ds(&data, QIODevice::WriteOnly);
- ds << m_timer.elapsed() << (int)Event << (int)event;
- processMessage(data);
+ QDeclarativeDebugData ed = {m_timer.elapsed(), (int)Event, (int)event, QString()};
+ processMessage(ed);
}
void QDeclarativeDebugTrace::startRangeImpl(RangeType range)
@@ -94,10 +106,8 @@ void QDeclarativeDebugTrace::startRangeImpl(RangeType range)
if (status() != Enabled || !m_enabled)
return;
- QByteArray data;
- QDataStream ds(&data, QIODevice::WriteOnly);
- ds << m_timer.elapsed() << (int)RangeStart << (int)range;
- processMessage(data);
+ QDeclarativeDebugData rd = {m_timer.elapsed(), (int)RangeStart, (int)range, QString()};
+ processMessage(rd);
}
void QDeclarativeDebugTrace::rangeDataImpl(RangeType range, const QString &rData)
@@ -105,10 +115,8 @@ void QDeclarativeDebugTrace::rangeDataImpl(RangeType range, const QString &rData
if (status() != Enabled || !m_enabled)
return;
- QByteArray data;
- QDataStream ds(&data, QIODevice::WriteOnly);
- ds << m_timer.elapsed() << (int)RangeData << (int)range << rData;
- processMessage(data);
+ QDeclarativeDebugData rd = {m_timer.elapsed(), (int)RangeData, (int)range, rData};
+ processMessage(rd);
}
void QDeclarativeDebugTrace::endRangeImpl(RangeType range)
@@ -116,22 +124,20 @@ void QDeclarativeDebugTrace::endRangeImpl(RangeType range)
if (status() != Enabled || !m_enabled)
return;
- QByteArray data;
- QDataStream ds(&data, QIODevice::WriteOnly);
- ds << m_timer.elapsed() << (int)RangeEnd << (int)range;
- processMessage(data);
+ QDeclarativeDebugData rd = {m_timer.elapsed(), (int)RangeEnd, (int)range, QString()};
+ processMessage(rd);
}
/*
Either send the message directly, or queue up
a list of messages to send later (via sendMessages)
*/
-void QDeclarativeDebugTrace::processMessage(const QByteArray &message)
+void QDeclarativeDebugTrace::processMessage(const QDeclarativeDebugData &message)
{
if (m_deferredSend)
m_data.append(message);
else
- sendMessage(message);
+ sendMessage(message.toByteArray());
}
/*
@@ -142,7 +148,7 @@ 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));
+ sendMessage(m_data.at(i).toByteArray());
m_data.clear();
}
}
diff --git a/src/declarative/debugger/qdeclarativedebugtrace_p.h b/src/declarative/debugger/qdeclarativedebugtrace_p.h
index b935fbe..86c0987 100644
--- a/src/declarative/debugger/qdeclarativedebugtrace_p.h
+++ b/src/declarative/debugger/qdeclarativedebugtrace_p.h
@@ -49,18 +49,22 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
+struct QDeclarativeDebugData
+{
+ qint64 time;
+ int messageType;
+ int detailType;
+ QString detailData;
+
+ QByteArray toByteArray() const;
+};
+
+Q_DECLARE_TYPEINFO(QDeclarativeDebugData,Q_PRIMITIVE_TYPE);
+
class QUrl;
class Q_AUTOTEST_EXPORT QDeclarativeDebugTrace : public QDeclarativeDebugService
{
public:
- enum EventType {
- FramePaint,
- Mouse,
- Key,
-
- MaximumEventType
- };
-
enum Message {
Event,
RangeStart,
@@ -70,6 +74,14 @@ public:
MaximumMessage
};
+ enum EventType {
+ FramePaint,
+ Mouse,
+ Key,
+
+ MaximumEventType
+ };
+
enum RangeType {
Painting,
Compiling,
@@ -94,12 +106,12 @@ private:
void startRangeImpl(RangeType);
void rangeDataImpl(RangeType, const QString &);
void endRangeImpl(RangeType);
- void processMessage(const QByteArray &);
+ void processMessage(const QDeclarativeDebugData &);
void sendMessages();
QPerformanceTimer m_timer;
bool m_enabled;
bool m_deferredSend;
- QList<QByteArray> m_data;
+ QList<QDeclarativeDebugData> m_data;
};
QT_END_NAMESPACE