QmlProfiler: Load the timeline model data event by event

All the models do the same thing when loading the data: They iterate
the list of events, determine for each one if they accept it, and if
so, they load it. After the list has been fully loaded, they do some
finalization. This can be centralized, and ultimately we won't need to
expose the central QVector<QmlEvent> for that anymore.

Change-Id: Ia82facfdc3968200bbec323a02f2fcc02ac44e9e
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Ulf Hermann
2016-04-26 13:23:35 +02:00
parent 67378a7928
commit 5ba6f04d4b
16 changed files with 460 additions and 496 deletions

View File

@@ -28,11 +28,6 @@
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
bool DebugMessagesModel::accepted(const QmlEventType &event) const
{
return event.message == DebugMessage;
}
DebugMessagesModel::DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent) : DebugMessagesModel::DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent) :
QmlProfilerTimelineModel(manager, DebugMessage, MaximumRangeType, ProfileDebugMessages, parent), QmlProfilerTimelineModel(manager, DebugMessage, MaximumRangeType, ProfileDebugMessages, parent),
m_maximumMsgType(-1) m_maximumMsgType(-1)
@@ -99,24 +94,16 @@ int DebugMessagesModel::collapsedRow(int index) const
return 1; return 1;
} }
void DebugMessagesModel::loadData() void DebugMessagesModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
if (!accepted(type) || event.timestamp() < 0)
continue;
m_data.insert(insert(event.timestamp(), 0, type.detailType), m_data.insert(insert(event.timestamp(), 0, type.detailType),
MessageData(event.string(), event.typeIndex())); MessageData(event.string(), event.typeIndex()));
if (type.detailType > m_maximumMsgType) if (type.detailType > m_maximumMsgType)
m_maximumMsgType = event.typeIndex(); m_maximumMsgType = event.typeIndex();
} }
void DebugMessagesModel::finalize()
{
setCollapsedRowCount(2); setCollapsedRowCount(2);
setExpandedRowCount(m_maximumMsgType + 2); setExpandedRowCount(m_maximumMsgType + 2);
} }

View File

@@ -34,9 +34,6 @@ class DebugMessagesModel : public QmlProfilerTimelineModel
{ {
Q_OBJECT Q_OBJECT
protected:
bool accepted(const QmlEventType &event) const override;
public: public:
DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent = 0); DebugMessagesModel(QmlProfilerModelManager *manager, QObject *parent = 0);
@@ -46,7 +43,8 @@ public:
QVariantMap details(int index) const override; QVariantMap details(int index) const override;
int expandedRow(int index) const override; int expandedRow(int index) const override;
int collapsedRow(int index) const override; int collapsedRow(int index) const override;
void loadData() override; void loadEvent(const QmlEvent &event, const QmlEventType &type) override;
void finalize() override;
void clear() override; void clear() override;
QVariantMap location(int index) const override; QVariantMap location(int index) const override;

View File

@@ -140,18 +140,8 @@ int InputEventsModel::collapsedRow(int index) const
return 1; return 1;
} }
void InputEventsModel::loadData() void InputEventsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
if (!accepted(type))
continue;
m_data.insert(insert(event.timestamp(), 0, type.detailType), m_data.insert(insert(event.timestamp(), 0, type.detailType),
InputEvent(static_cast<InputEventType>(event.number<qint32>(0)), InputEvent(static_cast<InputEventType>(event.number<qint32>(0)),
event.number<qint32>(1), event.number<qint32>(2))); event.number<qint32>(1), event.number<qint32>(2)));
@@ -162,7 +152,10 @@ void InputEventsModel::loadData()
} else if (m_keyTypeId == -1) { } else if (m_keyTypeId == -1) {
m_keyTypeId = event.typeIndex(); m_keyTypeId = event.typeIndex();
} }
} }
void InputEventsModel::finalize()
{
setCollapsedRowCount(2); setCollapsedRowCount(2);
setExpandedRowCount(3); setExpandedRowCount(3);
} }

View File

