From b89d12c45067c19a7dfdacb62c19f7ecebef0c85 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 13 Nov 2015 17:55:58 +0100 Subject: [PATCH] QmlProfiler: Include debug messages in trace A separate model will show them in the timeline for better orientation. Change-Id: I537bac82ddef6a8bcc64ae403731512f8edcc9db Reviewed-by: Joerg Bornemann --- .../qmldebug/qmldebugcommandlinearguments.h | 2 +- src/libs/qmldebug/qmlprofilereventtypes.h | 2 ++ src/libs/qmldebug/qmlprofilertraceclient.cpp | 17 ++++++++++++++++- .../qmlprofiler/qmlprofilerdatamodel.cpp | 7 +++++-- .../qmlprofiler/qmlprofilermodelmanager.cpp | 7 +++++-- .../qmlprofiler/qmlprofilertracefile.cpp | 17 +++++++++++++---- 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/libs/qmldebug/qmldebugcommandlinearguments.h b/src/libs/qmldebug/qmldebugcommandlinearguments.h index cfa26d929d0..f00559aaf19 100644 --- a/src/libs/qmldebug/qmldebugcommandlinearguments.h +++ b/src/libs/qmldebug/qmldebugcommandlinearguments.h @@ -50,7 +50,7 @@ static inline QString qmlDebugServices(QmlDebugServicesPreset preset) case QmlDebuggerServices: return QStringLiteral("DebugMessages,QmlDebugger,V8Debugger,QmlInspector"); case QmlProfilerServices: - return QStringLiteral("CanvasFrameRate,EngineControl"); + return QStringLiteral("CanvasFrameRate,EngineControl,DebugMessages"); case QmlNativeDebuggerServices: return QStringLiteral("NativeQmlDebugger"); default: diff --git a/src/libs/qmldebug/qmlprofilereventtypes.h b/src/libs/qmldebug/qmlprofilereventtypes.h index 60792b37c9b..1842fdb34c4 100644 --- a/src/libs/qmldebug/qmlprofilereventtypes.h +++ b/src/libs/qmldebug/qmlprofilereventtypes.h @@ -45,6 +45,7 @@ enum Message { PixmapCacheEvent, SceneGraphFrame, MemoryAllocation, + DebugMessage, MaximumMessage }; @@ -148,6 +149,7 @@ enum ProfileFeature { ProfileBinding, ProfileHandlingSignal, ProfileInputEvents, + ProfileDebugMessages, MaximumProfileFeature }; diff --git a/src/libs/qmldebug/qmlprofilertraceclient.cpp b/src/libs/qmldebug/qmlprofilertraceclient.cpp index 28ba5359949..e5662a313d9 100644 --- a/src/libs/qmldebug/qmlprofilertraceclient.cpp +++ b/src/libs/qmldebug/qmlprofilertraceclient.cpp @@ -30,6 +30,7 @@ #include "qmlprofilertraceclient.h" #include "qmlenginecontrolclient.h" +#include "qdebugmessageclient.h" namespace QmlDebug { @@ -53,6 +54,7 @@ public: QmlProfilerTraceClient *q; QmlEngineControlClient engineControl; + QScopedPointer messageClient; qint64 inProgressRanges; QStack rangeStartTimes[MaximumRangeType]; QStack rangeDatas[MaximumRangeType]; @@ -86,7 +88,7 @@ QmlProfilerTraceClient::QmlProfilerTraceClient(QmlDebugConnection *client, quint : QmlDebugClient(QLatin1String("CanvasFrameRate"), client) , d(new QmlProfilerTraceClientPrivate(this, client)) { - d->requestedFeatures = features; + setRequestedFeatures(features); connect(&d->engineControl, &QmlEngineControlClient::engineAboutToBeAdded, this, &QmlProfilerTraceClient::sendRecordingStatus); } @@ -152,6 +154,19 @@ quint64 QmlProfilerTraceClient::recordedFeatures() const void QmlProfilerTraceClient::setRequestedFeatures(quint64 features) { d->requestedFeatures = features; + if (features & static_cast(1) << ProfileDebugMessages) { + d->messageClient.reset(new QDebugMessageClient(connection())); + connect(d->messageClient.data(), &QDebugMessageClient::message, this, [this](QtMsgType type, + const QString &text, const QmlDebug::QDebugContextInfo &context) + { + emit this->rangedEvent(QmlDebug::DebugMessage, QmlDebug::MaximumRangeType, + type, context.timestamp, 0, text, + QmlDebug::QmlEventLocation(context.file, context.line, 1), 0, 0, + 0, 0, 0); + }); + } else { + d->messageClient.reset(); + } } void QmlProfilerTraceClient::setFlushInterval(quint32 flushInterval) diff --git a/src/plugins/qmlprofiler/qmlprofilerdatamodel.cpp b/src/plugins/qmlprofiler/qmlprofilerdatamodel.cpp index bab4affe1fa..4d5ef9c86f3 100644 --- a/src/plugins/qmlprofiler/qmlprofilerdatamodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerdatamodel.cpp @@ -266,8 +266,11 @@ void QmlProfilerDataModel::addQmlEvent(QmlDebug::Message message, QmlDebug::Rang Q_D(QmlProfilerDataModel); QString displayName; - QmlEventTypeData typeData(displayName, location, message, rangeType, detailType, data); - QmlEventData eventData(startTime, duration, -1, ndata1, ndata2, ndata3, ndata4, ndata5); + QmlEventTypeData typeData(displayName, location, message, rangeType, detailType, + message == QmlDebug::DebugMessage ? QString() : data); + QmlEventData eventData = (message == QmlDebug::DebugMessage) ? + QmlEventData(startTime, duration, -1, data) : + QmlEventData(startTime, duration, -1, ndata1, ndata2, ndata3, ndata4, ndata5); QHash::Iterator it = d->eventTypeIds.find(typeData); if (it != d->eventTypeIds.end()) { diff --git a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp index 0d1c6510df3..90e035b86b5 100644 --- a/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp +++ b/src/plugins/qmlprofiler/qmlprofilermodelmanager.cpp @@ -45,7 +45,7 @@ namespace QmlProfiler { namespace Internal { -static const char *ProfileFeatureNames[QmlDebug::MaximumProfileFeature] = { +static const char *ProfileFeatureNames[] = { QT_TRANSLATE_NOOP("MainView", "JavaScript"), QT_TRANSLATE_NOOP("MainView", "Memory Usage"), QT_TRANSLATE_NOOP("MainView", "Pixmap Cache"), @@ -56,9 +56,12 @@ static const char *ProfileFeatureNames[QmlDebug::MaximumProfileFeature] = { QT_TRANSLATE_NOOP("MainView", "Creating"), QT_TRANSLATE_NOOP("MainView", "Binding"), QT_TRANSLATE_NOOP("MainView", "Handling Signal"), - QT_TRANSLATE_NOOP("MainView", "Input Events") + QT_TRANSLATE_NOOP("MainView", "Input Events"), + QT_TRANSLATE_NOOP("MainView", "Debug Messages") }; +Q_STATIC_ASSERT(sizeof(ProfileFeatureNames) == sizeof(char *) * QmlDebug::MaximumProfileFeature); + ///////////////////////////////////////////////////////////////////// QmlProfilerTraceTime::QmlProfilerTraceTime(QObject *parent) : QObject(parent), m_startTime(-1), m_endTime(-1) diff --git a/src/plugins/qmlprofiler/qmlprofilertracefile.cpp b/src/plugins/qmlprofiler/qmlprofilertracefile.cpp index ceadbdbf946..141ba200ef3 100644 --- a/src/plugins/qmlprofiler/qmlprofilertracefile.cpp +++ b/src/plugins/qmlprofiler/qmlprofilertracefile.cpp @@ -65,7 +65,8 @@ static const char *MESSAGE_STRINGS[] = { "Complete", "PixmapCache", "SceneGraph", - "MemoryAllocation" + "MemoryAllocation", + "DebugMessage" }; Q_STATIC_ASSERT(sizeof(MESSAGE_STRINGS) == QmlDebug::MaximumMessage * sizeof(const char *)); @@ -226,6 +227,8 @@ QmlDebug::ProfileFeature featureFromEvent(const QmlProfilerDataModel::QmlEventTy return ProfileSceneGraph; case MemoryAllocation: return ProfileMemory; + case DebugMessage: + return ProfileDebugMessages; default: return MaximumProfileFeature; } @@ -235,8 +238,6 @@ void QmlProfilerFileReader::loadEventData(QXmlStreamReader &stream) { QTC_ASSERT(stream.name() == _("eventData"), return); - QXmlStreamAttributes attributes = stream.attributes(); - int eventIndex = -1; QmlProfilerDataModel::QmlEventTypeData event = { QString(), // displayname @@ -327,7 +328,8 @@ void QmlProfilerFileReader::loadEventData(QXmlStreamReader &stream) elementName == _("sgEventType") || elementName == _("memoryEventType") || elementName == _("mouseEvent") || - elementName == _("keyEvent")) { + elementName == _("keyEvent") || + elementName == _("level")) { event.detailType = readData.toInt(); break; } @@ -417,6 +419,8 @@ void QmlProfilerFileReader::loadProfilerDataModel(QXmlStreamReader &stream) range.setNumericData(1, attributes.value(_("data1")).toLongLong()); if (attributes.hasAttribute(_("data2"))) range.setNumericData(2, attributes.value(_("data2")).toLongLong()); + if (attributes.hasAttribute(_("text"))) + range.setStringData(attributes.value(_("text")).toString()); range.setTypeIndex(attributes.value(_("eventIndex")).toInt()); @@ -585,6 +589,8 @@ void QmlProfilerFileWriter::save(QIODevice *device) stream.writeTextElement(_("sgEventType"), QString::number(event.detailType)); } else if (event.message == MemoryAllocation) { stream.writeTextElement(_("memoryEventType"), QString::number(event.detailType)); + } else if (event.message == DebugMessage) { + stream.writeTextElement(_("level"), QString::number(event.detailType)); } stream.writeEndElement(); incrementProgress(); @@ -652,6 +658,9 @@ void QmlProfilerFileWriter::save(QIODevice *device) if (event.message == MemoryAllocation) stream.writeAttribute(_("amount"), QString::number(range.numericData(0))); + if (event.message == DebugMessage) + stream.writeAttribute(_("text"), range.stringData()); + stream.writeEndElement(); incrementProgress(); }