QmlProfiler: Rename all the timeline model data structs to Item

This allows us to define a template for filling a
QmlProfilerTimelineModel without spelling out all the type names.

Change-Id: I97870287a795d95f58a949729afa715f145817bb
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Ulf Hermann
2018-05-09 09:27:07 +02:00
parent 9685711cb3
commit 86b368f912
14 changed files with 47 additions and 47 deletions

View File

@@ -102,7 +102,7 @@ int DebugMessagesModel::collapsedRow(int index) const
void DebugMessagesModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
m_data.insert(insert(event.timestamp(), 0, type.detailType()),
MessageData(event.string(), event.typeIndex()));
Item(event.string(), event.typeIndex()));
if (type.detailType() > m_maximumMsgType)
m_maximumMsgType = type.detailType();
}

View File

@@ -35,6 +35,13 @@ class DebugMessagesModel : public QmlProfilerTimelineModel
Q_OBJECT
public:
struct Item {
Item(const QString &text = QString(), int typeId = -1) :
text(text), typeId(typeId) {}
QString text;
int typeId;
};
DebugMessagesModel(QmlProfilerModelManager *manager, Timeline::TimelineModelAggregator *parent);
int typeId(int index) const override;
@@ -51,15 +58,8 @@ public:
private:
static QString messageType(uint i);
struct MessageData {
MessageData(const QString &text = QString(), int typeId = -1) :
text(text), typeId(typeId) {}
QString text;
int typeId;
};
int m_maximumMsgType;
QVector<MessageData> m_data;
QVector<Item> m_data;
};
} // namespace Internal

View File

