forked from qt-creator/qt-creator
Group memory usage events by their cause and add location information
Change-Id: Id33fa51daffe97e9e60467942b92f0598a17c27d Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
#include "qmlprofiler/sortedtimelinemodel.h"
|
#include "qmlprofiler/sortedtimelinemodel.h"
|
||||||
#include "qmlprofiler/abstracttimelinemodel_p.h"
|
#include "qmlprofiler/abstracttimelinemodel_p.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QStack>
|
||||||
|
|
||||||
namespace QmlProfilerExtension {
|
namespace QmlProfilerExtension {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -88,6 +88,28 @@ float MemoryUsageModel::getHeight(int index) const
|
|||||||
return qMin(1.0f, (float)d->range(index).size / (float)d->maxSize);
|
return qMin(1.0f, (float)d->range(index).size / (float)d->maxSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QVariantMap MemoryUsageModel::getEventLocation(int index) const
|
||||||
|
{
|
||||||
|
static const QLatin1String file("file");
|
||||||
|
static const QLatin1String line("line");
|
||||||
|
static const QLatin1String column("column");
|
||||||
|
|
||||||
|
Q_D(const MemoryUsageModel);
|
||||||
|
QVariantMap result;
|
||||||
|
|
||||||
|
int originType = d->range(index).originTypeIndex;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
const QVariantList MemoryUsageModel::getLabels() const
|
const QVariantList MemoryUsageModel::getLabels() const
|
||||||
{
|
{
|
||||||
Q_D(const MemoryUsageModel);
|
Q_D(const MemoryUsageModel);
|
||||||
@@ -149,9 +171,25 @@ const QVariantList MemoryUsageModel::getEventDetails(int index) const
|
|||||||
result << res;
|
result << res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ev->originTypeIndex != -1) {
|
||||||
|
QVariantMap valuePair;
|
||||||
|
valuePair.insert(tr("Location"),
|
||||||
|
d->modelManager->qmlModel()->getEventTypes().at(ev->originTypeIndex).displayName);
|
||||||
|
result << valuePair;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
void MemoryUsageModel::loadData()
|
void MemoryUsageModel::loadData()
|
||||||
{
|
{
|
||||||
Q_D(MemoryUsageModel);
|
Q_D(MemoryUsageModel);
|
||||||
@@ -164,40 +202,67 @@ void MemoryUsageModel::loadData()
|
|||||||
qint64 currentUsage = 0;
|
qint64 currentUsage = 0;
|
||||||
int currentUsageIndex = -1;
|
int currentUsageIndex = -1;
|
||||||
int currentJSHeapIndex = -1;
|
int currentJSHeapIndex = -1;
|
||||||
|
|
||||||
|
QStack<RangeStackFrame> rangeStack;
|
||||||
|
MemoryAllocation dummy = {
|
||||||
|
QmlDebug::MaximumMemoryType, -1, -1 , -1
|
||||||
|
};
|
||||||
|
|
||||||
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes();
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types = simpleModel->getEventTypes();
|
||||||
foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) {
|
foreach (const QmlProfilerDataModel::QmlEventData &event, simpleModel->getEvents()) {
|
||||||
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex];
|
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex];
|
||||||
if (!eventAccepted(type))
|
while (!rangeStack.empty() && rangeStack.top().endTime < event.startTime)
|
||||||
|
rangeStack.pop();
|
||||||
|
if (!eventAccepted(type)) {
|
||||||
|
if (type.rangeType != QmlDebug::MaximumRangeType) {
|
||||||
|
rangeStack.push(RangeStackFrame(event.typeIndex, event.startTime,
|
||||||
|
event.startTime + event.duration));
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (type.detailType == QmlDebug::SmallItem || type.detailType == QmlDebug::LargeItem) {
|
if (type.detailType == QmlDebug::SmallItem || type.detailType == QmlDebug::LargeItem) {
|
||||||
currentUsage += event.numericData1;
|
currentUsage += event.numericData1;
|
||||||
MemoryAllocation allocation = {
|
MemoryAllocation &last = currentUsageIndex > -1 ? d->data(currentUsageIndex) : dummy;
|
||||||
QmlDebug::SmallItem,
|
if (!rangeStack.empty() && last.originTypeIndex == rangeStack.top().originTypeIndex) {
|
||||||
currentUsage,
|
last.size = currentUsage;
|
||||||
event.numericData1
|
last.delta += event.numericData1;
|
||||||
};
|
} else {
|
||||||
if (currentUsageIndex != -1) {
|
MemoryAllocation allocation = {
|
||||||
d->insertEnd(currentUsageIndex,
|
QmlDebug::SmallItem,
|
||||||
event.startTime - d->range(currentUsageIndex).start - 1);
|
currentUsage,
|
||||||
|
event.numericData1,
|
||||||
|
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex
|
||||||
|
};
|
||||||
|
if (currentUsageIndex != -1) {
|
||||||
|
d->insertEnd(currentUsageIndex,
|
||||||
|
event.startTime - d->range(currentUsageIndex).start - 1);
|
||||||
|
}
|
||||||
|
currentUsageIndex = d->insertStart(event.startTime, allocation);
|
||||||
}
|
}
|
||||||
currentUsageIndex = d->insertStart(event.startTime, allocation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.detailType == QmlDebug::HeapPage || type.detailType == QmlDebug::LargeItem) {
|
if (type.detailType == QmlDebug::HeapPage || type.detailType == QmlDebug::LargeItem) {
|
||||||
currentSize += event.numericData1;
|
currentSize += event.numericData1;
|
||||||
MemoryAllocation allocation = {
|
MemoryAllocation &last = currentJSHeapIndex > -1 ? d->data(currentJSHeapIndex) : dummy;
|
||||||
(QmlDebug::MemoryType)type.detailType,
|
if (!rangeStack.empty() && last.originTypeIndex == rangeStack.top().originTypeIndex) {
|
||||||
currentSize,
|
last.size = currentSize;
|
||||||
event.numericData1
|
last.delta += event.numericData1;
|
||||||
};
|
} else {
|
||||||
|
MemoryAllocation allocation = {
|
||||||
|
(QmlDebug::MemoryType)type.detailType,
|
||||||
|
currentSize,
|
||||||
|
event.numericData1,
|
||||||
|
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex
|
||||||
|
};
|
||||||
|
|
||||||
if (currentSize > d->maxSize)
|
if (currentSize > d->maxSize)
|
||||||
d->maxSize = currentSize;
|
d->maxSize = currentSize;
|
||||||
if (currentJSHeapIndex != -1)
|
if (currentJSHeapIndex != -1)
|
||||||
d->insertEnd(currentJSHeapIndex,
|
d->insertEnd(currentJSHeapIndex,
|
||||||
event.startTime - d->range(currentJSHeapIndex).start - 1);
|
event.startTime - d->range(currentJSHeapIndex).start - 1);
|
||||||
currentJSHeapIndex = d->insertStart(event.startTime, allocation);
|
currentJSHeapIndex = d->insertStart(event.startTime, allocation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), simpleModel->getEvents().count());
|
d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), simpleModel->getEvents().count());
|
||||||
|
@@ -38,6 +38,7 @@ public:
|
|||||||
QmlDebug::MemoryType type;
|
QmlDebug::MemoryType type;
|
||||||
qint64 size;
|
qint64 size;
|
||||||
qint64 delta;
|
qint64 delta;
|
||||||
|
int originTypeIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
MemoryUsageModel(QObject *parent = 0);
|
MemoryUsageModel(QObject *parent = 0);
|
||||||
@@ -50,6 +51,8 @@ public:
|
|||||||
QColor getColor(int index) const;
|
QColor getColor(int index) const;
|
||||||
float getHeight(int index) const;
|
float getHeight(int index) const;
|
||||||
|
|
||||||
|
const QVariantMap getEventLocation(int index) const;
|
||||||
|
|
||||||
const QVariantList getLabels() const;
|
const QVariantList getLabels() const;
|
||||||
const QVariantList getEventDetails(int index) const;
|
const QVariantList getEventDetails(int index) const;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user