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-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-05-02 12:18:57 +02:00
|
|
|
announceFeatures((1ULL << mainFeature()) | 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
|
|
|
{
|
|
|
|
|
static const QLatin1String file("file");
|
|
|
|
|
static const QLatin1String line("line");
|
|
|
|
|
static const QLatin1String column("column");
|
|
|
|
|
|
|
|
|
|
QVariantMap result;
|
|
|
|
|
|
2014-10-27 19:54:23 +01:00
|
|
|
int originType = m_data[index].originTypeIndex;
|
2014-06-24 11:53:47 +02:00
|
|
|
if (originType > -1) {
|
2016-05-02 12:18:57 +02:00
|
|
|
const QmlEventLocation &location =
|
2016-04-26 11:50:59 +02:00
|
|
|
modelManager()->qmlModel()->eventTypes().at(originType).location;
|
2014-06-24 11:53:47 +02:00
|
|
|
|
|
|
|
|
result.insert(file, location.filename);
|
|
|
|
|
result.insert(line, location.line);
|
|
|
|
|
result.insert(column, location.column);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(tr("Memory Allocation")));
|
2016-05-02 12:18:57 +02:00
|
|
|
element.insert(QLatin1String("id"), QVariant(HeapPage));
|
2014-10-29 10:42:22 +01:00
|
|
|
result << element;
|
|
|
|
|
|
|
|
|
|
element.clear();
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(tr("Memory Usage")));
|
2016-05-02 12:18:57 +02:00
|
|
|
element.insert(QLatin1String("id"), QVariant(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
|
|
|
|
2014-07-07 14:41:44 +02:00
|
|
|
result.insert(tr("Total"), QString::fromLatin1("%1 bytes").arg(ev->size));
|
2014-07-11 11:01:47 +02:00
|
|
|
if (ev->allocations > 0) {
|
2014-07-07 14:41:44 +02:00
|
|
|
result.insert(tr("Allocated"), QString::fromLatin1("%1 bytes").arg(ev->allocated));
|
|
|
|
|
result.insert(tr("Allocations"), QString::number(ev->allocations));
|
2014-07-11 11:01:47 +02:00
|
|
|
}
|
|
|
|
|
if (ev->deallocations > 0) {
|
2014-07-07 14:41:44 +02:00
|
|
|
result.insert(tr("Deallocated"), QString::fromLatin1("%1 bytes").arg(-ev->deallocated));
|
|
|
|
|
result.insert(tr("Deallocations"), QString::number(ev->deallocations));
|
2014-07-11 11:01:47 +02:00
|
|
|
}
|
2014-10-28 14:30:04 +01:00
|
|
|
result.insert(tr("Type"), QVariant(memoryTypeName(selectionId(index))));
|
2014-07-07 14:41:44 +02:00
|
|
|
|
2014-06-24 11:53:47 +02:00
|
|
|
if (ev->originTypeIndex != -1) {
|
2014-07-07 14:41:44 +02:00
|
|
|
result.insert(tr("Location"),
|
2016-04-26 11:50:59 +02:00
|
|
|
modelManager()->qmlModel()->eventTypes().at(ev->originTypeIndex).displayName);
|
2014-06-24 11:53:47 +02:00
|
|
|
}
|
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-04-26 13:23:35 +02:00
|
|
|
return QmlProfilerTimelineModel::accepted(type) || type.rangeType != MaximumRangeType;
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
while (!m_rangeStack.empty() && m_rangeStack.top().endTime < event.timestamp())
|
|
|
|
|
m_rangeStack.pop();
|
|
|
|
|
if (type.message != MemoryAllocation) {
|
|
|
|
|
if (type.rangeType != MaximumRangeType) {
|
|
|
|
|
m_rangeStack.push(RangeStackFrame(event.typeIndex(), event.timestamp(),
|
|
|
|
|
event.timestamp() + event.duration()));
|
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-04-26 13:23:35 +02:00
|
|
|
if (type.detailType == SmallItem || type.detailType == LargeItem) {
|
|
|
|
|
if (!m_rangeStack.empty() && m_currentUsageIndex > -1 &&
|
|
|
|
|
type.detailType == selectionId(m_currentUsageIndex) &&
|
|
|
|
|
m_data[m_currentUsageIndex].originTypeIndex == m_rangeStack.top().originTypeIndex &&
|
|
|
|
|
m_rangeStack.top().startTime < startTime(m_currentUsageIndex)) {
|
|
|
|
|
m_data[m_currentUsageIndex].update(event.number<qint64>(0));
|
|
|
|
|
m_currentUsage = m_data[m_currentUsageIndex].size;
|
|
|
|
|
} else {
|
|
|
|
|
MemoryAllocationItem allocation(event.typeIndex(), m_currentUsage,
|
|
|
|
|
m_rangeStack.empty() ? -1 : m_rangeStack.top().originTypeIndex);
|
|
|
|
|
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);
|
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
|
|
|
if (type.detailType == HeapPage || type.detailType == LargeItem) {
|
|
|
|
|
if (!m_rangeStack.empty() && m_currentJSHeapIndex > -1 &&
|
|
|
|
|
type.detailType == selectionId(m_currentJSHeapIndex) &&
|
|
|
|
|
m_data[m_currentJSHeapIndex].originTypeIndex ==
|
|
|
|
|
m_rangeStack.top().originTypeIndex &&
|
|
|
|
|
m_rangeStack.top().startTime < startTime(m_currentJSHeapIndex)) {
|
|
|
|
|
m_data[m_currentJSHeapIndex].update(event.number<qint64>(0));
|
|
|
|
|
m_currentSize = m_data[m_currentJSHeapIndex].size;
|
|
|
|
|
} else {
|
|
|
|
|
MemoryAllocationItem allocation(event.typeIndex(), m_currentSize,
|
|
|
|
|
m_rangeStack.empty() ? -1 : m_rangeStack.top().originTypeIndex);
|
|
|
|
|
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);
|
|
|
|
|
m_currentJSHeapIndex = insertStart(event.timestamp(), type.detailType);
|
|
|
|
|
m_data.insert(m_currentJSHeapIndex, allocation);
|
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;
|
|
|
|
|
m_rangeStack.clear();
|
2014-10-29 10:31:28 +01:00
|
|
|
QmlProfilerTimelineModel::clear();
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 19:54:23 +01:00
|
|
|
QString MemoryUsageModel::memoryTypeName(int type)
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
|
|
|
|
switch (type) {
|
2016-05-02 12:18:57 +02:00
|
|
|
case HeapPage: return tr("Heap Allocation");
|
|
|
|
|
case LargeItem: return tr("Large Item Allocation");
|
|
|
|
|
case SmallItem: return tr("Heap Usage");
|
|
|
|
|
case MaximumMemoryType: return tr("Total");
|
2014-05-27 16:30:48 +02:00
|
|
|
default: return tr("Unknown");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
MemoryUsageModel::MemoryAllocationItem::MemoryAllocationItem(int type, qint64 baseAmount,
|
2014-07-11 11:01:47 +02:00
|
|
|
int originTypeIndex) :
|
2014-10-28 14:30:04 +01:00
|
|
|
typeId(type), size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0),
|
2014-07-11 11:01:47 +02:00
|
|
|
originTypeIndex(originTypeIndex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
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
|