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
|
|
|
|
2014-06-24 11:53:47 +02:00
|
|
|
#include <QStack>
|
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
|
|
|
{
|
2014-11-26 11:18:54 +01:00
|
|
|
m_maxSize = 1;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 11:53:47 +02:00
|
|
|
struct RangeStackFrame {
|
|
|
|
|
RangeStackFrame() : originTypeIndex(-1), startTime(-1), endTime(-1) {}
|
|
|
|
|
RangeStackFrame(int originTypeIndex, qint64 startTime, qint64 endTime) :
|
|
|
|
|
originTypeIndex(originTypeIndex), startTime(startTime), endTime(endTime) {}
|
|
|
|
|
int originTypeIndex;
|
|
|
|
|
qint64 startTime;
|
|
|
|
|
qint64 endTime;
|
|
|
|
|
};
|
|
|
|
|
|
2014-05-27 16:30:48 +02:00
|
|
|
void MemoryUsageModel::loadData()
|
|
|
|
|
{
|
2014-10-27 19:54:23 +01:00
|
|
|
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
|
2014-05-27 16:30:48 +02:00
|
|
|
if (simpleModel->isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
qint64 currentSize = 0;
|
|
|
|
|
qint64 currentUsage = 0;
|
|
|
|
|
int currentUsageIndex = -1;
|
|
|
|
|
int currentJSHeapIndex = -1;
|
2014-06-24 11:53:47 +02:00
|
|
|
|
|
|
|
|
QStack<RangeStackFrame> rangeStack;
|
|
|
|
|
|
2016-04-26 11:50:59 +02:00
|
|
|
const QVector<QmlEventType> &types = simpleModel->eventTypes();
|
|
|
|
|
foreach (const QmlEvent &event, simpleModel->events()) {
|
|
|
|
|
const QmlEventType &type = types[event.typeIndex()];
|
2016-04-28 15:40:02 +02:00
|
|
|
while (!rangeStack.empty() && rangeStack.top().endTime < event.timestamp())
|
2014-06-24 11:53:47 +02:00
|
|
|
rangeStack.pop();
|
2014-07-08 14:53:47 +02:00
|
|
|
if (!accepted(type)) {
|
2016-05-02 12:18:57 +02:00
|
|
|
if (type.rangeType != MaximumRangeType) {
|
2016-04-28 15:40:02 +02:00
|
|
|
rangeStack.push(RangeStackFrame(event.typeIndex(), event.timestamp(),
|
|
|
|
|
event.timestamp() + event.duration()));
|
2014-06-24 11:53:47 +02:00
|
|
|
}
|
2014-05-27 16:30:48 +02:00
|
|
|
continue;
|
2014-06-24 11:53:47 +02:00
|
|
|
}
|
2014-05-27 16:30:48 +02:00
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
if (type.detailType == SmallItem || type.detailType == LargeItem) {
|
2014-10-28 14:30:04 +01:00
|
|
|
if (!rangeStack.empty() && currentUsageIndex > -1 &&
|
|
|
|
|
type.detailType == selectionId(currentUsageIndex) &&
|
|
|
|
|
m_data[currentUsageIndex].originTypeIndex == rangeStack.top().originTypeIndex &&
|
2014-10-27 18:45:14 +01:00
|
|
|
rangeStack.top().startTime < startTime(currentUsageIndex)) {
|
2016-04-28 15:57:12 +02:00
|
|
|
m_data[currentUsageIndex].update(event.number<qint64>(0));
|
2014-10-28 14:30:04 +01:00
|
|
|
currentUsage = m_data[currentUsageIndex].size;
|
2014-06-24 11:53:47 +02:00
|
|
|
} else {
|
2016-05-02 12:18:57 +02:00
|
|
|
MemoryAllocationItem allocation(event.typeIndex(), currentUsage,
|
2014-07-11 11:01:47 +02:00
|
|
|
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex);
|
2016-04-28 15:57:12 +02:00
|
|
|
allocation.update(event.number<qint64>(0));
|
2014-07-11 11:01:47 +02:00
|
|
|
currentUsage = allocation.size;
|
|
|
|
|
|
2014-06-24 11:53:47 +02:00
|
|
|
if (currentUsageIndex != -1) {
|
2014-08-26 12:57:29 +02:00
|
|
|
insertEnd(currentUsageIndex,
|
2016-04-28 15:40:02 +02:00
|
|
|
event.timestamp() - startTime(currentUsageIndex) - 1);
|
2014-06-24 11:53:47 +02:00
|
|
|
}
|
2016-04-28 15:40:02 +02:00
|
|
|
currentUsageIndex = insertStart(event.timestamp(), SmallItem);
|
2014-10-27 19:54:23 +01:00
|
|
|
m_data.insert(currentUsageIndex, allocation);
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
if (type.detailType == HeapPage || type.detailType == LargeItem) {
|
2014-10-28 14:30:04 +01:00
|
|
|
if (!rangeStack.empty() && currentJSHeapIndex > -1 &&
|
|
|
|
|
type.detailType == selectionId(currentJSHeapIndex) &&
|
|
|
|
|
m_data[currentJSHeapIndex].originTypeIndex ==
|
|
|
|
|
rangeStack.top().originTypeIndex &&
|
2014-10-27 18:45:14 +01:00
|
|
|
rangeStack.top().startTime < startTime(currentJSHeapIndex)) {
|
2016-04-28 15:57:12 +02:00
|
|
|
m_data[currentJSHeapIndex].update(event.number<qint64>(0));
|
2014-10-28 14:30:04 +01:00
|
|
|
currentSize = m_data[currentJSHeapIndex].size;
|
2014-06-24 11:53:47 +02:00
|
|
|
} else {
|
2016-05-02 12:18:57 +02:00
|
|
|
MemoryAllocationItem allocation(event.typeIndex(), currentSize,
|
2014-07-11 11:01:47 +02:00
|
|
|
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex);
|
2016-04-28 15:57:12 +02:00
|
|
|
allocation.update(event.number<qint64>(0));
|
2014-07-11 11:01:47 +02:00
|
|
|
currentSize = allocation.size;
|
2014-06-24 11:53:47 +02:00
|
|
|
|
2014-10-27 19:54:23 +01:00
|
|
|
if (currentSize > m_maxSize)
|
|
|
|
|
m_maxSize = currentSize;
|
2014-06-24 11:53:47 +02:00
|
|
|
if (currentJSHeapIndex != -1)
|
2014-08-26 12:57:29 +02:00
|
|
|
insertEnd(currentJSHeapIndex,
|
2016-04-28 15:40:02 +02:00
|
|
|
event.timestamp() - startTime(currentJSHeapIndex) - 1);
|
|
|
|
|
currentJSHeapIndex = insertStart(event.timestamp(), type.detailType);
|
2014-10-27 19:54:23 +01:00
|
|
|
m_data.insert(currentJSHeapIndex, allocation);
|
2014-06-24 11:53:47 +02:00
|
|
|
}
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentJSHeapIndex != -1)
|
2014-10-27 19:54:23 +01:00
|
|
|
insertEnd(currentJSHeapIndex, modelManager()->traceTime()->endTime() -
|
2014-10-27 18:45:14 +01:00
|
|
|
startTime(currentJSHeapIndex) - 1);
|
2014-05-27 16:30:48 +02:00
|
|
|
if (currentUsageIndex != -1)
|
2014-10-27 19:54:23 +01:00
|
|
|
insertEnd(currentUsageIndex, modelManager()->traceTime()->endTime() -
|
2014-10-27 18:45:14 +01:00
|
|
|
startTime(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;
|
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
|