aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/qmlprofilerextension/memoryusagemodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/qmlprofilerextension/memoryusagemodel.cpp')
-rw-r--r--plugins/qmlprofilerextension/memoryusagemodel.cpp158
1 files changed, 62 insertions, 96 deletions
diff --git a/plugins/qmlprofilerextension/memoryusagemodel.cpp b/plugins/qmlprofilerextension/memoryusagemodel.cpp
index 5a83899cd7..516bcc2c03 100644
--- a/plugins/qmlprofilerextension/memoryusagemodel.cpp
+++ b/plugins/qmlprofilerextension/memoryusagemodel.cpp
@@ -19,7 +19,6 @@
#include "memoryusagemodel.h"
#include "qmldebug/qmlprofilereventtypes.h"
#include "qmlprofiler/qmlprofilermodelmanager.h"
-#include "qmlprofiler/abstracttimelinemodel_p.h"
#include <QStack>
@@ -28,53 +27,33 @@ namespace Internal {
using namespace QmlProfiler;
-class MemoryUsageModel::MemoryUsageModelPrivate : public AbstractTimelineModelPrivate
+MemoryUsageModel::MemoryUsageModel(QmlProfilerModelManager *manager, QObject *parent) :
+ QmlProfilerTimelineModel(manager,
+ tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileMemory)),
+ QmlDebug::MemoryAllocation, QmlDebug::MaximumRangeType, parent)
{
-public:
- static QString memoryTypeName(int type);
-
- QVector<MemoryAllocation> data;
- qint64 maxSize;
-private:
- Q_DECLARE_PUBLIC(MemoryUsageModel)
-};
-
-MemoryUsageModel::MemoryUsageModel(QObject *parent)
- : AbstractTimelineModel(new MemoryUsageModelPrivate(),
- tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileMemory)),
- QmlDebug::MemoryAllocation, QmlDebug::MaximumRangeType, parent)
-{
- Q_D(MemoryUsageModel);
- d->maxSize = 1;
-}
-
-quint64 MemoryUsageModel::features() const
-{
- // Will listen to all range events, too, to determine context.
- return (1 << QmlDebug::ProfileMemory) | QmlDebug::Constants::QML_JS_RANGE_FEATURES;
+ m_maxSize = 1;
+ announceFeatures((1 << QmlDebug::ProfileMemory) | QmlDebug::Constants::QML_JS_RANGE_FEATURES);
}
int MemoryUsageModel::rowMaxValue(int rowNumber) const
{
- Q_D(const MemoryUsageModel);
Q_UNUSED(rowNumber);
- return d->maxSize;
+ return m_maxSize;
}
int MemoryUsageModel::row(int index) const
{
- Q_D(const MemoryUsageModel);
- QmlDebug::MemoryType type = d->data[index].type;
+ int type = selectionId(index);
if (type == QmlDebug::HeapPage || type == QmlDebug::LargeItem)
return 1;
else
return 2;
}
-int MemoryUsageModel::selectionId(int index) const
+int MemoryUsageModel::typeId(int index) const
{
- Q_D(const MemoryUsageModel);
- return d->data[index].type;
+ return m_data[index].typeId;
}
QColor MemoryUsageModel::color(int index) const
@@ -84,8 +63,7 @@ QColor MemoryUsageModel::color(int index) const
float MemoryUsageModel::relativeHeight(int index) const
{
- Q_D(const MemoryUsageModel);
- return qMin(1.0f, (float)d->data[index].size / (float)d->maxSize);
+ return qMin(1.0f, (float)m_data[index].size / (float)m_maxSize);
}
QVariantMap MemoryUsageModel::location(int index) const
@@ -94,13 +72,12 @@ QVariantMap MemoryUsageModel::location(int index) const
static const QLatin1String line("line");
static const QLatin1String column("column");
- Q_D(const MemoryUsageModel);
QVariantMap result;
- int originType = d->data[index].originTypeIndex;
+ int originType = m_data[index].originTypeIndex;
if (originType > -1) {
const QmlDebug::QmlEventLocation &location =
- d->modelManager->qmlModel()->getEventTypes().at(originType).location;
+ modelManager()->qmlModel()->getEventTypes().at(originType).location;
result.insert(file, location.filename);
result.insert(line, location.line);
@@ -112,36 +89,25 @@ QVariantMap MemoryUsageModel::location(int index) const
QVariantList MemoryUsageModel::labels() const
{
- Q_D(const MemoryUsageModel);
QVariantList result;
- if (d->expanded && !d->hidden && !isEmpty()) {
- {
- QVariantMap element;
- element.insert(QLatin1String("description"), QVariant(tr("Memory Allocation")));
+ QVariantMap element;
+ element.insert(QLatin1String("description"), QVariant(tr("Memory Allocation")));
+ element.insert(QLatin1String("id"), QVariant(QmlDebug::HeapPage));
+ result << element;
- element.insert(QLatin1String("id"), QVariant(QmlDebug::HeapPage));
- result << element;
- }
-
- {
- QVariantMap element;
- element.insert(QLatin1String("description"), QVariant(tr("Memory Usage")));
-
- element.insert(QLatin1String("id"), QVariant(QmlDebug::SmallItem));
- result << element;
- }
- }
+ element.clear();
+ element.insert(QLatin1String("description"), QVariant(tr("Memory Usage")));
+ element.insert(QLatin1String("id"), QVariant(QmlDebug::SmallItem));
+ result << element;
return result;
}
QVariantMap MemoryUsageModel::details(int index) const
{
- Q_D(const MemoryUsageModel);
-
QVariantMap result;
- const MemoryAllocation *ev = &d->data[index];
+ const MemoryAllocation *ev = &m_data[index];
if (ev->allocated >= -ev->deallocated)
result.insert(QLatin1String("displayName"), tr("Memory Allocated"));
@@ -157,11 +123,11 @@ QVariantMap MemoryUsageModel::details(int index) const
result.insert(tr("Deallocated"), QString::fromLatin1("%1 bytes").arg(-ev->deallocated));
result.insert(tr("Deallocations"), QString::number(ev->deallocations));
}
- result.insert(tr("Type"), QVariant(MemoryUsageModelPrivate::memoryTypeName(ev->type)));
+ result.insert(tr("Type"), QVariant(memoryTypeName(selectionId(index))));
if (ev->originTypeIndex != -1) {
result.insert(tr("Location"),
- d->modelManager->qmlModel()->getEventTypes().at(ev->originTypeIndex).displayName);
+ modelManager()->qmlModel()->getEventTypes().at(ev->originTypeIndex).displayName);
}
return result;
}
@@ -177,9 +143,8 @@ struct RangeStackFrame {
void MemoryUsageModel::loadData()
{
- Q_D(MemoryUsageModel);
clear();
- QmlProfilerDataModel *simpleModel = d->modelManager->qmlModel();
+ QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
@@ -189,7 +154,6 @@ void MemoryUsageModel::loadData()
int currentJSHeapIndex = -1;
QStack<RangeStackFrame> rangeStack;
- MemoryAllocation dummy;
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes();
foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) {
@@ -205,74 +169,76 @@ void MemoryUsageModel::loadData()
}
if (type.detailType == QmlDebug::SmallItem || type.detailType == QmlDebug::LargeItem) {
- MemoryAllocation &last = currentUsageIndex > -1 ? d->data[currentUsageIndex] : dummy;
- if (!rangeStack.empty() && type.detailType == last.type &&
- last.originTypeIndex == rangeStack.top().originTypeIndex &&
- rangeStack.top().startTime < range(currentUsageIndex).start) {
- last.update(event.numericData1);
- currentUsage = last.size;
+ if (!rangeStack.empty() && currentUsageIndex > -1 &&
+ type.detailType == selectionId(currentUsageIndex) &&
+ m_data[currentUsageIndex].originTypeIndex == rangeStack.top().originTypeIndex &&
+ rangeStack.top().startTime < startTime(currentUsageIndex)) {
+ m_data[currentUsageIndex].update(event.numericData1);
+ currentUsage = m_data[currentUsageIndex].size;
} else {
- MemoryAllocation allocation(QmlDebug::SmallItem, currentUsage,
+ MemoryAllocation allocation(event.typeIndex, currentUsage,
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex);
allocation.update(event.numericData1);
currentUsage = allocation.size;
if (currentUsageIndex != -1) {
insertEnd(currentUsageIndex,
- event.startTime - range(currentUsageIndex).start - 1);
+ event.startTime - startTime(currentUsageIndex) - 1);
}
- currentUsageIndex = insertStart(event.startTime, event.typeIndex);
- d->data.insert(currentUsageIndex, allocation);
+ currentUsageIndex = insertStart(event.startTime, QmlDebug::SmallItem);
+ m_data.insert(currentUsageIndex, allocation);
}
}
if (type.detailType == QmlDebug::HeapPage || type.detailType == QmlDebug::LargeItem) {
- MemoryAllocation &last = currentJSHeapIndex > -1 ? d->data[currentJSHeapIndex] : dummy;
- if (!rangeStack.empty() && type.detailType == last.type &&
- last.originTypeIndex == rangeStack.top().originTypeIndex &&
- rangeStack.top().startTime < range(currentJSHeapIndex).start) {
- last.update(event.numericData1);
- currentSize = last.size;
+ if (!rangeStack.empty() && currentJSHeapIndex > -1 &&
+ type.detailType == selectionId(currentJSHeapIndex) &&
+ m_data[currentJSHeapIndex].originTypeIndex ==
+ rangeStack.top().originTypeIndex &&
+ rangeStack.top().startTime < startTime(currentJSHeapIndex)) {
+ m_data[currentJSHeapIndex].update(event.numericData1);
+ currentSize = m_data[currentJSHeapIndex].size;
} else {
- MemoryAllocation allocation((QmlDebug::MemoryType)type.detailType, currentSize,
+ MemoryAllocation allocation(event.typeIndex, currentSize,
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex);
allocation.update(event.numericData1);
currentSize = allocation.size;
- if (currentSize > d->maxSize)
- d->maxSize = currentSize;
+ if (currentSize > m_maxSize)
+ m_maxSize = currentSize;
if (currentJSHeapIndex != -1)
insertEnd(currentJSHeapIndex,
- event.startTime - range(currentJSHeapIndex).start - 1);
- currentJSHeapIndex = insertStart(event.startTime, event.typeIndex);
- d->data.insert(currentJSHeapIndex, allocation);
+ event.startTime - startTime(currentJSHeapIndex) - 1);
+ currentJSHeapIndex = insertStart(event.startTime, type.detailType);
+ m_data.insert(currentJSHeapIndex, allocation);
}
}
- d->modelManager->modelProxyCountUpdated(d->modelId, count(),
- simpleModel->getEvents().count());
+ updateProgress(count(), simpleModel->getEvents().count());
}
if (currentJSHeapIndex != -1)
- insertEnd(currentJSHeapIndex, traceEndTime() - range(currentJSHeapIndex).start - 1);
+ insertEnd(currentJSHeapIndex, modelManager()->traceTime()->endTime() -
+ startTime(currentJSHeapIndex) - 1);
if (currentUsageIndex != -1)
- insertEnd(currentUsageIndex, traceEndTime() - range(currentUsageIndex).start - 1);
+ insertEnd(currentUsageIndex, modelManager()->traceTime()->endTime() -
+ startTime(currentUsageIndex) - 1);
computeNesting();
- d->expandedRowCount = d->collapsedRowCount = 3;
- d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
+ setExpandedRowCount(3);
+ setCollapsedRowCount(3);
+ updateProgress(1, 1);
}
void MemoryUsageModel::clear()
{
- Q_D(MemoryUsageModel);
- d->data.clear();
- d->maxSize = 1;
- AbstractTimelineModel::clear();
+ m_data.clear();
+ m_maxSize = 1;
+ QmlProfilerTimelineModel::clear();
}
-QString MemoryUsageModel::MemoryUsageModelPrivate::memoryTypeName(int type)
+QString MemoryUsageModel::memoryTypeName(int type)
{
switch (type) {
case QmlDebug::HeapPage: return tr("Heap Allocation");
@@ -283,9 +249,9 @@ QString MemoryUsageModel::MemoryUsageModelPrivate::memoryTypeName(int type)
}
}
-MemoryUsageModel::MemoryAllocation::MemoryAllocation(QmlDebug::MemoryType type, qint64 baseAmount,
+MemoryUsageModel::MemoryAllocation::MemoryAllocation(int type, qint64 baseAmount,
int originTypeIndex) :
- type(type), size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0),
+ typeId(type), size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0),
originTypeIndex(originTypeIndex)
{
}