diff options
-rw-r--r-- | src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp | 59 | ||||
-rw-r--r-- | src/qml/debugger/qqmlprofiler_p.h | 26 |
2 files changed, 40 insertions, 45 deletions
diff --git a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp index 688ced26ec..0ee69a6e02 100644 --- a/src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp +++ b/src/plugins/qmltooling/qmldbg_profiler/qqmlprofileradapter.cpp @@ -65,51 +65,46 @@ QQmlProfilerAdapter::QQmlProfilerAdapter(QQmlProfilerService *service, QQmlEngin // convert to QByteArrays that can be sent to the debug client // use of QDataStream can skew results // (see tst_qqmldebugtrace::trace() benchmark) -static void qQmlProfilerDataToByteArrays(const QQmlProfilerData *d, QList<QByteArray> &messages) +static void qQmlProfilerDataToByteArrays(const QQmlProfilerData &d, QList<QByteArray> &messages) { QQmlDebugPacket ds; - Q_ASSERT_X(((d->messageType | d->detailType) & (1 << 31)) == 0, Q_FUNC_INFO, - "You can use at most 31 message types and 31 detail types."); - for (uint decodedMessageType = 0; (d->messageType >> decodedMessageType) != 0; + Q_ASSERT_X((d.messageType & (1 << 31)) == 0, Q_FUNC_INFO, + "You can use at most 31 message types."); + for (quint32 decodedMessageType = 0; (d.messageType >> decodedMessageType) != 0; ++decodedMessageType) { - if ((d->messageType & (1 << decodedMessageType)) == 0) + if ((d.messageType & (1 << decodedMessageType)) == 0) continue; - for (uint decodedDetailType = 0; (d->detailType >> decodedDetailType) != 0; - ++decodedDetailType) { - if ((d->detailType & (1 << decodedDetailType)) == 0) - continue; + //### using QDataStream is relatively expensive + ds << d.time << decodedMessageType << static_cast<quint32>(d.detailType); - //### using QDataStream is relatively expensive - ds << d->time << decodedMessageType << decodedDetailType; - - switch (decodedMessageType) { - case QQmlProfilerDefinitions::RangeStart: - case QQmlProfilerDefinitions::RangeEnd: - break; - case QQmlProfilerDefinitions::RangeData: - ds << (d->detailString.isEmpty() ? d->detailUrl.toString() : d->detailString); - break; - case QQmlProfilerDefinitions::RangeLocation: - ds << (d->detailUrl.isEmpty() ? d->detailString : d->detailUrl.toString()) << d->x - << d->y; - break; - default: - Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid message type."); - break; - } - messages.append(ds.squeezedData()); - ds.clear(); + switch (decodedMessageType) { + case QQmlProfilerDefinitions::RangeStart: + case QQmlProfilerDefinitions::RangeEnd: + break; + case QQmlProfilerDefinitions::RangeData: + ds << (d.detailString.isEmpty() ? d.detailUrl.toString() : d.detailString); + break; + case QQmlProfilerDefinitions::RangeLocation: + ds << (d.detailUrl.isEmpty() ? d.detailString : d.detailUrl.toString()) << d.x << d.y; + break; + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid message type."); + break; } + messages.append(ds.squeezedData()); + ds.clear(); } } qint64 QQmlProfilerAdapter::sendMessages(qint64 until, QList<QByteArray> &messages) { while (next != data.length()) { - if (data[next].time > until || messages.length() > s_numMessagesPerBatch) - return data[next].time; - qQmlProfilerDataToByteArrays(&(data[next++]), messages); + const QQmlProfilerData &nextData = data.at(next); + if (nextData.time > until || messages.length() > s_numMessagesPerBatch) + return nextData.time; + qQmlProfilerDataToByteArrays(nextData, messages); + ++next; } next = 0; diff --git a/src/qml/debugger/qqmlprofiler_p.h b/src/qml/debugger/qqmlprofiler_p.h index 24001159f3..d32b350055 100644 --- a/src/qml/debugger/qqmlprofiler_p.h +++ b/src/qml/debugger/qqmlprofiler_p.h @@ -77,33 +77,33 @@ QT_BEGIN_NAMESPACE // independently when converting to QByteArrays. Thus you can only pack // messages if their data doesn't overlap. It's up to you to figure that // out. -struct Q_AUTOTEST_EXPORT QQmlProfilerData +struct Q_AUTOTEST_EXPORT QQmlProfilerData : public QQmlProfilerDefinitions { QQmlProfilerData() {} - QQmlProfilerData(qint64 time, int messageType, int detailType, const QUrl &url, + QQmlProfilerData(qint64 time, int messageType, RangeType detailType, const QUrl &url, int x = 0, int y = 0) : time(time), messageType(messageType), detailType(detailType), detailUrl(url), x(x), y(y) {} - QQmlProfilerData(qint64 time, int messageType, int detailType, const QString &str, + QQmlProfilerData(qint64 time, int messageType, RangeType detailType, const QString &str, int x = 0, int y = 0) : time(time), messageType(messageType), detailType(detailType),detailString(str), x(x), y(y) {} - QQmlProfilerData(qint64 time, int messageType, int detailType, const QString &str, + QQmlProfilerData(qint64 time, int messageType, RangeType detailType, const QString &str, const QUrl &url, int x = 0, int y = 0) : time(time), messageType(messageType), detailType(detailType), detailString(str), detailUrl(url), x(x), y(y) {} - QQmlProfilerData(qint64 time, int messageType, int detailType) : + QQmlProfilerData(qint64 time, int messageType, RangeType detailType) : time(time), messageType(messageType), detailType(detailType) {} qint64 time; int messageType; //bit field of QQmlProfilerService::Message - int detailType; + RangeType detailType; // RangeData prefers detailString; RangeLocation prefers detailUrl. QString detailString; //used by RangeData and possibly by RangeLocation @@ -121,7 +121,7 @@ public: void startBinding(const QQmlSourceLocation &location) { m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), - (1 << RangeStart | 1 << RangeLocation), 1 << Binding, + (1 << RangeStart | 1 << RangeLocation), Binding, location.sourceFile, qmlSourceCoordinate(location.line), qmlSourceCoordinate(location.column))); } @@ -131,39 +131,39 @@ public: { m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), (1 << RangeStart | 1 << RangeLocation | 1 << RangeData), - 1 << Compiling, url, 1, 1)); + Compiling, url, 1, 1)); } void startHandlingSignal(const QQmlSourceLocation &location) { m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), - (1 << RangeStart | 1 << RangeLocation), 1 << HandlingSignal, + (1 << RangeStart | 1 << RangeLocation), HandlingSignal, location.sourceFile, location.line, location.column)); } void startCreating() { - m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), 1 << RangeStart, 1 << Creating)); + m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), 1 << RangeStart, Creating)); } void startCreating(const QString &typeName, const QUrl &fileName, int line, int column) { m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), (1 << RangeStart | 1 << RangeLocation | 1 << RangeData), - 1 << Creating, typeName, fileName, line, column)); + Creating, typeName, fileName, line, column)); } void updateCreating(const QString &typeName, const QUrl &fileName, int line, int column) { m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), (1 << RangeLocation | 1 << RangeData), - 1 << Creating, typeName, fileName, line, column)); + Creating, typeName, fileName, line, column)); } template<RangeType Range> void endRange() { - m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), 1 << RangeEnd, 1 << Range)); + m_data.append(QQmlProfilerData(m_timer.nsecsElapsed(), 1 << RangeEnd, Range)); } QQmlProfiler(); |