2014-05-27 16:30:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2013 Digia Plc
|
|
|
|
|
** All rights reserved.
|
|
|
|
|
** For any questions to Digia, please use contact form at http://qt.digia.com <http://qt.digia.com/>
|
|
|
|
|
**
|
|
|
|
|
** This file is part of the Qt Enterprise Qt Quick Profiler Add-on.
|
|
|
|
|
**
|
|
|
|
|
** Licensees holding valid Qt Enterprise licenses may use this file in
|
|
|
|
|
** accordance with the Qt Enterprise License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please use
|
|
|
|
|
** contact form at http://qt.digia.com <http://qt.digia.com/>
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "memoryusagemodel.h"
|
|
|
|
|
#include "qmldebug/qmlprofilereventtypes.h"
|
|
|
|
|
#include "qmlprofiler/qmlprofilermodelmanager.h"
|
2014-06-12 16:03:40 +02:00
|
|
|
#include "qmlprofiler/abstracttimelinemodel_p.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
|
|
|
|
|
|
|
|
namespace QmlProfilerExtension {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
using namespace QmlProfiler;
|
|
|
|
|
|
2014-08-26 12:57:29 +02:00
|
|
|
class MemoryUsageModel::MemoryUsageModelPrivate : public AbstractTimelineModelPrivate
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static QString memoryTypeName(int type);
|
|
|
|
|
|
2014-08-26 12:57:29 +02:00
|
|
|
QVector<MemoryAllocation> data;
|
2014-05-27 16:30:48 +02:00
|
|
|
qint64 maxSize;
|
|
|
|
|
private:
|
|
|
|
|
Q_DECLARE_PUBLIC(MemoryUsageModel)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MemoryUsageModel::MemoryUsageModel(QObject *parent)
|
2014-09-08 18:33:02 +02:00
|
|
|
: AbstractTimelineModel(new MemoryUsageModelPrivate(),
|
|
|
|
|
tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileMemory)),
|
2014-07-08 13:29:21 +02:00
|
|
|
QmlDebug::MemoryAllocation, QmlDebug::MaximumRangeType, parent)
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
2014-11-20 11:04:42 +01:00
|
|
|
Q_D(MemoryUsageModel);
|
|
|
|
|
d->maxSize = 1;
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-08 18:33:02 +02:00
|
|
|
quint64 MemoryUsageModel::features() const
|
|
|
|
|
{
|
|
|
|
|
// Will listen to all range events, too, to determine context.
|
|
|
|
|
return (1 << QmlDebug::ProfileMemory) | QmlDebug::Constants::QML_JS_RANGE_FEATURES;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-24 11:53:19 +02:00
|
|
|
int MemoryUsageModel::rowMaxValue(int rowNumber) const
|
|
|
|
|
{
|
|
|
|
|
Q_D(const MemoryUsageModel);
|
|
|
|
|
Q_UNUSED(rowNumber);
|
|
|
|
|
return d->maxSize;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-08 14:53:47 +02:00
|
|
|
int MemoryUsageModel::row(int index) const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
|
|
|
|
Q_D(const MemoryUsageModel);
|
2014-08-26 12:57:29 +02:00
|
|
|
QmlDebug::MemoryType type = d->data[index].type;
|
2014-05-27 16:30:48 +02:00
|
|
|
if (type == QmlDebug::HeapPage || type == QmlDebug::LargeItem)
|
|
|
|
|
return 1;
|
|
|
|
|
else
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-29 17:12:11 +02:00
|
|
|
int MemoryUsageModel::selectionId(int index) const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
|
|
|
|
Q_D(const MemoryUsageModel);
|
2014-08-26 12:57:29 +02:00
|
|
|
return d->data[index].type;
|
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
|
|
|
{
|
|
|
|
|
Q_D(const MemoryUsageModel);
|
2014-08-26 12:57:29 +02:00
|
|
|
return qMin(1.0f, (float)d->data[index].size / (float)d->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");
|
|
|
|
|
|
|
|
|
|
Q_D(const MemoryUsageModel);
|
|
|
|
|
QVariantMap result;
|
|
|
|
|
|
2014-08-26 12:57:29 +02:00
|
|
|
int originType = d->data[index].originTypeIndex;
|
2014-06-24 11:53:47 +02:00
|
|
|
if (originType > -1) {
|
|
|
|
|
const QmlDebug::QmlEventLocation &location =
|
|
|
|
|
d->modelManager->qmlModel()->getEventTypes().at(originType).location;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
Q_D(const MemoryUsageModel);
|
|
|
|
|
QVariantList result;
|
|
|
|
|
|
2014-09-11 11:23:07 +02:00
|
|
|
if (d->expanded && !d->hidden && !isEmpty()) {
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
|
|
|
|
QVariantMap element;
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(tr("Memory Allocation")));
|
|
|
|
|
|
|
|
|
|
element.insert(QLatin1String("id"), QVariant(QmlDebug::HeapPage));
|
|
|
|
|
result << element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
QVariantMap element;
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(tr("Memory Usage")));
|
|
|
|
|
|
|
|
|
|
element.insert(QLatin1String("id"), QVariant(QmlDebug::SmallItem));
|
|
|
|
|
result << element;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-07 14:41:44 +02:00
|
|
|
QVariantMap MemoryUsageModel::details(int index) const
|
2014-05-27 16:30:48 +02:00
|
|
|
{
|
|
|
|
|
Q_D(const MemoryUsageModel);
|
2014-07-11 10:09:08 +02:00
|
|
|
|
2014-07-07 14:41:44 +02:00
|
|
|
QVariantMap result;
|
2014-08-26 12:57:29 +02:00
|
|
|
const MemoryAllocation *ev = &d->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-07-07 14:41:44 +02:00
|
|
|
result.insert(tr("Type"), QVariant(MemoryUsageModelPrivate::memoryTypeName(ev->type)));
|
|
|
|
|
|
2014-06-24 11:53:47 +02:00
|
|
|
if (ev->originTypeIndex != -1) {
|
2014-07-07 14:41:44 +02:00
|
|
|
result.insert(tr("Location"),
|
2014-06-24 11:53:47 +02:00
|
|
|
d->modelManager->qmlModel()->getEventTypes().at(ev->originTypeIndex).displayName);
|
|
|
|
|
}
|
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()
|
|
|
|
|
{
|
|
|
|
|
Q_D(MemoryUsageModel);
|
|
|
|
|
clear();
|
|
|
|
|
QmlProfilerDataModel *simpleModel = d->modelManager->qmlModel();
|
|
|
|
|
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;
|
2014-07-11 11:01:47 +02:00
|
|
|
MemoryAllocation dummy;
|
2014-06-24 11:53:47 +02:00
|
|
|
|
2014-06-13 16:56:46 +02:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes();
|
2014-05-27 16:30:48 +02:00
|
|
|
foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) {
|
2014-06-13 16:56:46 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex];
|
2014-06-24 11:53:47 +02:00
|
|
|
while (!rangeStack.empty() && rangeStack.top().endTime < event.startTime)
|
|
|
|
|
rangeStack.pop();
|
2014-07-08 14:53:47 +02:00
|
|
|
if (!accepted(type)) {
|
2014-06-24 11:53:47 +02:00
|
|
|
if (type.rangeType != QmlDebug::MaximumRangeType) {
|
|
|
|
|
rangeStack.push(RangeStackFrame(event.typeIndex, event.startTime,
|
|
|
|
|
event.startTime + event.duration));
|
|
|
|
|
}
|
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
|
|
|
|
2014-06-13 16:56:46 +02:00
|
|
|
if (type.detailType == QmlDebug::SmallItem || type.detailType == QmlDebug::LargeItem) {
|
2014-08-26 12:57:29 +02:00
|
|
|
MemoryAllocation &last = currentUsageIndex > -1 ? d->data[currentUsageIndex] : dummy;
|
2014-07-11 11:01:47 +02:00
|
|
|
if (!rangeStack.empty() && type.detailType == last.type &&
|
|
|
|
|
last.originTypeIndex == rangeStack.top().originTypeIndex &&
|
2014-08-26 12:57:29 +02:00
|
|
|
rangeStack.top().startTime < range(currentUsageIndex).start) {
|
2014-07-11 11:01:47 +02:00
|
|
|
last.update(event.numericData1);
|
|
|
|
|
currentUsage = last.size;
|
2014-06-24 11:53:47 +02:00
|
|
|
} else {
|
2014-07-11 11:01:47 +02:00
|
|
|
MemoryAllocation allocation(QmlDebug::SmallItem, currentUsage,
|
|
|
|
|
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex);
|
|
|
|
|
allocation.update(event.numericData1);
|
|
|
|
|
currentUsage = allocation.size;
|
|
|
|
|
|
2014-06-24 11:53:47 +02:00
|
|
|
if (currentUsageIndex != -1) {
|
2014-08-26 12:57:29 +02:00
|
|
|
insertEnd(currentUsageIndex,
|
|
|
|
|
event.startTime - range(currentUsageIndex).start - 1);
|
2014-06-24 11:53:47 +02:00
|
|
|
}
|
2014-08-29 19:31:23 +02:00
|
|
|
currentUsageIndex = insertStart(event.startTime, event.typeIndex);
|
2014-08-26 12:57:29 +02:00
|
|
|
d->data.insert(currentUsageIndex, allocation);
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:56:46 +02:00
|
|
|
if (type.detailType == QmlDebug::HeapPage || type.detailType == QmlDebug::LargeItem) {
|
2014-08-26 12:57:29 +02:00
|
|
|
MemoryAllocation &last = currentJSHeapIndex > -1 ? d->data[currentJSHeapIndex] : dummy;
|
2014-07-11 11:01:47 +02:00
|
|
|
if (!rangeStack.empty() && type.detailType == last.type &&
|
|
|
|
|
last.originTypeIndex == rangeStack.top().originTypeIndex &&
|
2014-08-26 12:57:29 +02:00
|
|
|
rangeStack.top().startTime < range(currentJSHeapIndex).start) {
|
2014-07-11 11:01:47 +02:00
|
|
|
last.update(event.numericData1);
|
|
|
|
|
currentSize = last.size;
|
2014-06-24 11:53:47 +02:00
|
|
|
} else {
|
2014-07-11 11:01:47 +02:00
|
|
|
MemoryAllocation allocation((QmlDebug::MemoryType)type.detailType, currentSize,
|
|
|
|
|
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex);
|
|
|
|
|
allocation.update(event.numericData1);
|
|
|
|
|
currentSize = allocation.size;
|
2014-06-24 11:53:47 +02:00
|
|
|
|
|
|
|
|
if (currentSize > d->maxSize)
|
|
|
|
|
d->maxSize = currentSize;
|
|
|
|
|
if (currentJSHeapIndex != -1)
|
2014-08-26 12:57:29 +02:00
|
|
|
insertEnd(currentJSHeapIndex,
|
|
|
|
|
event.startTime - range(currentJSHeapIndex).start - 1);
|
2014-08-29 19:31:23 +02:00
|
|
|
currentJSHeapIndex = insertStart(event.startTime, event.typeIndex);
|
2014-08-26 12:57:29 +02:00
|
|
|
d->data.insert(currentJSHeapIndex, allocation);
|
2014-06-24 11:53:47 +02:00
|
|
|
}
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-26 12:57:29 +02:00
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, count(),
|
|
|
|
|
simpleModel->getEvents().count());
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentJSHeapIndex != -1)
|
2014-08-26 12:57:29 +02:00
|
|
|
insertEnd(currentJSHeapIndex, traceEndTime() - range(currentJSHeapIndex).start - 1);
|
2014-05-27 16:30:48 +02:00
|
|
|
if (currentUsageIndex != -1)
|
2014-08-26 12:57:29 +02:00
|
|
|
insertEnd(currentUsageIndex, traceEndTime() - range(currentUsageIndex).start - 1);
|
2014-05-27 16:30:48 +02:00
|
|
|
|
|
|
|
|
|
2014-08-26 12:57:29 +02:00
|
|
|
computeNesting();
|
2014-09-11 11:02:52 +02:00
|
|
|
d->expandedRowCount = d->collapsedRowCount = 3;
|
2014-05-27 16:30:48 +02:00
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MemoryUsageModel::clear()
|
|
|
|
|
{
|
|
|
|
|
Q_D(MemoryUsageModel);
|
2014-08-26 12:57:29 +02:00
|
|
|
d->data.clear();
|
2014-05-27 16:30:48 +02:00
|
|
|
d->maxSize = 1;
|
2014-08-26 12:57:29 +02:00
|
|
|
AbstractTimelineModel::clear();
|
2014-05-27 16:30:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MemoryUsageModel::MemoryUsageModelPrivate::memoryTypeName(int type)
|
|
|
|
|
{
|
|
|
|
|
switch (type) {
|
|
|
|
|
case QmlDebug::HeapPage: return tr("Heap Allocation");
|
|
|
|
|
case QmlDebug::LargeItem: return tr("Large Item Allocation");
|
|
|
|
|
case QmlDebug::SmallItem: return tr("Heap Usage");
|
|
|
|
|
case QmlDebug::MaximumMemoryType: return tr("Total");
|
|
|
|
|
default: return tr("Unknown");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-11 11:01:47 +02:00
|
|
|
MemoryUsageModel::MemoryAllocation::MemoryAllocation(QmlDebug::MemoryType type, qint64 baseAmount,
|
|
|
|
|
int originTypeIndex) :
|
|
|
|
|
type(type), size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0),
|
|
|
|
|
originTypeIndex(originTypeIndex)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MemoryUsageModel::MemoryAllocation::update(qint64 amount)
|
|
|
|
|
{
|
|
|
|
|
size += amount;
|
|
|
|
|
if (amount < 0) {
|
|
|
|
|
deallocated += amount;
|
|
|
|
|
++deallocations;
|
|
|
|
|
} else {
|
|
|
|
|
allocated += amount;
|
|
|
|
|
++allocations;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-27 16:30:48 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProfilerExtension
|