@@ -81,7 +81,7 @@ QVariantMap InputEventsModel::details(int index) const
result.insert(tr("Timestamp"), Timeline::formatTime(startTime(index),
modelManager()->traceDuration()));
QString type;
const InputEvent &event = m_data[index];
const Item &event = m_data[index];
switch (event.type) {
case InputKeyPress:
type = tr("Key Press");
@@ -150,7 +150,7 @@ int InputEventsModel::collapsedRow(int index) const
void InputEventsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
m_data.insert(insert(event.timestamp(), 0, type.detailType()),
InputEvent(static_cast<InputEventType>(event.number<qint32>(0)),
Item(static_cast<InputEventType>(event.number<qint32>(0)),
event.number<qint32>(1), event.number<qint32>(2)));
if (type.detailType() == Mouse) {
@@ -175,7 +175,7 @@ void InputEventsModel::clear()
QmlProfilerTimelineModel::clear();
}
InputEventsModel::InputEvent::InputEvent(InputEventType type, int a, int b) :
InputEventsModel::Item::Item(InputEventType type, int a, int b) :
type(type), a(a), b(b)
{
}

View File

@@ -35,8 +35,8 @@ class InputEventsModel : public QmlProfilerTimelineModel
Q_OBJECT
public:
struct InputEvent {
InputEvent(InputEventType type = MaximumInputEventType, int a = 0, int b = 0);
struct Item {
Item(InputEventType type = MaximumInputEventType, int a = 0, int b = 0);
InputEventType type;
int a;
int b;
@@ -60,7 +60,7 @@ private:
int m_keyTypeId;
int m_mouseTypeId;
QVector<InputEvent> m_data;
QVector<Item> m_data;
};
} // namespace Internal

View File

@@ -109,7 +109,7 @@ static int toSameSignedInt(qint64 number)
QVariantMap MemoryUsageModel::details(int index) const
{
QVariantMap result;
const MemoryAllocationItem *ev = &m_data[index];
const Item *ev = &m_data[index];
if (ev->allocated >= -ev->deallocated)
result.insert(QLatin1String("displayName"), tr("Memory Allocated"));
@@ -181,7 +181,7 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type
m_data[m_currentUsageIndex].update(event.number<qint64>(0));
m_currentUsage = m_data[m_currentUsageIndex].size;
} else {
MemoryAllocationItem allocation(
Item allocation(
m_rangeStack.empty() ? event.typeIndex() :
m_rangeStack.top().originTypeIndex,
m_currentUsage);
@@ -212,7 +212,7 @@ void MemoryUsageModel::loadEvent(const QmlEvent &event, const QmlEventType &type
m_data[m_currentJSHeapIndex].update(event.number<qint64>(0));
m_currentSize = m_data[m_currentJSHeapIndex].size;
} else {
MemoryAllocationItem allocation(
Item allocation(
m_rangeStack.empty() ? event.typeIndex() :
m_rangeStack.top().originTypeIndex,
m_currentSize);
@@ -279,13 +279,13 @@ bool MemoryUsageModel::handlesTypeId(int typeId) const
return false;
}
MemoryUsageModel::MemoryAllocationItem::MemoryAllocationItem(int typeId, qint64 baseAmount) :
MemoryUsageModel::Item::Item(int typeId, qint64 baseAmount) :
size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0),
typeId(typeId)
{
}
void MemoryUsageModel::MemoryAllocationItem::update(qint64 amount)
void MemoryUsageModel::Item::update(qint64 amount)
{
size += amount;
if (amount < 0) {

View File

@@ -39,7 +39,7 @@ class MemoryUsageModel : public QmlProfilerTimelineModel
Q_OBJECT
public:
struct MemoryAllocationItem {
struct Item {
qint64 size;
qint64 allocated;
qint64 deallocated;
@@ -47,7 +47,7 @@ public:
int deallocations;
int typeId;
MemoryAllocationItem(int typeId = -1, qint64 baseAmount = 0);
Item(int typeId = -1, qint64 baseAmount = 0);
void update(qint64 amount);
};
@@ -86,7 +86,7 @@ private:
ContinueUsage = 0x2
};
QVector<MemoryAllocationItem> m_data;
QVector<Item> m_data;
QStack<RangeStackFrame> m_rangeStack;
qint64 m_maxSize = 1;
qint64 m_currentSize = 0;

View File

@@ -114,7 +114,7 @@ QVariantList PixmapCacheModel::labels() const
QVariantMap PixmapCacheModel::details(int index) const
{
QVariantMap result;
const PixmapCacheItem *ev = &m_data[index];
const Item *ev = &m_data[index];
if (ev->pixmapEventType == PixmapCacheCountChanged) {
result.insert(QLatin1String("displayName"), tr("Image Cached"));
@@ -165,7 +165,7 @@ QVariantMap PixmapCacheModel::details(int index) const
*/
void PixmapCacheModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
PixmapCacheItem newEvent;
Item newEvent;
const PixmapEventType pixmapType = static_cast<PixmapEventType>(type.detailType());
newEvent.pixmapEventType = pixmapType;
qint64 pixmapStartTime = event.timestamp();
@@ -407,7 +407,7 @@ void PixmapCacheModel::clear()
#ifdef WITH_TESTS
PixmapCacheModel::LoadState PixmapCacheModel::loadState(int index) const
{
const PixmapCacheItem &item = m_data[index];
const Item &item = m_data[index];
if (item.urlIndex == -1 || item.sizeIndex == -1)
return MaximumLoadState;
@@ -416,7 +416,7 @@ PixmapCacheModel::LoadState PixmapCacheModel::loadState(int index) const
PixmapCacheModel::CacheState PixmapCacheModel::cacheState(int index) const
{
const PixmapCacheItem &item = m_data[index];
const Item &item = m_data[index];
if (item.urlIndex == -1 || item.sizeIndex == -1)
return MaximumCacheState;
@@ -425,14 +425,14 @@ PixmapCacheModel::CacheState PixmapCacheModel::cacheState(int index) const
QString PixmapCacheModel::fileName(int index) const
{
const PixmapCacheItem &item = m_data[index];
const Item &item = m_data[index];
return (item.urlIndex == -1) ? QString() : m_pixmaps[item.urlIndex].url;
}
#endif // WITH_TESTS
void PixmapCacheModel::computeMaxCacheSize()
{
foreach (const PixmapCacheModel::PixmapCacheItem &event, m_data) {
foreach (const PixmapCacheModel::Item &event, m_data) {
if (event.pixmapEventType == PixmapCacheModel::PixmapCacheCountChanged) {
if (event.cacheSize > m_maxCacheSize)
m_maxCacheSize = event.cacheSize;
@@ -462,7 +462,7 @@ void PixmapCacheModel::flattenLoads()
// computes "compressed row"
QVector <qint64> eventEndTimes;
for (int i = 0; i < count(); i++) {
PixmapCacheModel::PixmapCacheItem &event = m_data[i];
PixmapCacheModel::Item &event = m_data[i];
if (event.pixmapEventType == PixmapCacheModel::PixmapLoadingStarted) {
event.rowNumberCollapsed = 0;
while (eventEndTimes.count() > event.rowNumberCollapsed &&
@@ -486,7 +486,7 @@ void PixmapCacheModel::flattenLoads()
}
int PixmapCacheModel::updateCacheCount(int lastCacheSizeEvent,
qint64 pixmapStartTime, qint64 pixSize, PixmapCacheItem &newEvent, int typeId)
qint64 pixmapStartTime, qint64 pixSize, Item &newEvent, int typeId)
{
newEvent.pixmapEventType = PixmapCacheCountChanged;
newEvent.rowNumberCollapsed = 1;

View File

@@ -85,7 +85,7 @@ public:
MaximumPixmapEventType
};
struct PixmapCacheItem {
struct Item {
int typeId = -1;
PixmapEventType pixmapEventType = MaximumPixmapEventType;
int urlIndex = -1;
@@ -123,9 +123,9 @@ private:
void resizeUnfinishedLoads();
void flattenLoads();
int updateCacheCount(int m_lastCacheSizeEvent, qint64 startTime, qint64 pixSize,
PixmapCacheItem &newEvent, int typeId);
Item &newEvent, int typeId);
QVector<PixmapCacheItem> m_data;
QVector<Item> m_data;
QVector<Pixmap> m_pixmaps;
qint64 m_maxCacheSize = 1;

View File

@@ -76,7 +76,7 @@ void QmlProfilerAnimationsModel::loadEvent(const QmlEvent &event, const QmlEvent
// 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.
QmlPaintEventData lastEvent;
Item lastEvent;
lastEvent.typeId = event.typeIndex();
lastEvent.framerate = event.number<qint32>(0);
lastEvent.animationcount = event.number<qint32>(1);

View File

@@ -43,7 +43,7 @@ class QmlProfilerAnimationsModel : public QmlProfilerTimelineModel
Q_OBJECT
public:
struct QmlPaintEventData {
struct Item {
int framerate;
int animationcount;
int typeId;
@@ -69,7 +69,7 @@ public:
void clear() override;
private:
QVector<QmlProfilerAnimationsModel::QmlPaintEventData> m_data;
QVector<Item> m_data;
int m_maxGuiThreadAnimations = 0;
int m_maxRenderThreadAnimations = 0;
qint64 m_minNextStartTimes[2];

View File

@@ -70,7 +70,7 @@ void QmlProfilerRangeModel::loadEvent(const QmlEvent &event, const QmlEventType
if (event.rangeStage() == RangeStart) {
int index = insertStart(event.timestamp(), event.typeIndex());
m_stack.append(index);
m_data.insert(index, QmlRangeEventStartInstance());
m_data.insert(index, Item());
} else if (event.rangeStage() == RangeEnd) {
if (!m_stack.isEmpty()) {
int index = m_stack.pop();

View File

@@ -44,8 +44,8 @@ class QmlProfilerRangeModel : public QmlProfilerTimelineModel
Q_OBJECT
public:
struct QmlRangeEventStartInstance {
QmlRangeEventStartInstance() :
struct Item {
Item() :
displayRowExpanded(1),
displayRowCollapsed(Constants::QML_MIN_LEVEL),
bindingLoopHead(-1) {}
@@ -84,7 +84,7 @@ private:
void computeExpandedLevels();
void findBindingLoops();
QVector<QmlRangeEventStartInstance> m_data;
QVector<Item> m_data;
QStack<int> m_stack;
QVector<int> m_expandedRowTypes;
};

View File

@@ -230,7 +230,7 @@ void SceneGraphTimelineModel::flattenLoads()
QVector <qint64> eventEndTimes;
for (int i = 0; i < count(); i++) {
SceneGraphEvent &event = m_data[i];
Item &event = m_data[i];
int stage = selectionId(i);
// Don't try to put render thread events in GUI row and vice versa.
// Rows below those are free for all.
@@ -272,7 +272,7 @@ qint64 SceneGraphTimelineModel::insert(qint64 start, qint64 duration, int typeIn
return 0;
m_data.insert(QmlProfilerTimelineModel::insert(start, duration, stage),
SceneGraphEvent(typeIndex, glyphCount));
Item(typeIndex, glyphCount));
return duration;
}
@@ -293,7 +293,7 @@ void SceneGraphTimelineModel::clear()
QmlProfilerTimelineModel::clear();
}
SceneGraphTimelineModel::SceneGraphEvent::SceneGraphEvent(int typeId, int glyphCount) :
SceneGraphTimelineModel::Item::Item(int typeId, int glyphCount) :
typeId(typeId), rowNumberCollapsed(-1), glyphCount(glyphCount)
{
}

View File

@@ -75,8 +75,8 @@ public:
MaximumSceneGraphStage = MaximumTextureStage
};
struct SceneGraphEvent {
SceneGraphEvent(int typeId = -1, int glyphCount = -1);
struct Item {
Item(int typeId = -1, int glyphCount = -1);
int typeId;
int rowNumberCollapsed;
int glyphCount; // only used for one event type
@@ -105,7 +105,7 @@ private:
int glyphCount = -1);
static const char *threadLabel(SceneGraphStage stage);
QVector<SceneGraphEvent> m_data;
QVector<Item> m_data;
};
} // namespace Internal