diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-06-03 15:50:32 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-06-06 16:17:04 +0000 |
commit | 34d53223121838c5043ba035277970b103df9148 (patch) | |
tree | ce3fc2d5bd00ebd9c0acea13391d1f1dfc633cd3 /src/plugins/qmlprofiler/memoryusagemodel.cpp | |
parent | 887a71c493761a0c55319874363cb8f4c0992560 (diff) |
QmlProfiler: Don't continue memory usage ranges across other ranges
When a function returns and is called again, without memory being
allocated or freed in between, we don't want to assign any memory
events from the second call to a memory range starting in the first
call.
Change-Id: I3d5cd10381f31ff73849a5a396ad6bda7661afec
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/plugins/qmlprofiler/memoryusagemodel.cpp')
-rw-r--r-- | src/plugins/qmlprofiler/memoryusagemodel.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/plugins/qmlprofiler/memoryusagemodel.cpp b/src/plugins/qmlprofiler/memoryusagemodel.cpp index 386444c776e..b7f85e1684a 100644 --- a/src/plugins/qmlprofiler/memoryusagemodel.cpp +++ b/src/plugins/qmlprofiler/memoryusagemodel.cpp @@ -27,6 +27,8 @@ #include "qmlprofilermodelmanager.h" #include "qmlprofilereventtypes.h" +#include <utils/qtcassert.h> + namespace QmlProfiler { namespace Internal { @@ -137,15 +139,33 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type m_rangeStack.push(RangeStackFrame(event.typeIndex(), event.timestamp())); else if (event.rangeStage() == RangeEnd) m_rangeStack.pop(); + + m_continuation = ContinueNothing; } return; } + auto canContinue = [&](EventContinuation continuation) { + QTC_ASSERT(continuation != ContinueNothing, return false); + if ((m_continuation & continuation) == 0) + return false; + + int currentIndex = (continuation == ContinueAllocation ? m_currentJSHeapIndex : + m_currentUsageIndex); + + if (m_rangeStack.isEmpty()) { + qint64 amount = event.number<qint64>(0); + // outside of ranges show monotonous allocation or deallocation + return (amount >= 0 && m_data[currentIndex].allocated >= 0) + || (amount < 0 && m_data[currentIndex].deallocated > 0); + } else { + return m_data[currentIndex].typeId == m_rangeStack.top().originTypeIndex + && m_rangeStack.top().startTime < startTime(currentIndex); + } + }; + if (type.detailType == SmallItem || type.detailType == LargeItem) { - if (!m_rangeStack.empty() && m_currentUsageIndex > -1 && - type.detailType == selectionId(m_currentUsageIndex) && - m_data[m_currentUsageIndex].typeId == m_rangeStack.top().originTypeIndex && - m_rangeStack.top().startTime < startTime(m_currentUsageIndex)) { + if (canContinue(ContinueUsage)) { m_data[m_currentUsageIndex].update(event.number<qint64>(0)); m_currentUsage = m_data[m_currentUsageIndex].size; } else { @@ -162,15 +182,13 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type } m_currentUsageIndex = insertStart(event.timestamp(), SmallItem); m_data.insert(m_currentUsageIndex, allocation); + m_continuation = m_continuation | ContinueUsage; } } if (type.detailType == HeapPage || type.detailType == LargeItem) { - if (!m_rangeStack.empty() && m_currentJSHeapIndex > -1 && - type.detailType == selectionId(m_currentJSHeapIndex) && - m_data[m_currentJSHeapIndex].typeId == - m_rangeStack.top().originTypeIndex && - m_rangeStack.top().startTime < startTime(m_currentJSHeapIndex)) { + if (canContinue(ContinueAllocation) + && type.detailType == selectionId(m_currentJSHeapIndex)) { m_data[m_currentJSHeapIndex].update(event.number<qint64>(0)); m_currentSize = m_data[m_currentJSHeapIndex].size; } else { @@ -188,6 +206,7 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type event.timestamp() - startTime(m_currentJSHeapIndex) - 1); m_currentJSHeapIndex = insertStart(event.timestamp(), type.detailType); m_data.insert(m_currentJSHeapIndex, allocation); + m_continuation = m_continuation | ContinueAllocation; } } } @@ -215,6 +234,7 @@ void MemoryUsageModel::clear() m_currentUsage = 0; m_currentUsageIndex = -1; m_currentJSHeapIndex = -1; + m_continuation = ContinueNothing; m_rangeStack.clear(); QmlProfilerTimelineModel::clear(); } |