diff options
author | Ulf Hermann <ulf.hermann@digia.com> | 2014-06-24 11:53:47 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@digia.com> | 2014-07-02 12:21:16 +0300 |
commit | 3a5340e1a8ed20402995a333c49ca7f9e592677d (patch) | |
tree | 2e1c283df9b8b57302d4c6a9935f6a829d878e4c | |
parent | 7eca9fbc4205cc1e1c31c04674e9b9672f2b73ce (diff) | |
download | qt-creator-3a5340e1a8ed20402995a333c49ca7f9e592677d.tar.gz |
Group memory usage events by their cause and add location information
Change-Id: Id33fa51daffe97e9e60467942b92f0598a17c27d
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
-rw-r--r-- | plugins/qmlprofilerextension/memoryusagemodel.cpp | 111 | ||||
-rw-r--r-- | plugins/qmlprofilerextension/memoryusagemodel.h | 3 |
2 files changed, 91 insertions, 23 deletions
diff --git a/plugins/qmlprofilerextension/memoryusagemodel.cpp b/plugins/qmlprofilerextension/memoryusagemodel.cpp index 64a6aa44f8..8cf9a42158 100644 --- a/plugins/qmlprofilerextension/memoryusagemodel.cpp +++ b/plugins/qmlprofilerextension/memoryusagemodel.cpp @@ -22,7 +22,7 @@ #include "qmlprofiler/sortedtimelinemodel.h" #include "qmlprofiler/abstracttimelinemodel_p.h" -#include <QDebug> +#include <QStack> namespace QmlProfilerExtension { namespace Internal { @@ -88,6 +88,28 @@ float MemoryUsageModel::getHeight(int index) const return qMin(1.0f, (float)d->range(index).size / (float)d->maxSize); } +const QVariantMap MemoryUsageModel::getEventLocation(int index) const +{ + static const QLatin1String file("file"); + static const QLatin1String line("line"); + static const QLatin1String column("column"); + + Q_D(const MemoryUsageModel); + QVariantMap result; + + int originType = d->range(index).originTypeIndex; + if (originType > -1) { + const QmlDebug::QmlEventLocation &location = + d->modelManager->qmlModel()->getEventTypes().at(originType).location; + + result.insert(file, location.filename); + result.insert(line, location.line); + result.insert(column, location.column); + } + + return result; +} + const QVariantList MemoryUsageModel::getLabels() const { Q_D(const MemoryUsageModel); @@ -149,9 +171,25 @@ const QVariantList MemoryUsageModel::getEventDetails(int index) const result << res; } + if (ev->originTypeIndex != -1) { + QVariantMap valuePair; + valuePair.insert(tr("Location"), + d->modelManager->qmlModel()->getEventTypes().at(ev->originTypeIndex).displayName); + result << valuePair; + } + return result; } +struct RangeStackFrame { + RangeStackFrame() : originTypeIndex(-1), startTime(-1), endTime(-1) {} + RangeStackFrame(int originTypeIndex, qint64 startTime, qint64 endTime) : + originTypeIndex(originTypeIndex), startTime(startTime), endTime(endTime) {} + int originTypeIndex; + qint64 startTime; + qint64 endTime; +}; + void MemoryUsageModel::loadData() { Q_D(MemoryUsageModel); @@ -164,40 +202,67 @@ void MemoryUsageModel::loadData() qint64 currentUsage = 0; int currentUsageIndex = -1; int currentJSHeapIndex = -1; + + QStack<RangeStackFrame> rangeStack; + MemoryAllocation dummy = { + QmlDebug::MaximumMemoryType, -1, -1 , -1 + }; + const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes(); foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) { const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex]; - if (!eventAccepted(type)) + while (!rangeStack.empty() && rangeStack.top().endTime < event.startTime) + rangeStack.pop(); + if (!eventAccepted(type)) { + if (type.rangeType != QmlDebug::MaximumRangeType) { + rangeStack.push(RangeStackFrame(event.typeIndex, event.startTime, + event.startTime + event.duration)); + } continue; + } if (type.detailType == QmlDebug::SmallItem || type.detailType == QmlDebug::LargeItem) { currentUsage += event.numericData1; - MemoryAllocation allocation = { - QmlDebug::SmallItem, - currentUsage, - event.numericData1 - }; - if (currentUsageIndex != -1) { - d->insertEnd(currentUsageIndex, - event.startTime - d->range(currentUsageIndex).start - 1); + MemoryAllocation &last = currentUsageIndex > -1 ? d->data(currentUsageIndex) : dummy; + if (!rangeStack.empty() && last.originTypeIndex == rangeStack.top().originTypeIndex) { + last.size = currentUsage; + last.delta += event.numericData1; + } else { + MemoryAllocation allocation = { + QmlDebug::SmallItem, + currentUsage, + event.numericData1, + rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex + }; + if (currentUsageIndex != -1) { + d->insertEnd(currentUsageIndex, + event.startTime - d->range(currentUsageIndex).start - 1); + } + currentUsageIndex = d->insertStart(event.startTime, allocation); } - currentUsageIndex = d->insertStart(event.startTime, allocation); } if (type.detailType == QmlDebug::HeapPage || type.detailType == QmlDebug::LargeItem) { currentSize += event.numericData1; - MemoryAllocation allocation = { - (QmlDebug::MemoryType)type.detailType, - currentSize, - event.numericData1 - }; - - if (currentSize > d->maxSize) - d->maxSize = currentSize; - if (currentJSHeapIndex != -1) - d->insertEnd(currentJSHeapIndex, - event.startTime - d->range(currentJSHeapIndex).start - 1); - currentJSHeapIndex = d->insertStart(event.startTime, allocation); + MemoryAllocation &last = currentJSHeapIndex > -1 ? d->data(currentJSHeapIndex) : dummy; + if (!rangeStack.empty() && last.originTypeIndex == rangeStack.top().originTypeIndex) { + last.size = currentSize; + last.delta += event.numericData1; + } else { + MemoryAllocation allocation = { + (QmlDebug::MemoryType)type.detailType, + currentSize, + event.numericData1, + rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex + }; + + if (currentSize > d->maxSize) + d->maxSize = currentSize; + if (currentJSHeapIndex != -1) + d->insertEnd(currentJSHeapIndex, + event.startTime - d->range(currentJSHeapIndex).start - 1); + currentJSHeapIndex = d->insertStart(event.startTime, allocation); + } } d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), simpleModel->getEvents().count()); diff --git a/plugins/qmlprofilerextension/memoryusagemodel.h b/plugins/qmlprofilerextension/memoryusagemodel.h index c256b02590..7559c9c749 100644 --- a/plugins/qmlprofilerextension/memoryusagemodel.h +++ b/plugins/qmlprofilerextension/memoryusagemodel.h @@ -38,6 +38,7 @@ public: QmlDebug::MemoryType type; qint64 size; qint64 delta; + int originTypeIndex; }; MemoryUsageModel(QObject *parent = 0); @@ -50,6 +51,8 @@ public: QColor getColor(int index) const; float getHeight(int index) const; + const QVariantMap getEventLocation(int index) const; + const QVariantList getLabels() const; const QVariantList getEventDetails(int index) const; |