QmlProfiler: Use origin type's ID for memory allocations

We want the editor to jump to the right source location when selecting
different events from the timeline. If all memory events have the same
ID this doesn't work. Now they of course have the IDs of the origin
events, but that's not a problem because when you select first the
memory event and then its origin, the editor position does in fact not
have to change.

As an added benefit, the typeId cannot be -1 anymore now.

Change-Id: I95520eeb3e6902e046f3f552c74dba776e7c8b62
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Ulf Hermann
2016-05-26 09:27:59 +02:00
parent 1b650190d8
commit 1b9b59a45f
2 changed files with 22 additions and 25 deletions

View File

@@ -77,15 +77,12 @@ QVariantMap MemoryUsageModel::location(int index) const
QVariantMap result; QVariantMap result;
int originType = m_data[index].originTypeIndex; const QmlEventLocation &location =
if (originType > -1) { modelManager()->qmlModel()->eventTypes().at(m_data[index].typeId).location;
const QmlEventLocation &location =
modelManager()->qmlModel()->eventTypes().at(originType).location;
result.insert(file, location.filename); result.insert(file, location.filename);
result.insert(line, location.line); result.insert(line, location.line);
result.insert(column, location.column); result.insert(column, location.column);
}
return result; return result;
} }
@@ -128,10 +125,8 @@ QVariantMap MemoryUsageModel::details(int index) const
} }
result.insert(tr("Type"), QVariant(memoryTypeName(selectionId(index)))); result.insert(tr("Type"), QVariant(memoryTypeName(selectionId(index))));
if (ev->originTypeIndex != -1) { result.insert(tr("Location"),
result.insert(tr("Location"), modelManager()->qmlModel()->eventTypes().at(ev->typeId).displayName);
modelManager()->qmlModel()->eventTypes().at(ev->originTypeIndex).displayName);
}
return result; return result;
} }
@@ -155,13 +150,15 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type
if (type.detailType == SmallItem || type.detailType == LargeItem) { if (type.detailType == SmallItem || type.detailType == LargeItem) {
if (!m_rangeStack.empty() && m_currentUsageIndex > -1 && if (!m_rangeStack.empty() && m_currentUsageIndex > -1 &&
type.detailType == selectionId(m_currentUsageIndex) && type.detailType == selectionId(m_currentUsageIndex) &&
m_data[m_currentUsageIndex].originTypeIndex == m_rangeStack.top().originTypeIndex && m_data[m_currentUsageIndex].typeId == m_rangeStack.top().originTypeIndex &&
m_rangeStack.top().startTime < startTime(m_currentUsageIndex)) { m_rangeStack.top().startTime < startTime(m_currentUsageIndex)) {
m_data[m_currentUsageIndex].update(event.number<qint64>(0)); m_data[m_currentUsageIndex].update(event.number<qint64>(0));
m_currentUsage = m_data[m_currentUsageIndex].size; m_currentUsage = m_data[m_currentUsageIndex].size;
} else { } else {
MemoryAllocationItem allocation(event.typeIndex(), m_currentUsage, MemoryAllocationItem allocation(
m_rangeStack.empty() ? -1 : m_rangeStack.top().originTypeIndex); m_rangeStack.empty() ? event.typeIndex() :
m_rangeStack.top().originTypeIndex,
m_currentUsage);
allocation.update(event.number<qint64>(0)); allocation.update(event.number<qint64>(0));
m_currentUsage = allocation.size; m_currentUsage = allocation.size;
@@ -177,14 +174,16 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type
if (type.detailType == HeapPage || type.detailType == LargeItem) { if (type.detailType == HeapPage || type.detailType == LargeItem) {
if (!m_rangeStack.empty() && m_currentJSHeapIndex > -1 && if (!m_rangeStack.empty() && m_currentJSHeapIndex > -1 &&
type.detailType == selectionId(m_currentJSHeapIndex) && type.detailType == selectionId(m_currentJSHeapIndex) &&
m_data[m_currentJSHeapIndex].originTypeIndex == m_data[m_currentJSHeapIndex].typeId ==
m_rangeStack.top().originTypeIndex && m_rangeStack.top().originTypeIndex &&
m_rangeStack.top().startTime < startTime(m_currentJSHeapIndex)) { m_rangeStack.top().startTime < startTime(m_currentJSHeapIndex)) {
m_data[m_currentJSHeapIndex].update(event.number<qint64>(0)); m_data[m_currentJSHeapIndex].update(event.number<qint64>(0));
m_currentSize = m_data[m_currentJSHeapIndex].size; m_currentSize = m_data[m_currentJSHeapIndex].size;
} else { } else {
MemoryAllocationItem allocation(event.typeIndex(), m_currentSize, MemoryAllocationItem allocation(
m_rangeStack.empty() ? -1 : m_rangeStack.top().originTypeIndex); m_rangeStack.empty() ? event.typeIndex() :
m_rangeStack.top().originTypeIndex,
m_currentSize);
allocation.update(event.number<qint64>(0)); allocation.update(event.number<qint64>(0));
m_currentSize = allocation.size; m_currentSize = allocation.size;
@@ -237,10 +236,9 @@ QString MemoryUsageModel::memoryTypeName(int type)
} }
} }
MemoryUsageModel::MemoryAllocationItem::MemoryAllocationItem(int type, qint64 baseAmount, MemoryUsageModel::MemoryAllocationItem::MemoryAllocationItem(int typeId, qint64 baseAmount) :
int originTypeIndex) : size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0),
typeId(type), size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0), typeId(typeId)
originTypeIndex(originTypeIndex)
{ {
} }

View File

@@ -41,15 +41,14 @@ class MemoryUsageModel : public QmlProfilerTimelineModel
public: public:
struct MemoryAllocationItem { struct MemoryAllocationItem {
int typeId;
qint64 size; qint64 size;
qint64 allocated; qint64 allocated;
qint64 deallocated; qint64 deallocated;
int allocations; int allocations;
int deallocations; int deallocations;
int originTypeIndex; int typeId;
MemoryAllocationItem(int typeId = -1, qint64 baseAmount = 0, int originTypeIndex = -1); MemoryAllocationItem(int typeId = -1, qint64 baseAmount = 0);
void update(qint64 amount); void update(qint64 amount);
}; };