@@ -36,6 +36,9 @@ class InputEventsModel : public QmlProfilerTimelineModel
protected: protected:
bool accepted(const QmlEventType &event) const; bool accepted(const QmlEventType &event) const;
void loadEvent(const QmlEvent &event, const QmlEventType &type) override;
void finalize() override;
void clear() override;
public: public:
struct InputEvent { struct InputEvent {
@@ -53,8 +56,6 @@ public:
QVariantMap details(int index) const; QVariantMap details(int index) const;
int expandedRow(int index) const; int expandedRow(int index) const;
int collapsedRow(int index) const; int collapsedRow(int index) const;
void loadData();
void clear();
private: private:
static QMetaEnum metaEnum(const char *name); static QMetaEnum metaEnum(const char *name);

View File

@@ -27,15 +27,12 @@
#include "qmlprofilermodelmanager.h" #include "qmlprofilermodelmanager.h"
#include "qmlprofilereventtypes.h" #include "qmlprofilereventtypes.h"
#include <QStack>
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
MemoryUsageModel::MemoryUsageModel(QmlProfilerModelManager *manager, QObject *parent) : MemoryUsageModel::MemoryUsageModel(QmlProfilerModelManager *manager, QObject *parent) :
QmlProfilerTimelineModel(manager, MemoryAllocation, MaximumRangeType, ProfileMemory, parent) QmlProfilerTimelineModel(manager, MemoryAllocation, MaximumRangeType, ProfileMemory, parent)
{ {
m_maxSize = 1;
announceFeatures((1ULL << mainFeature()) | Constants::QML_JS_RANGE_FEATURES); announceFeatures((1ULL << mainFeature()) | Constants::QML_JS_RANGE_FEATURES);
} }
@@ -137,94 +134,78 @@ QVariantMap MemoryUsageModel::details(int index) const
return result; return result;
} }
struct RangeStackFrame { bool MemoryUsageModel::accepted(const QmlEventType &type) const
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()
{ {
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel(); return QmlProfilerTimelineModel::accepted(type) || type.rangeType != MaximumRangeType;
if (simpleModel->isEmpty()) }
return;
qint64 currentSize = 0; void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
qint64 currentUsage = 0; {
int currentUsageIndex = -1; while (!m_rangeStack.empty() && m_rangeStack.top().endTime < event.timestamp())
int currentJSHeapIndex = -1; m_rangeStack.pop();
if (type.message != MemoryAllocation) {
QStack<RangeStackFrame> rangeStack;
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
while (!rangeStack.empty() && rangeStack.top().endTime < event.timestamp())
rangeStack.pop();
if (!accepted(type)) {
if (type.rangeType != MaximumRangeType) { if (type.rangeType != MaximumRangeType) {
rangeStack.push(RangeStackFrame(event.typeIndex(), event.timestamp(), m_rangeStack.push(RangeStackFrame(event.typeIndex(), event.timestamp(),
event.timestamp() + event.duration())); event.timestamp() + event.duration()));
} }
continue; return;
} }
if (type.detailType == SmallItem || type.detailType == LargeItem) { if (type.detailType == SmallItem || type.detailType == LargeItem) {
if (!rangeStack.empty() && currentUsageIndex > -1 && if (!m_rangeStack.empty() && m_currentUsageIndex > -1 &&
type.detailType == selectionId(currentUsageIndex) && type.detailType == selectionId(m_currentUsageIndex) &&
m_data[currentUsageIndex].originTypeIndex == rangeStack.top().originTypeIndex && m_data[m_currentUsageIndex].originTypeIndex == m_rangeStack.top().originTypeIndex &&
rangeStack.top().startTime < startTime(currentUsageIndex)) { m_rangeStack.top().startTime < startTime(m_currentUsageIndex)) {
m_data[currentUsageIndex].update(event.number<qint64>(0)); m_data[m_currentUsageIndex].update(event.number<qint64>(0));
currentUsage = m_data[currentUsageIndex].size; m_currentUsage = m_data[m_currentUsageIndex].size;
} else { } else {
MemoryAllocationItem allocation(event.typeIndex(), currentUsage, MemoryAllocationItem allocation(event.typeIndex(), m_currentUsage,
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex); m_rangeStack.empty() ? -1 : m_rangeStack.top().originTypeIndex);
allocation.update(event.number<qint64>(0)); allocation.update(event.number<qint64>(0));
currentUsage = allocation.size; m_currentUsage = allocation.size;
if (currentUsageIndex != -1) { if (m_currentUsageIndex != -1) {
insertEnd(currentUsageIndex, insertEnd(m_currentUsageIndex,
event.timestamp() - startTime(currentUsageIndex) - 1); event.timestamp() - startTime(m_currentUsageIndex) - 1);
} }
currentUsageIndex = insertStart(event.timestamp(), SmallItem); m_currentUsageIndex = insertStart(event.timestamp(), SmallItem);
m_data.insert(currentUsageIndex, allocation); m_data.insert(m_currentUsageIndex, allocation);
} }
} }
if (type.detailType == HeapPage || type.detailType == LargeItem) { if (type.detailType == HeapPage || type.detailType == LargeItem) {
if (!rangeStack.empty() && currentJSHeapIndex > -1 && if (!m_rangeStack.empty() && m_currentJSHeapIndex > -1 &&
type.detailType == selectionId(currentJSHeapIndex) && type.detailType == selectionId(m_currentJSHeapIndex) &&
m_data[currentJSHeapIndex].originTypeIndex == m_data[m_currentJSHeapIndex].originTypeIndex ==
rangeStack.top().originTypeIndex && m_rangeStack.top().originTypeIndex &&
rangeStack.top().startTime < startTime(currentJSHeapIndex)) { m_rangeStack.top().startTime < startTime(m_currentJSHeapIndex)) {
m_data[currentJSHeapIndex].update(event.number<qint64>(0)); m_data[m_currentJSHeapIndex].update(event.number<qint64>(0));
currentSize = m_data[currentJSHeapIndex].size; m_currentSize = m_data[m_currentJSHeapIndex].size;
} else { } else {
MemoryAllocationItem allocation(event.typeIndex(), currentSize, MemoryAllocationItem allocation(event.typeIndex(), m_currentSize,
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex); m_rangeStack.empty() ? -1 : m_rangeStack.top().originTypeIndex);
allocation.update(event.number<qint64>(0)); allocation.update(event.number<qint64>(0));
currentSize = allocation.size; m_currentSize = allocation.size;
if (currentSize > m_maxSize) if (m_currentSize > m_maxSize)
m_maxSize = currentSize; m_maxSize = m_currentSize;
if (currentJSHeapIndex != -1) if (m_currentJSHeapIndex != -1)
insertEnd(currentJSHeapIndex, insertEnd(m_currentJSHeapIndex,
event.timestamp() - startTime(currentJSHeapIndex) - 1); event.timestamp() - startTime(m_currentJSHeapIndex) - 1);
currentJSHeapIndex = insertStart(event.timestamp(), type.detailType); m_currentJSHeapIndex = insertStart(event.timestamp(), type.detailType);
m_data.insert(currentJSHeapIndex, allocation); m_data.insert(m_currentJSHeapIndex, allocation);
}
} }
} }
}
if (currentJSHeapIndex != -1) void MemoryUsageModel::finalize()
insertEnd(currentJSHeapIndex, modelManager()->traceTime()->endTime() - {
startTime(currentJSHeapIndex) - 1); if (m_currentJSHeapIndex != -1)
if (currentUsageIndex != -1) insertEnd(m_currentJSHeapIndex, modelManager()->traceTime()->endTime() -
insertEnd(currentUsageIndex, modelManager()->traceTime()->endTime() - startTime(m_currentJSHeapIndex) - 1);
startTime(currentUsageIndex) - 1); if (m_currentUsageIndex != -1)
insertEnd(m_currentUsageIndex, modelManager()->traceTime()->endTime() -
startTime(m_currentUsageIndex) - 1);
computeNesting(); computeNesting();
@@ -236,6 +217,11 @@ void MemoryUsageModel::clear()
{ {
m_data.clear(); m_data.clear();
m_maxSize = 1; m_maxSize = 1;
m_currentSize = 0;
m_currentUsage = 0;
m_currentUsageIndex = -1;
m_currentJSHeapIndex = -1;
m_rangeStack.clear();
QmlProfilerTimelineModel::clear(); QmlProfilerTimelineModel::clear();
} }

View File

@@ -30,6 +30,7 @@
#include <QStringList> #include <QStringList>
#include <QColor> #include <QColor>
#include <QStack>
namespace QmlProfiler { namespace QmlProfiler {
namespace Internal { namespace Internal {
@@ -68,14 +69,30 @@ public:
QVariantMap details(int index) const; QVariantMap details(int index) const;
protected: protected:
void loadData(); bool accepted(const QmlEventType &type) const override;
void clear(); void loadEvent(const QmlEvent &event, const QmlEventType &type) override;
void finalize() override;
void clear() override;
private: private:
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;
};
static QString memoryTypeName(int type); static QString memoryTypeName(int type);
QVector<MemoryAllocationItem> m_data; QVector<MemoryAllocationItem> m_data;
qint64 m_maxSize; QStack<RangeStackFrame> m_rangeStack;
qint64 m_maxSize = 1;
qint64 m_currentSize = 0;
qint64 m_currentUsage = 0;
int m_currentUsageIndex = -1;
int m_currentJSHeapIndex = -1;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -34,7 +34,6 @@ PixmapCacheModel::PixmapCacheModel(QmlProfilerModelManager *manager, QObject *pa
QmlProfilerTimelineModel(manager, PixmapCacheEvent, MaximumRangeType, ProfilePixmapCache, QmlProfilerTimelineModel(manager, PixmapCacheEvent, MaximumRangeType, ProfilePixmapCache,
parent) parent)
{ {
m_maxCacheSize = 1;
} }
int PixmapCacheModel::rowMaxValue(int rowNumber) const int PixmapCacheModel::rowMaxValue(int rowNumber) const
@@ -164,22 +163,8 @@ QVariantMap PixmapCacheModel::details(int index) const
* necessarily the order the pixmaps are really loaded but it's the best we can do with the given * necessarily the order the pixmaps are really loaded but it's the best we can do with the given
* information. If they're loaded sequentially the representation is correct. * information. If they're loaded sequentially the representation is correct.
*/ */
void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
void PixmapCacheModel::loadData()
{ {
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
int lastCacheSizeEvent = -1;
int cumulatedCount = 0;
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
if (!accepted(type))
continue;
PixmapCacheItem newEvent; PixmapCacheItem newEvent;
newEvent.pixmapEventType = static_cast<PixmapEventType>(type.detailType); newEvent.pixmapEventType = static_cast<PixmapEventType>(type.detailType);
qint64 pixmapStartTime = event.timestamp(); qint64 pixmapStartTime = event.timestamp();
@@ -224,7 +209,7 @@ void PixmapCacheModel::loadData()
PixmapState &state = pixmap.sizes[newEvent.sizeIndex]; PixmapState &state = pixmap.sizes[newEvent.sizeIndex];
if (state.cacheState == ToBeCached) { if (state.cacheState == ToBeCached) {
lastCacheSizeEvent = updateCacheCount(lastCacheSizeEvent, pixmapStartTime, m_lastCacheSizeEvent = updateCacheCount(m_lastCacheSizeEvent, pixmapStartTime,
state.size.width() * state.size.height(), newEvent, state.size.width() * state.size.height(), newEvent,
event.typeIndex()); event.typeIndex());
state.cacheState = Cached; state.cacheState = Cached;
@@ -234,8 +219,8 @@ void PixmapCacheModel::loadData()
case PixmapCacheCountChanged: {// Cache Size Changed Event case PixmapCacheCountChanged: {// Cache Size Changed Event
pixmapStartTime = event.timestamp() + 1; // delay 1 ns for proper sorting pixmapStartTime = event.timestamp() + 1; // delay 1 ns for proper sorting
bool uncache = cumulatedCount > event.number<qint32>(2); bool uncache = m_cumulatedCount > event.number<qint32>(2);
cumulatedCount = event.number<qint32>(2); m_cumulatedCount = event.number<qint32>(2);
qint64 pixSize = 0; qint64 pixSize = 0;
// First try to find a preferred pixmap, which either is Corrupt and will be uncached // First try to find a preferred pixmap, which either is Corrupt and will be uncached
@@ -285,7 +270,7 @@ void PixmapCacheModel::loadData()
pixmap.sizes << PixmapState(uncache ? Uncached : ToBeCached); pixmap.sizes << PixmapState(uncache ? Uncached : ToBeCached);
} }
lastCacheSizeEvent = updateCacheCount(lastCacheSizeEvent, pixmapStartTime, pixSize, m_lastCacheSizeEvent = updateCacheCount(m_lastCacheSizeEvent, pixmapStartTime, pixSize,
newEvent, event.typeIndex()); newEvent, event.typeIndex());
break; break;
} }
@@ -348,7 +333,7 @@ void PixmapCacheModel::loadData()
} }
PixmapState &state = pixmap.sizes[newEvent.sizeIndex]; PixmapState &state = pixmap.sizes[newEvent.sizeIndex];
// If the pixmap loading wasn't started, start it at tracetimestamp() // If the pixmap loading wasn't started, start it at traceStartTime()
if (state.loadState == Initial) { if (state.loadState == Initial) {
newEvent.pixmapEventType = PixmapLoadingStarted; newEvent.pixmapEventType = PixmapLoadingStarted;
newEvent.typeId = event.typeIndex(); newEvent.typeId = event.typeIndex();
@@ -358,8 +343,8 @@ void PixmapCacheModel::loadData()
m_data.insert(state.started, newEvent); m_data.insert(state.started, newEvent);
// All other indices are wrong now as we've prepended. Fix them ... // All other indices are wrong now as we've prepended. Fix them ...
if (lastCacheSizeEvent >= state.started) if (m_lastCacheSizeEvent >= state.started)
++lastCacheSizeEvent; ++m_lastCacheSizeEvent;
for (int pixmapIndex = 0; pixmapIndex < m_pixmaps.count(); ++pixmapIndex) { for (int pixmapIndex = 0; pixmapIndex < m_pixmaps.count(); ++pixmapIndex) {
Pixmap &brokenPixmap = m_pixmaps[pixmapIndex]; Pixmap &brokenPixmap = m_pixmaps[pixmapIndex];
@@ -397,14 +382,16 @@ void PixmapCacheModel::loadData()
default: default:
break; break;
} }
}
void PixmapCacheModel::finalize()
{
if (m_lastCacheSizeEvent != -1) {
insertEnd(m_lastCacheSizeEvent, modelManager()->traceTime()->endTime() -
startTime(m_lastCacheSizeEvent));
} }
if (lastCacheSizeEvent != -1)
insertEnd(lastCacheSizeEvent, modelManager()->traceTime()->endTime() -
startTime(lastCacheSizeEvent));
resizeUnfinishedLoads(); resizeUnfinishedLoads();
computeMaxCacheSize(); computeMaxCacheSize();
flattenLoads(); flattenLoads();
computeNesting(); computeNesting();
@@ -413,14 +400,15 @@ void PixmapCacheModel::loadData()
void PixmapCacheModel::clear() void PixmapCacheModel::clear()
{ {
m_pixmaps.clear(); m_pixmaps.clear();
m_maxCacheSize = 1;
m_data.clear(); m_data.clear();
m_maxCacheSize = 1;
m_lastCacheSizeEvent = -1;
m_cumulatedCount = 0;
QmlProfilerTimelineModel::clear(); QmlProfilerTimelineModel::clear();
} }
void PixmapCacheModel::computeMaxCacheSize() void PixmapCacheModel::computeMaxCacheSize()
{ {
m_maxCacheSize = 1;
foreach (const PixmapCacheModel::PixmapCacheItem &event, m_data) { foreach (const PixmapCacheModel::PixmapCacheItem &event, m_data) {
if (event.pixmapEventType == PixmapCacheModel::PixmapCacheCountChanged) { if (event.pixmapEventType == PixmapCacheModel::PixmapCacheCountChanged) {
if (event.cacheSize > m_maxCacheSize) if (event.cacheSize > m_maxCacheSize)

View File

@@ -106,19 +106,23 @@ public:
QVariantMap details(int index) const; QVariantMap details(int index) const;
protected: protected:
void loadData(); void loadEvent(const QmlEvent &event, const QmlEventType &type) override;
void clear(); void finalize() override;
void clear() override;
private: private:
void computeMaxCacheSize(); void computeMaxCacheSize();
void resizeUnfinishedLoads(); void resizeUnfinishedLoads();
void flattenLoads(); void flattenLoads();
int updateCacheCount(int lastCacheSizeEvent, qint64 startTime, qint64 pixSize, int updateCacheCount(int m_lastCacheSizeEvent, qint64 startTime, qint64 pixSize,
PixmapCacheItem &newEvent, int typeId); PixmapCacheItem &newEvent, int typeId);
QVector<PixmapCacheItem> m_data; QVector<PixmapCacheItem> m_data;
QVector<Pixmap> m_pixmaps; QVector<Pixmap> m_pixmaps;
qint64 m_maxCacheSize;
qint64 m_maxCacheSize = 1;
int m_lastCacheSizeEvent = -1;
int m_cumulatedCount = 0;
static const int s_pixmapCacheCountHue = 240; static const int s_pixmapCacheCountHue = 240;
}; };

View File

@@ -44,11 +44,11 @@ QmlProfilerAnimationsModel::QmlProfilerAnimationsModel(QmlProfilerModelManager *
QObject *parent) : QObject *parent) :
QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileAnimations, parent) QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileAnimations, parent)
{ {
m_maxGuiThreadAnimations = m_maxRenderThreadAnimations = 0;
} }
void QmlProfilerAnimationsModel::clear() void QmlProfilerAnimationsModel::clear()
{ {
m_minNextStartTimes[0] = m_minNextStartTimes[1] = 0;
m_maxGuiThreadAnimations = m_maxRenderThreadAnimations = 0; m_maxGuiThreadAnimations = m_maxRenderThreadAnimations = 0;
m_data.clear(); m_data.clear();
QmlProfilerTimelineModel::clear(); QmlProfilerTimelineModel::clear();
@@ -59,26 +59,10 @@ bool QmlProfilerAnimationsModel::accepted(const QmlEventType &event) const
return QmlProfilerTimelineModel::accepted(event) && event.detailType == AnimationFrame; return QmlProfilerTimelineModel::accepted(event) && event.detailType == AnimationFrame;
} }
void QmlProfilerAnimationsModel::loadData() void QmlProfilerAnimationsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel(); Q_UNUSED(type);
if (simpleModel->isEmpty()) AnimationThread lastThread = (AnimationThread)event.number<qint32>(2);
return;
// collect events
const QVector<QmlEvent> &referenceList = simpleModel->events();
const QVector<QmlEventType> &typeList = simpleModel->eventTypes();
AnimationThread lastThread;
QmlPaintEventData lastEvent;
qint64 minNextStartTimes[] = {0, 0};
foreach (const QmlEvent &event, referenceList) {
const QmlEventType &type = typeList[event.typeIndex()];
if (!accepted(type))
continue;
lastThread = (AnimationThread)event.number<qint32>(2);
// initial estimation of the event duration: 1/framerate // initial estimation of the event duration: 1/framerate
qint64 estimatedDuration = event.number<qint32>(0) > 0 ? 1e9 / event.number<qint32>(0) : 1; qint64 estimatedDuration = event.number<qint32>(0) > 0 ? 1e9 / event.number<qint32>(0) : 1;
@@ -88,7 +72,7 @@ void QmlProfilerAnimationsModel::loadData()
// ranges should not overlap. If they do, our estimate wasn't accurate enough // ranges should not overlap. If they do, our estimate wasn't accurate enough
qint64 realStartTime = qMax(event.timestamp() - estimatedDuration, qint64 realStartTime = qMax(event.timestamp() - estimatedDuration,
minNextStartTimes[lastThread]); m_minNextStartTimes[lastThread]);
// Sometimes our estimate is far off or the server has miscalculated the frame rate // Sometimes our estimate is far off or the server has miscalculated the frame rate
if (realStartTime >= realEndTime) if (realStartTime >= realEndTime)
@@ -96,10 +80,11 @@ void QmlProfilerAnimationsModel::loadData()
// Don't "fix" the framerate even if we've fixed the duration. // Don't "fix" the framerate even if we've fixed the duration.
// The server should know better after all and if it doesn't we want to see that. // The server should know better after all and if it doesn't we want to see that.
QmlPaintEventData lastEvent;
lastEvent.typeId = event.typeIndex(); lastEvent.typeId = event.typeIndex();
lastEvent.framerate = event.number<qint32>(0); lastEvent.framerate = event.number<qint32>(0);
lastEvent.animationcount = event.number<qint32>(1); lastEvent.animationcount = event.number<qint32>(1);
QTC_ASSERT(lastEvent.animationcount > 0, continue); QTC_ASSERT(lastEvent.animationcount > 0, return);
m_data.insert(insert(realStartTime, realEndTime - realStartTime, lastThread), lastEvent); m_data.insert(insert(realStartTime, realEndTime - realStartTime, lastThread), lastEvent);
@@ -109,9 +94,11 @@ void QmlProfilerAnimationsModel::loadData()
m_maxRenderThreadAnimations = qMax(lastEvent.animationcount, m_maxRenderThreadAnimations = qMax(lastEvent.animationcount,
m_maxRenderThreadAnimations); m_maxRenderThreadAnimations);
minNextStartTimes[lastThread] = event.timestamp() + 1; m_minNextStartTimes[lastThread] = event.timestamp() + 1;
} }
void QmlProfilerAnimationsModel::finalize()
{
computeNesting(); computeNesting();
setExpandedRowCount((m_maxGuiThreadAnimations == 0 || m_maxRenderThreadAnimations == 0) ? 2 : 3); setExpandedRowCount((m_maxGuiThreadAnimations == 0 || m_maxRenderThreadAnimations == 0) ? 2 : 3);
setCollapsedRowCount(expandedRowCount()); setCollapsedRowCount(expandedRowCount());

View File

@@ -64,16 +64,18 @@ public:
QVariantList labels() const; QVariantList labels() const;
QVariantMap details(int index) const; QVariantMap details(int index) const;
bool accepted(const QmlEventType &event) const;
protected: protected:
void loadData(); bool accepted(const QmlEventType &event) const override;
void clear(); void loadEvent(const QmlEvent &event, const QmlEventType &type) override;
void finalize() override;
void clear() override;
private: private:
QVector<QmlProfilerAnimationsModel::QmlPaintEventData> m_data; QVector<QmlProfilerAnimationsModel::QmlPaintEventData> m_data;
int m_maxGuiThreadAnimations; int m_maxGuiThreadAnimations = 0;
int m_maxRenderThreadAnimations; int m_maxRenderThreadAnimations = 0;
qint64 m_minNextStartTimes[2] = {0, 0};
int rowFromThreadId(int threadId) const; int rowFromThreadId(int threadId) const;
}; };

View File

@@ -62,25 +62,16 @@ bool QmlProfilerRangeModel::supportsBindingLoops() const
return rangeType() == Binding || rangeType() == HandlingSignal; return rangeType() == Binding || rangeType() == HandlingSignal;
} }
void QmlProfilerRangeModel::loadData() void QmlProfilerRangeModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel(); Q_UNUSED(type);
if (simpleModel->isEmpty())
return;
// collect events
const QVector<QmlEvent> &eventList = simpleModel->events();
const QVector<QmlEventType> &typesList = simpleModel->eventTypes();
foreach (const QmlEvent &event, eventList) {
const QmlEventType &type = typesList[event.typeIndex()];
if (!accepted(type))
continue;
// store starttime-based instance // store starttime-based instance
m_data.insert(insert(event.timestamp(), event.duration(), event.typeIndex()), m_data.insert(insert(event.timestamp(), event.duration(), event.typeIndex()),
QmlRangeEventStartInstance()); QmlRangeEventStartInstance());
} }
void QmlProfilerRangeModel::finalize()
{
// compute range nesting // compute range nesting
computeNesting(); computeNesting();

View File

@@ -73,8 +73,9 @@ public:
virtual QList<const Timeline::TimelineRenderPass *> supportedRenderPasses() const; virtual QList<const Timeline::TimelineRenderPass *> supportedRenderPasses() const;
protected: protected:
void loadData(); void loadEvent(const QmlEvent &event, const QmlEventType &type) override;
void clear(); void finalize() override;
void clear() override;
private: private:

View File

@@ -134,4 +134,21 @@ QVariantMap QmlProfilerTimelineModel::locationFromTypeId(int index) const
return result; return result;
} }
void QmlProfilerTimelineModel::loadData()
{
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
if (accepted(type)) {
loadEvent(event, type);
}
}
finalize();
} }
} // namespace QmlProfiler

