2014-05-27 16:30:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-14 11:03:04 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-05-27 16:30:48 +02:00
|
|
|
**
|
2016-01-14 11:03:04 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-05-27 16:30:48 +02:00
|
|
|
**
|
2016-01-14 11:03:04 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2014-05-27 16:30:48 +02:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-14 11:03:04 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-05-27 16:30:48 +02:00
|
|
|
**
|
2016-01-14 11:03:04 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-05-27 16:30:48 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "memoryusagemodel.h"
|
2016-04-26 10:21:00 +02:00
|
|
|
#include "qmlprofilermodelmanager.h"
|
2016-05-02 12:18:57 +02:00
|
|
|
#include "qmlprofilereventtypes.h"
|
2014-05-27 16:30:48 +02:00
|
|
|
|
2016-06-03 15:50:32 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2016-04-26 10:21:00 +02:00
|
|
|
namespace QmlProfiler {
|
2014-05-27 16:30:48 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-10-29 10:31:28 +01:00
|
|
|
MemoryUsageModel::MemoryUsageModel(QmlProfilerModelManager *manager, QObject *parent) :
|
2016-05-02 12:18:57 +02:00
|
|
|
QmlProfilerTimelineModel(manager, MemoryAllocation, MaximumRangeType, ProfileMemory, parent)
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
2016-04-28 16:19:17 +02:00
|
|
|
// Announce additional features. The base class already announces the main feature.
|
|
|
|
|
announceFeatures(Constants::QML_JS_RANGE_FEATURES);
|
2014-09-08 18:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-24 11:53:19 +02:00
|
|
|
int MemoryUsageModel::rowMaxValue(int rowNumber) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(rowNumber);
|
2014-10-27 19:54:23 +01:00
|
|
|
return m_maxSize;
|
2014-06-24 11:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-17 13:30:53 +01:00
|
|
|
int MemoryUsageModel::expandedRow(int index) const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
2014-10-28 14:30:04 +01:00
|
|
|
int type = selectionId(index);
|
2016-05-02 12:18:57 +02:00
|
|
|
return (type == HeapPage || type == LargeItem) ? 1 : 2;
|
2014-11-17 13:30:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int MemoryUsageModel::collapsedRow(int index) const
|
|
|
|
|
{
|
|
|
|
|
return expandedRow(index);
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 14:30:04 +01:00
|
|
|
int MemoryUsageModel::typeId(int index) const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
2014-10-28 14:30:04 +01:00
|
|
|
return m_data[index].typeId;
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-08 14:53:47 +02:00
|
|
|
QColor MemoryUsageModel::color(int index) const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
2014-08-29 17:12:11 +02:00
|
|
|
return colorBySelectionId(index);
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-02 12:30:40 +02:00
|
|
|
float MemoryUsageModel::relativeHeight(int index) const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
2014-10-27 19:54:23 +01:00
|
|
|
return qMin(1.0f, (float)m_data[index].size / (float)m_maxSize);
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-08 14:53:47 +02:00
|
|
|
QVariantMap MemoryUsageModel::location(int index) const
|
2014-06-24 11:53:47 +02:00
|
|
|
{
|
2016-06-03 14:02:51 +02:00
|
|
|
return locationFromTypeId(index);
|
2014-06-24 11:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-08 14:53:47 +02:00
|
|
|
QVariantList MemoryUsageModel::labels() const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
|
|
|
|
QVariantList result;
|
|
|
|
|
|
2014-10-29 10:42:22 +01:00
|
|
|
QVariantMap element;
|
2016-06-03 14:02:51 +02:00
|
|
|
element.insert(QLatin1String("description"), tr("Memory Allocation"));
|
|
|
|
|
element.insert(QLatin1String("id"), HeapPage);
|
2014-10-29 10:42:22 +01:00
|
|
|
result << element;
|
|
|
|
|
|
|
|
|
|
element.clear();
|
2016-06-03 14:02:51 +02:00
|
|
|
element.insert(QLatin1String("description"), tr("Memory Usage"));
|
|
|
|
|
element.insert(QLatin1String("id"), SmallItem);
|
2014-10-29 10:42:22 +01:00
|
|
|
result << element;
|
2014-05-27 16:30:48 +02:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 14:41:44 +02:00
|
|
|
QVariantMap MemoryUsageModel::details(int index) const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
2014-07-07 14:41:44 +02:00
|
|
|
QVariantMap result;
|
2016-05-02 12:18:57 +02:00
|
|
|
const MemoryAllocationItem *ev = &m_data[index];
|
2014-05-27 16:30:48 +02:00
|
|
|
|
2014-07-11 11:01:47 +02:00
|
|
|
if (ev->allocated >= -ev->deallocated)
|
2014-07-07 14:41:44 +02:00
|
|
|
result.insert(QLatin1String("displayName"), tr("Memory Allocated"));
|
2014-07-11 10:09:08 +02:00
|
|
|
else
|
2014-07-07 14:41:44 +02:00
|
|
|
result.insert(QLatin1String("displayName"), tr("Memory Freed"));
|
2014-05-27 16:30:48 +02:00
|
|
|
|
2016-06-03 14:02:51 +02:00
|
|
|
result.insert(tr("Total"), tr("%1 bytes").arg(ev->size));
|
2014-07-11 11:01:47 +02:00
|
|
|
if (ev->allocations > 0) {
|
2016-06-03 14:02:51 +02:00
|
|
|
result.insert(tr("Allocated"), tr("%1 bytes").arg(ev->allocated));
|
2014-07-07 14:41:44 +02:00
|
|
|
result.insert(tr("Allocations"), QString::number(ev->allocations));
|
2014-07-11 11:01:47 +02:00
|
|
|
}
|
|
|
|
|
if (ev->deallocations > 0) {
|
2016-06-03 14:02:51 +02:00
|
|
|
result.insert(tr("Deallocated"), tr("%1 bytes").arg(-ev->deallocated));
|
2014-07-07 14:41:44 +02:00
|
|
|
result.insert(tr("Deallocations"), QString::number(ev->deallocations));
|
2014-07-11 11:01:47 +02:00
|
|
|
}
|
2016-06-03 14:02:51 +02:00
|
|
|
QString memoryTypeName;
|
|
|
|
|
switch (selectionId(index)) {
|
|
|
|
|
case HeapPage: memoryTypeName = tr("Heap Allocation"); break;
|
|
|
|
|
case LargeItem: memoryTypeName = tr("Large Item Allocation"); break;
|
|
|
|
|
case SmallItem: memoryTypeName = tr("Heap Usage"); break;
|
|
|
|
|
default: Q_UNREACHABLE();
|
|
|
|
|
}
|
|
|
|
|
result.insert(tr("Type"), memoryTypeName);
|
2014-07-07 14:41:44 +02:00
|
|
|
|
2016-05-26 09:27:59 +02:00
|
|
|
result.insert(tr("Location"),
|
2016-06-06 19:51:55 +02:00
|
|
|
modelManager()->qmlModel()->eventTypes().at(ev->typeId).displayName());
|
2014-05-27 16:30:48 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
bool MemoryUsageModel::accepted(const QmlEventType &type) const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
2016-06-06 19:51:55 +02:00
|
|
|
return QmlProfilerTimelineModel::accepted(type) || type.rangeType() != MaximumRangeType;
|
2016-04-26 13:23:35 +02:00
|
|
|
}
|
2014-05-27 16:30:48 +02:00
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
|
|
|
|
|
{
|
2016-06-06 19:51:55 +02:00
|
|
|
if (type.message() != MemoryAllocation) {
|
|
|
|
|
if (type.rangeType() != MaximumRangeType) {
|
2016-04-28 16:13:16 +02:00
|
|
|
if (event.rangeStage() == RangeStart)
|
|
|
|
|
m_rangeStack.push(RangeStackFrame(event.typeIndex(), event.timestamp()));
|
|
|
|
|
else if (event.rangeStage() == RangeEnd)
|
|
|
|
|
m_rangeStack.pop();
|
2016-06-03 15:50:32 +02:00
|
|
|
|
|
|
|
|
m_continuation = ContinueNothing;
|
2014-06-24 11:53:47 +02:00
|
|
|
}
|
2016-04-26 13:23:35 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2014-05-27 16:30:48 +02:00
|
|
|
|
2016-06-03 15:50:32 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-06 19:51:55 +02:00
|
|
|
if (type.detailType() == SmallItem || type.detailType() == LargeItem) {
|
2016-06-03 15:50:32 +02:00
|
|
|
if (canContinue(ContinueUsage)) {
|
2016-04-26 13:23:35 +02:00
|
|
|
m_data[m_currentUsageIndex].update(event.number<qint64>(0));
|
|
|
|
|
m_currentUsage = m_data[m_currentUsageIndex].size;
|
|
|
|
|
} else {
|
2016-05-26 09:27:59 +02:00
|
|
|
MemoryAllocationItem allocation(
|
|
|
|
|
m_rangeStack.empty() ? event.typeIndex() :
|
|
|
|
|
m_rangeStack.top().originTypeIndex,
|
|
|
|
|
m_currentUsage);
|
2016-04-26 13:23:35 +02:00
|
|
|
allocation.update(event.number<qint64>(0));
|
|
|
|
|
m_currentUsage = allocation.size;
|
|
|
|
|
|
|
|
|
|
if (m_currentUsageIndex != -1) {
|
|
|
|
|
insertEnd(m_currentUsageIndex,
|
|
|
|
|
event.timestamp() - startTime(m_currentUsageIndex) - 1);
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
2016-04-26 13:23:35 +02:00
|
|
|
m_currentUsageIndex = insertStart(event.timestamp(), SmallItem);
|
|
|
|
|
m_data.insert(m_currentUsageIndex, allocation);
|
2016-06-03 15:50:32 +02:00
|
|
|
m_continuation = m_continuation | ContinueUsage;
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
2016-04-26 13:23:35 +02:00
|
|
|
}
|
2014-05-27 16:30:48 +02:00
|
|
|
|
2016-06-06 19:51:55 +02:00
|
|
|
if (type.detailType() == HeapPage || type.detailType() == LargeItem) {
|
2016-06-03 15:50:32 +02:00
|
|
|
if (canContinue(ContinueAllocation)
|
2016-06-06 19:51:55 +02:00
|
|
|
&& type.detailType() == selectionId(m_currentJSHeapIndex)) {
|
2016-04-26 13:23:35 +02:00
|
|
|
m_data[m_currentJSHeapIndex].update(event.number<qint64>(0));
|
|
|
|
|
m_currentSize = m_data[m_currentJSHeapIndex].size;
|
|
|
|
|
} else {
|
2016-05-26 09:27:59 +02:00
|
|
|
MemoryAllocationItem allocation(
|
|
|
|
|
m_rangeStack.empty() ? event.typeIndex() :
|
|
|
|
|
m_rangeStack.top().originTypeIndex,
|
|
|
|
|
m_currentSize);
|
2016-04-26 13:23:35 +02:00
|
|
|
allocation.update(event.number<qint64>(0));
|
|
|
|
|
m_currentSize = allocation.size;
|
|
|
|
|
|
|
|
|
|
if (m_currentSize > m_maxSize)
|
|
|
|
|
m_maxSize = m_currentSize;
|
|
|
|
|
if (m_currentJSHeapIndex != -1)
|
|
|
|
|
insertEnd(m_currentJSHeapIndex,
|
|
|
|
|
event.timestamp() - startTime(m_currentJSHeapIndex) - 1);
|
2016-06-06 19:51:55 +02:00
|
|
|
m_currentJSHeapIndex = insertStart(event.timestamp(), type.detailType());
|
2016-04-26 13:23:35 +02:00
|
|
|
m_data.insert(m_currentJSHeapIndex, allocation);
|
2016-06-03 15:50:32 +02:00
|
|
|
m_continuation = m_continuation | ContinueAllocation;
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-04-26 13:23:35 +02:00
|
|
|
}
|
2014-05-27 16:30:48 +02:00
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
void MemoryUsageModel::finalize()
|
|
|
|
|
{
|
|
|
|
|
if (m_currentJSHeapIndex != -1)
|
|
|
|
|
insertEnd(m_currentJSHeapIndex, modelManager()->traceTime()->endTime() -
|
|
|
|
|
startTime(m_currentJSHeapIndex) - 1);
|
|
|
|
|
if (m_currentUsageIndex != -1)
|
|
|
|
|
insertEnd(m_currentUsageIndex, modelManager()->traceTime()->endTime() -
|
|
|
|
|
startTime(m_currentUsageIndex) - 1);
|
2014-05-27 16:30:48 +02:00
|
|
|
|
|
|
|
|
|
2014-08-26 12:57:29 +02:00
|
|
|
computeNesting();
|
2014-10-27 19:54:23 +01:00
|
|
|
setExpandedRowCount(3);
|
|
|
|
|
setCollapsedRowCount(3);
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MemoryUsageModel::clear()
|
|
|
|
|
{
|
2014-10-27 19:54:23 +01:00
|
|
|
m_data.clear();
|
|
|
|
|
m_maxSize = 1;
|
2016-04-26 13:23:35 +02:00
|
|
|
m_currentSize = 0;
|
|
|
|
|
m_currentUsage = 0;
|
|
|
|
|
m_currentUsageIndex = -1;
|
|
|
|
|
m_currentJSHeapIndex = -1;
|
2016-06-03 15:50:32 +02:00
|
|
|
m_continuation = ContinueNothing;
|
2016-04-26 13:23:35 +02:00
|
|
|
m_rangeStack.clear();
|
2014-10-29 10:31:28 +01:00
|
|
|
QmlProfilerTimelineModel::clear();
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-26 09:27:59 +02:00
|
|
|
MemoryUsageModel::MemoryAllocationItem::MemoryAllocationItem(int typeId, qint64 baseAmount) :
|
|
|
|
|
size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0),
|
|
|
|
|
typeId(typeId)
|
2014-07-11 11:01:47 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
void MemoryUsageModel::MemoryAllocationItem::update(qint64 amount)
|
2014-07-11 11:01:47 +02:00
|
|
|
{
|
|
|
|
|
size += amount;
|
|
|
|
|
if (amount < 0) {
|
|
|
|
|
deallocated += amount;
|
|
|
|
|
++deallocations;
|
|
|
|
|
} else {
|
|
|
|
|
allocated += amount;
|
|
|
|
|
++allocations;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-27 16:30:48 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
2016-04-26 10:21:00 +02:00
|
|
|
} // namespace QmlProfiler
|