Write memory events into tracefiles generated by qmlprofiler
authorUlf Hermann <ulf.hermann@digia.com>
Mon, 16 Jun 2014 11:33:33 +0000 (13:33 +0200)
committerUlf Hermann <ulf.hermann@digia.com>
Tue, 12 Aug 2014 08:16:40 +0000 (10:16 +0200)
Change-Id: Ic01505194f29967ed1aad16fe36e14dc5532ae25
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/debugger/qqmlprofilerdefinitions_p.h
tools/qmlprofiler/qmlprofilerapplication.cpp
tools/qmlprofiler/qmlprofilerclient.cpp
tools/qmlprofiler/qmlprofilerclient.h
tools/qmlprofiler/qmlprofilerdata.cpp
tools/qmlprofiler/qmlprofilerdata.h

index 689a06a..f05a7fe 100644 (file)
@@ -43,6 +43,7 @@
 #define QQMLPROFILERDEFINITIONS_P_H
 
 #include <private/qtqmlglobal_p.h>
+#include <private/qv4profiling_p.h>
 
 //
 //  W A R N I N G
@@ -127,6 +128,8 @@ struct QQmlProfilerDefinitions {
 
         MaximumSceneGraphFrameType
     };
+
+    typedef QV4::Profiling::MemoryType MemoryType;
 };
 
 QT_END_NAMESPACE
index e235f6c..9828074 100644 (file)
@@ -117,6 +117,10 @@ QmlProfilerApplication::QmlProfilerApplication(int &argc, char **argv) :
                                                      QmlEventLocation,int,int,int)),
             &m_profilerData, SLOT(addPixmapCacheEvent(QQmlProfilerService::PixmapEventType,qint64,
                                                       QmlEventLocation,int,int,int)));
+    connect(&m_qmlProfilerClient, SIGNAL(memoryAllocation(QQmlProfilerService::MemoryType,qint64,
+                                                          qint64)),
+            &m_profilerData, SLOT(addMemoryEvent(QQmlProfilerService::MemoryType,qint64,
+                                                 qint64)));
 
     connect(&m_qmlProfilerClient, SIGNAL(complete()), this, SLOT(qmlComplete()));
 
index 9322158..14fc817 100644 (file)
@@ -216,6 +216,12 @@ void QmlProfilerClient::messageReceived(const QByteArray &data)
         emit pixmapCache((QQmlProfilerService::PixmapEventType)pixEvTy, time,
                          QmlEventLocation(pixUrl,0,0), width, height, refcount);
         d->maximumTime = qMax(time, d->maximumTime);
+    } else if (messageType == QQmlProfilerService::MemoryAllocation) {
+        int type;
+        qint64 delta;
+        stream >> type >> delta;
+        emit memoryAllocation((QQmlProfilerService::MemoryType)type, time, delta);
+        d->maximumTime = qMax(time, d->maximumTime);
     } else {
         int range;
         stream >> range;
index 67e5046..cdf80ff 100644 (file)
@@ -108,6 +108,7 @@ signals:
                          qint64 numericData4, qint64 numericData5);
     void pixmapCache(QQmlProfilerService::PixmapEventType, qint64 time,
                      const QmlEventLocation &location, int width, int height, int refCount);
+    void memoryAllocation(QQmlProfilerService::MemoryType type, qint64 time, qint64 amount);
 
 protected:
     virtual void messageReceived(const QByteArray &);
index bf2d05e..85efab9 100644 (file)
@@ -378,6 +378,24 @@ void QmlProfilerData::addPixmapCacheEvent(QQmlProfilerDefinitions::PixmapEventTy
     d->startInstanceList.append(rangeEventStartInstance);
 }
 
+void QmlProfilerData::addMemoryEvent(QQmlProfilerService::MemoryType type, qint64 time,
+                                     qint64 size)
+{
+    setState(AcquiringData);
+    QString eventHashStr = QString::fromLatin1("MemoryAllocation:%1").arg(type);
+    QmlRangeEventData *newEvent;
+    if (d->eventDescriptions.contains(eventHashStr)) {
+        newEvent = d->eventDescriptions[eventHashStr];
+    } else {
+        newEvent = new QmlRangeEventData(eventHashStr, type, eventHashStr, QmlEventLocation(),
+                                         QString(), QQmlProfilerService::MemoryAllocation,
+                                         QQmlProfilerService::MaximumRangeType);
+        d->eventDescriptions.insert(eventHashStr, newEvent);
+    }
+    QmlRangeEventStartInstance rangeEventStartInstance(time, size, 0, 0, 0, 0, newEvent);
+    d->startInstanceList.append(rangeEventStartInstance);
+}
+
 QString QmlProfilerData::rootEventName()
 {
     return tr("<program>");
@@ -589,6 +607,9 @@ bool QmlProfilerData::save(const QString &filename)
         else if (eventData->message == QQmlProfilerService::SceneGraphFrame)
             stream.writeTextElement(QStringLiteral("sgEventType"),
                                     QString::number((int)eventData->detailType));
+        else if (eventData->message == QQmlProfilerService::MemoryAllocation)
+            stream.writeTextElement(QStringLiteral("memoryEventType"),
+                                    QString::number((int)eventData->detailType));
         stream.writeEndElement();
     }
     stream.writeEndElement(); // eventData
@@ -636,6 +657,8 @@ bool QmlProfilerData::save(const QString &filename)
             if (event.numericData5 > 0)
                 stream.writeAttribute(QStringLiteral("timing5"),
                                       QString::number(event.numericData5));
+        } else if (event.data->message == QQmlProfilerService::MemoryAllocation) {
+            stream.writeAttribute(QStringLiteral("amount"), QString::number(event.numericData1));
         }
         stream.writeEndElement();
     }
index 47da0ef..675c241 100644 (file)
@@ -95,6 +95,7 @@ public slots:
                                  qint64 numericData4, qint64 numericData5);
     void addPixmapCacheEvent(QQmlProfilerService::PixmapEventType type, qint64 time,
                              const QmlEventLocation &location, int width, int height, int refcount);
+    void addMemoryEvent(QQmlProfilerService::MemoryType type, qint64 time, qint64 size);
 
     void complete();
     bool save(const QString &filename);