View File

@@ -53,7 +53,10 @@ public:
Q_INVOKABLE virtual int bindingLoopDest(int index) const; Q_INVOKABLE virtual int bindingLoopDest(int index) const;
QVariantMap locationFromTypeId(int index) const; QVariantMap locationFromTypeId(int index) const;
virtual void loadData() = 0; void loadData();
virtual void loadEvent(const QmlEvent &event, const QmlEventType &type) = 0;
virtual void finalize() = 0;
void clear(); void clear();
private slots: private slots:
@@ -68,6 +71,8 @@ private:
const RangeType m_rangeType; const RangeType m_rangeType;
const ProfileFeature m_mainFeature; const ProfileFeature m_mainFeature;
QmlProfilerModelManager *const m_modelManager; QmlProfilerModelManager *const m_modelManager;
void updateProgress(qint64 count, qint64 max) const;
}; };
} } // namespace QmlProfiler

View File

@@ -131,38 +131,26 @@ QVariantMap SceneGraphTimelineModel::details(int index) const
return result; return result;
} }
void SceneGraphTimelineModel::loadData() void SceneGraphTimelineModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{ {
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
// combine the data of several eventtypes into two rows // combine the data of several eventtypes into two rows
const QVector<QmlEventType> &types = simpleModel->eventTypes();
foreach (const QmlEvent &event, simpleModel->events()) {
const QmlEventType &type = types[event.typeIndex()];
if (!accepted(type))
continue;
switch ((SceneGraphFrameType)type.detailType) { switch ((SceneGraphFrameType)type.detailType) {
case SceneGraphRendererFrame: { case SceneGraphRendererFrame: {
// Breakdown of render times. We repeat "render" here as "net" render time. It would // Breakdown of render times. We repeat "render" here as "net" render time. It would
// look incomplete if that was left out as the printf profiler lists it, too, and people // look incomplete if that was left out as the printf profiler lists it, too, and people
// are apparently comparing that. Unfortunately it is somewhat redundant as the other // are apparently comparing that. Unfortunately it is somewhat redundant as the other
// parts of the breakdown are usually very short. // parts of the breakdown are usually very short.
qint64 startTime = event.timestamp() - event.number<qint64>(0) - event.number<qint64>(1) qint64 startTime = event.timestamp() - event.number<qint64>(0) - event.number<qint64>(1) -
- event.number<qint64>(2) - event.number<qint64>(3); event.number<qint64>(2) - event.number<qint64>(3);
startTime += insert(startTime, event.number<qint64>(0), event.typeIndex(), startTime += insert(startTime, event.number<qint64>(0), event.typeIndex(),
RenderPreprocess); RenderPreprocess);
startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(), startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(), RenderUpdate);
RenderUpdate);
startTime += insert(startTime, event.number<qint64>(2), event.typeIndex(), RenderBind); startTime += insert(startTime, event.number<qint64>(2), event.typeIndex(), RenderBind);
insert(startTime, event.number<qint64>(3), event.typeIndex(), RenderRender); insert(startTime, event.number<qint64>(3), event.typeIndex(), RenderRender);
break; break;
} }
case SceneGraphAdaptationLayerFrame: { case SceneGraphAdaptationLayerFrame: {
qint64 startTime = event.timestamp() - event.number<qint64>(1) qint64 startTime = event.timestamp() - event.number<qint64>(1) - event.number<qint64>(2);
- event.number<qint64>(2);
startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(), GlyphRender, startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(), GlyphRender,
event.number<qint64>(0)); event.number<qint64>(0));
insert(startTime, event.number<qint64>(2), event.typeIndex(), GlyphStore, insert(startTime, event.number<qint64>(2), event.typeIndex(), GlyphStore,
@@ -175,8 +163,8 @@ void SceneGraphTimelineModel::loadData()
break; break;
} }
case SceneGraphRenderLoopFrame: { case SceneGraphRenderLoopFrame: {
qint64 startTime = event.timestamp() - event.number<qint64>(0) - event.number<qint64>(1) qint64 startTime = event.timestamp() - event.number<qint64>(0) - event.number<qint64>(1) -
- event.number<qint64>(2); event.number<qint64>(2);
startTime += insert(startTime, event.number<qint64>(0), event.typeIndex(), startTime += insert(startTime, event.number<qint64>(0), event.typeIndex(),
RenderThreadSync); RenderThreadSync);
startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(), startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(),
@@ -185,15 +173,12 @@ void SceneGraphTimelineModel::loadData()
break; break;
} }
case SceneGraphTexturePrepare: { case SceneGraphTexturePrepare: {
qint64 startTime = event.timestamp() - event.number<qint64>(0) - event.number<qint64>(1) qint64 startTime = event.timestamp() - event.number<qint64>(0) - event.number<qint64>(1) -
- event.number<qint64>(2) - event.number<qint64>(3) - event.number<qint64>(4); event.number<qint64>(2) - event.number<qint64>(3) - event.number<qint64>(4);
startTime += insert(startTime, event.number<qint64>(0), event.typeIndex(), TextureBind); startTime += insert(startTime, event.number<qint64>(0), event.typeIndex(), TextureBind);
startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(), startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(), TextureConvert);
TextureConvert); startTime += insert(startTime, event.number<qint64>(2), event.typeIndex(), TextureSwizzle);
startTime += insert(startTime, event.number<qint64>(2), event.typeIndex(), startTime += insert(startTime, event.number<qint64>(3), event.typeIndex(), TextureUpload);
TextureSwizzle);
startTime += insert(startTime, event.number<qint64>(3), event.typeIndex(),
TextureUpload);
insert(startTime, event.number<qint64>(4), event.typeIndex(), TextureMipmap); insert(startTime, event.number<qint64>(4), event.typeIndex(), TextureMipmap);
break; break;
} }
@@ -203,13 +188,12 @@ void SceneGraphTimelineModel::loadData()
break; break;
} }
case SceneGraphPolishAndSync: { case SceneGraphPolishAndSync: {
qint64 startTime = event.timestamp() - event.number<qint64>(0) - event.number<qint64>(1) qint64 startTime = event.timestamp() - event.number<qint64>(0) - event.number<qint64>(1) -
- event.number<qint64>(2) - event.number<qint64>(3); event.number<qint64>(2) - event.number<qint64>(3);
startTime += insert(startTime, event.number<qint64>(0), event.typeIndex(), Polish); startTime += insert(startTime, event.number<qint64>(0), event.typeIndex(), Polish);
startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(), Wait); startTime += insert(startTime, event.number<qint64>(1), event.typeIndex(), Wait);
startTime += insert(startTime, event.number<qint64>(2), event.typeIndex(), startTime += insert(startTime, event.number<qint64>(2), event.typeIndex(), GUIThreadSync);
GUIThreadSync);
insert(startTime, event.number<qint64>(3), event.typeIndex(), Animations); insert(startTime, event.number<qint64>(3), event.typeIndex(), Animations);
break; break;
} }
@@ -227,8 +211,10 @@ void SceneGraphTimelineModel::loadData()
} }
default: break; default: break;
} }
} }
void SceneGraphTimelineModel::finalize()
{
computeNesting(); computeNesting();
flattenLoads(); flattenLoads();
} }

View File

@@ -95,8 +95,9 @@ public:
QVariantMap details(int index) const; QVariantMap details(int index) const;
protected: protected:
void loadData(); void loadEvent(const QmlEvent &event, const QmlEventType &type) override;
void clear(); void finalize() override;
void clear() override;
private: private:
void flattenLoads(); void flattenLoads();