Adapt to switching of typeId and selectionId

Change-Id: I2aa918232b688bb84690fb8ee10753aa04804d7c
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2014-10-28 14:30:04 +01:00
committed by Ulf Hermann
parent bfbad9b941
commit b398ccb738
8 changed files with 80 additions and 56 deletions

View File

@@ -27,7 +27,8 @@ using namespace QmlProfiler;
InputEventsModel::InputEventsModel(QObject *parent) InputEventsModel::InputEventsModel(QObject *parent)
: AbstractTimelineModel(tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileInputEvents)), : AbstractTimelineModel(tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileInputEvents)),
QmlDebug::Event, QmlDebug::MaximumRangeType, parent) QmlDebug::Event, QmlDebug::MaximumRangeType, parent),
m_keyTypeId(-1), m_mouseTypeId(-1)
{ {
} }
@@ -36,9 +37,9 @@ quint64 InputEventsModel::features() const
return 1 << QmlDebug::ProfileInputEvents; return 1 << QmlDebug::ProfileInputEvents;
} }
int InputEventsModel::selectionId(int index) const int InputEventsModel::typeId(int index) const
{ {
return modelManager()->qmlModel()->getEventTypes()[typeId(index)].detailType; return selectionId(index) == QmlDebug::Mouse ? m_mouseTypeId : m_keyTypeId;
} }
QColor InputEventsModel::color(int index) const QColor InputEventsModel::color(int index) const
@@ -97,7 +98,13 @@ void InputEventsModel::loadData()
const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex]; const QmlProfilerDataModel::QmlEventTypeData &type = types[event.typeIndex];
if (!accepted(type)) if (!accepted(type))
continue; continue;
insert(event.startTime, 0, event.typeIndex); insert(event.startTime, 0, type.detailType);
if (type.detailType == QmlDebug::Mouse) {
if (m_mouseTypeId == -1)
m_mouseTypeId = event.typeIndex;
} else if (m_keyTypeId == -1) {
m_keyTypeId = event.typeIndex;
}
updateProgress(count(), simpleModel->getEvents().count()); updateProgress(count(), simpleModel->getEvents().count());
} }
setCollapsedRowCount(2); setCollapsedRowCount(2);
@@ -105,6 +112,12 @@ void InputEventsModel::loadData()
updateProgress(1, 1); updateProgress(1, 1);
} }
void InputEventsModel::clear()
{
m_keyTypeId = m_mouseTypeId = -1;
AbstractTimelineModel::clear();
}
bool InputEventsModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const bool InputEventsModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
{ {
return AbstractTimelineModel::accepted(event) && return AbstractTimelineModel::accepted(event) &&

View File

@@ -35,12 +35,18 @@ public:
InputEventsModel(QObject *parent = 0); InputEventsModel(QObject *parent = 0);
quint64 features() const; quint64 features() const;
int selectionId(int index) const; int typeId(int index) const;
QColor color(int index) const; QColor color(int index) const;
QVariantList labels() const; QVariantList labels() const;
QVariantMap details(int index) const; QVariantMap details(int index) const;
int row(int index) const; int row(int index) const;
void loadData(); void loadData();
void clear();
private:
int m_keyTypeId;
int m_mouseTypeId;
}; };
} }

View File

@@ -47,16 +47,16 @@ int MemoryUsageModel::rowMaxValue(int rowNumber) const
int MemoryUsageModel::row(int index) const int MemoryUsageModel::row(int index) const
{ {
QmlDebug::MemoryType type = m_data[index].type; int type = selectionId(index);
if (type == QmlDebug::HeapPage || type == QmlDebug::LargeItem) if (type == QmlDebug::HeapPage || type == QmlDebug::LargeItem)
return 1; return 1;
else else
return 2; return 2;
} }
int MemoryUsageModel::selectionId(int index) const int MemoryUsageModel::typeId(int index) const
{ {
return m_data[index].type; return m_data[index].typeId;
} }
QColor MemoryUsageModel::color(int index) const QColor MemoryUsageModel::color(int index) const
@@ -134,7 +134,7 @@ QVariantMap MemoryUsageModel::details(int index) const
result.insert(tr("Deallocated"), QString::fromLatin1("%1 bytes").arg(-ev->deallocated)); result.insert(tr("Deallocated"), QString::fromLatin1("%1 bytes").arg(-ev->deallocated));
result.insert(tr("Deallocations"), QString::number(ev->deallocations)); result.insert(tr("Deallocations"), QString::number(ev->deallocations));
} }
result.insert(tr("Type"), QVariant(memoryTypeName(ev->type))); result.insert(tr("Type"), QVariant(memoryTypeName(selectionId(index))));
if (ev->originTypeIndex != -1) { if (ev->originTypeIndex != -1) {
result.insert(tr("Location"), result.insert(tr("Location"),
@@ -165,7 +165,6 @@ void MemoryUsageModel::loadData()
int currentJSHeapIndex = -1; int currentJSHeapIndex = -1;
QStack<RangeStackFrame> rangeStack; QStack<RangeStackFrame> rangeStack;
MemoryAllocation dummy;
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()) {
@@ -181,14 +180,14 @@ void MemoryUsageModel::loadData()
} }
if (type.detailType == QmlDebug::SmallItem || type.detailType == QmlDebug::LargeItem) { if (type.detailType == QmlDebug::SmallItem || type.detailType == QmlDebug::LargeItem) {
MemoryAllocation &last = currentUsageIndex > -1 ? m_data[currentUsageIndex] : dummy; if (!rangeStack.empty() && currentUsageIndex > -1 &&
if (!rangeStack.empty() && type.detailType == last.type && type.detailType == selectionId(currentUsageIndex) &&
last.originTypeIndex == rangeStack.top().originTypeIndex && m_data[currentUsageIndex].originTypeIndex == rangeStack.top().originTypeIndex &&
rangeStack.top().startTime < startTime(currentUsageIndex)) { rangeStack.top().startTime < startTime(currentUsageIndex)) {
last.update(event.numericData1); m_data[currentUsageIndex].update(event.numericData1);
currentUsage = last.size; currentUsage = m_data[currentUsageIndex].size;
} else { } else {
MemoryAllocation allocation(QmlDebug::SmallItem, currentUsage, MemoryAllocation allocation(event.typeIndex, currentUsage,
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex); rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex);
allocation.update(event.numericData1); allocation.update(event.numericData1);
currentUsage = allocation.size; currentUsage = allocation.size;
@@ -197,20 +196,21 @@ void MemoryUsageModel::loadData()
insertEnd(currentUsageIndex, insertEnd(currentUsageIndex,
event.startTime - startTime(currentUsageIndex) - 1); event.startTime - startTime(currentUsageIndex) - 1);
} }
currentUsageIndex = insertStart(event.startTime, event.typeIndex); currentUsageIndex = insertStart(event.startTime, QmlDebug::SmallItem);
m_data.insert(currentUsageIndex, allocation); m_data.insert(currentUsageIndex, allocation);
} }
} }
if (type.detailType == QmlDebug::HeapPage || type.detailType == QmlDebug::LargeItem) { if (type.detailType == QmlDebug::HeapPage || type.detailType == QmlDebug::LargeItem) {
MemoryAllocation &last = currentJSHeapIndex > -1 ? m_data[currentJSHeapIndex] : dummy; if (!rangeStack.empty() && currentJSHeapIndex > -1 &&
if (!rangeStack.empty() && type.detailType == last.type && type.detailType == selectionId(currentJSHeapIndex) &&
last.originTypeIndex == rangeStack.top().originTypeIndex && m_data[currentJSHeapIndex].originTypeIndex ==
rangeStack.top().originTypeIndex &&
rangeStack.top().startTime < startTime(currentJSHeapIndex)) { rangeStack.top().startTime < startTime(currentJSHeapIndex)) {
last.update(event.numericData1); m_data[currentJSHeapIndex].update(event.numericData1);
currentSize = last.size; currentSize = m_data[currentJSHeapIndex].size;
} else { } else {
MemoryAllocation allocation((QmlDebug::MemoryType)type.detailType, currentSize, MemoryAllocation allocation(event.typeIndex, currentSize,
rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex); rangeStack.empty() ? -1 : rangeStack.top().originTypeIndex);
allocation.update(event.numericData1); allocation.update(event.numericData1);
currentSize = allocation.size; currentSize = allocation.size;
@@ -220,7 +220,7 @@ void MemoryUsageModel::loadData()
if (currentJSHeapIndex != -1) if (currentJSHeapIndex != -1)
insertEnd(currentJSHeapIndex, insertEnd(currentJSHeapIndex,
event.startTime - startTime(currentJSHeapIndex) - 1); event.startTime - startTime(currentJSHeapIndex) - 1);
currentJSHeapIndex = insertStart(event.startTime, event.typeIndex); currentJSHeapIndex = insertStart(event.startTime, type.detailType);
m_data.insert(currentJSHeapIndex, allocation); m_data.insert(currentJSHeapIndex, allocation);
} }
} }
@@ -260,9 +260,9 @@ QString MemoryUsageModel::memoryTypeName(int type)
} }
} }
MemoryUsageModel::MemoryAllocation::MemoryAllocation(QmlDebug::MemoryType type, qint64 baseAmount, MemoryUsageModel::MemoryAllocation::MemoryAllocation(int type, qint64 baseAmount,
int originTypeIndex) : int originTypeIndex) :
type(type), size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0), typeId(type), size(baseAmount), allocated(0), deallocated(0), allocations(0), deallocations(0),
originTypeIndex(originTypeIndex) originTypeIndex(originTypeIndex)
{ {
} }

View File

@@ -34,7 +34,7 @@ class MemoryUsageModel : public QmlProfiler::AbstractTimelineModel
public: public:
struct MemoryAllocation { struct MemoryAllocation {
QmlDebug::MemoryType type; int typeId;
qint64 size; qint64 size;
qint64 allocated; qint64 allocated;
qint64 deallocated; qint64 deallocated;
@@ -42,8 +42,7 @@ public:
int deallocations; int deallocations;
int originTypeIndex; int originTypeIndex;
MemoryAllocation(QmlDebug::MemoryType type = QmlDebug::MaximumMemoryType, MemoryAllocation(int typeId = -1, qint64 baseAmount = 0, int originTypeIndex = -1);
qint64 baseAmount = 0, int originTypeIndex = -1);
void update(qint64 amount); void update(qint64 amount);
}; };
@@ -53,7 +52,7 @@ public:
int rowMaxValue(int rowNumber) const; int rowMaxValue(int rowNumber) const;
int row(int index) const; int row(int index) const;
int selectionId(int index) const; int typeId(int index) const;
QColor color(int index) const; QColor color(int index) const;
float relativeHeight(int index) const; float relativeHeight(int index) const;

View File

@@ -53,10 +53,9 @@ int PixmapCacheModel::row(int index) const
return m_data[index].rowNumberCollapsed; return m_data[index].rowNumberCollapsed;
} }
int PixmapCacheModel::selectionId(int index) const int PixmapCacheModel::typeId(int index) const
{ {
return m_data[index].pixmapEventType == PixmapCacheCountChanged ? return m_data[index].typeId;
0 : m_data[index].urlIndex + 1;
} }
QColor PixmapCacheModel::color(int index) const QColor PixmapCacheModel::color(int index) const
@@ -309,7 +308,8 @@ void PixmapCacheModel::loadData()
PixmapState &state = pixmap.sizes[newEvent.sizeIndex]; PixmapState &state = pixmap.sizes[newEvent.sizeIndex];
state.loadState = Loading; state.loadState = Loading;
state.started = insertStart(pixmapStartTime, event.typeIndex); newEvent.typeId = event.typeIndex;
state.started = insertStart(pixmapStartTime, newEvent.urlIndex + 1);
m_data.insert(state.started, newEvent); m_data.insert(state.started, newEvent);
break; break;
} }
@@ -353,8 +353,10 @@ void PixmapCacheModel::loadData()
// If the pixmap loading wasn't started, start it at traceStartTime() // 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;
state.started = insert(modelManager()->traceTime()->startTime(), pixmapStartTime - newEvent.typeId = event.typeIndex;
modelManager()->traceTime()->startTime(), event.typeIndex); qint64 traceStart = modelManager()->traceTime()->startTime();
state.started = insert(traceStart, pixmapStartTime - traceStart,
newEvent.urlIndex + 1);
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 ...
@@ -487,7 +489,8 @@ int PixmapCacheModel::updateCacheCount(int lastCacheSizeEvent,
} }
newEvent.cacheSize = prevSize + pixSize; newEvent.cacheSize = prevSize + pixSize;
int index = insertStart(pixmapStartTime, typeId); newEvent.typeId = typeId;
int index = insertStart(pixmapStartTime, 0);
m_data.insert(index, newEvent); m_data.insert(index, newEvent);
return index; return index;
} }

View File

@@ -77,6 +77,7 @@ public:
}; };
struct PixmapCacheEvent { struct PixmapCacheEvent {
int typeId;
PixmapEventType pixmapEventType; PixmapEventType pixmapEventType;
int urlIndex; int urlIndex;
int sizeIndex; int sizeIndex;
@@ -90,7 +91,7 @@ public:
int rowMaxValue(int rowNumber) const; int rowMaxValue(int rowNumber) const;
int row(int index) const; int row(int index) const;
int selectionId(int index) const; int typeId(int index) const;
QColor color(int index) const; QColor color(int index) const;
float relativeHeight(int index) const; float relativeHeight(int index) const;

View File

@@ -81,12 +81,12 @@ quint64 SceneGraphTimelineModel::features() const
int SceneGraphTimelineModel::row(int index) const int SceneGraphTimelineModel::row(int index) const
{ {
return expanded() ? (m_data[index].stage + 1) : m_data[index].rowNumberCollapsed; return expanded() ? (selectionId(index) + 1) : m_data[index].rowNumberCollapsed;
} }
int SceneGraphTimelineModel::selectionId(int index) const int SceneGraphTimelineModel::typeId(int index) const
{ {
return m_data[index].stage; return m_data[index].typeId;
} }
QColor SceneGraphTimelineModel::color(int index) const QColor SceneGraphTimelineModel::color(int index) const
@@ -115,14 +115,15 @@ QVariantList SceneGraphTimelineModel::labels() const
QVariantMap SceneGraphTimelineModel::details(int index) const QVariantMap SceneGraphTimelineModel::details(int index) const
{ {
QVariantMap result; QVariantMap result;
const SceneGraphEvent *ev = &m_data[index]; const SceneGraphStage stage = static_cast<SceneGraphStage>(selectionId(index));
result.insert(QLatin1String("displayName"), result.insert(QLatin1String("displayName"), tr(threadLabel(stage)));
tr(threadLabel(static_cast<SceneGraphStage>(ev->stage)))); result.insert(tr("Stage"), tr(StageLabels[stage]));
result.insert(tr("Stage"), tr(StageLabels[ev->stage]));
result.insert(tr("Duration"), QmlProfilerBaseModel::formatTime(duration(index))); result.insert(tr("Duration"), QmlProfilerBaseModel::formatTime(duration(index)));
if (ev->glyphCount >= 0)
result.insert(tr("Glyphs"), QString::number(ev->glyphCount)); const int glyphCount = m_data[index].glyphCount;
if (glyphCount >= 0)
result.insert(tr("Glyphs"), QString::number(glyphCount));
return result; return result;
} }
@@ -234,11 +235,12 @@ void SceneGraphTimelineModel::flattenLoads()
for (int i = 0; i < count(); i++) { for (int i = 0; i < count(); i++) {
SceneGraphEvent &event = m_data[i]; SceneGraphEvent &event = m_data[i];
int stage = selectionId(i);
// Don't try to put render thread events in GUI row and vice versa. // Don't try to put render thread events in GUI row and vice versa.
// Rows below those are free for all. // Rows below those are free for all.
if (event.stage < MaximumGUIThreadStage) if (stage < MaximumGUIThreadStage)
event.rowNumberCollapsed = SceneGraphGUIThread; event.rowNumberCollapsed = SceneGraphGUIThread;
else if (event.stage < MaximumRenderThreadStage) else if (stage < MaximumRenderThreadStage)
event.rowNumberCollapsed = SceneGraphRenderThread; event.rowNumberCollapsed = SceneGraphRenderThread;
else else
event.rowNumberCollapsed = SceneGraphRenderThreadDetails; event.rowNumberCollapsed = SceneGraphRenderThreadDetails;
@@ -273,8 +275,8 @@ qint64 SceneGraphTimelineModel::insert(qint64 start, qint64 duration, int typeIn
if (duration <= 0) if (duration <= 0)
return 0; return 0;
m_data.insert(AbstractTimelineModel::insert(start, duration, typeIndex), m_data.insert(AbstractTimelineModel::insert(start, duration, stage),
SceneGraphEvent(stage, glyphCount)); SceneGraphEvent(typeIndex, glyphCount));
return duration; return duration;
} }
@@ -295,8 +297,8 @@ void SceneGraphTimelineModel::clear()
AbstractTimelineModel::clear(); AbstractTimelineModel::clear();
} }
SceneGraphTimelineModel::SceneGraphEvent::SceneGraphEvent(SceneGraphStage stage, int glyphCount) : SceneGraphTimelineModel::SceneGraphEvent::SceneGraphEvent(int typeId, int glyphCount) :
stage(stage), rowNumberCollapsed(-1), glyphCount(glyphCount) typeId(typeId), rowNumberCollapsed(-1), glyphCount(glyphCount)
{ {
} }

View File

@@ -71,8 +71,8 @@ public:
}; };
struct SceneGraphEvent { struct SceneGraphEvent {
SceneGraphEvent(SceneGraphStage stage = MaximumSceneGraphStage, int glyphCount = -1); SceneGraphEvent(int typeId = -1, int glyphCount = -1);
SceneGraphStage stage; int typeId;
int rowNumberCollapsed; int rowNumberCollapsed;
int glyphCount; // only used for one event type int glyphCount; // only used for one event type
}; };
@@ -81,7 +81,7 @@ public:
quint64 features() const; quint64 features() const;
int row(int index) const; int row(int index) const;
int selectionId(int index) const; int typeId(int index) const;
QColor color(int index) const; QColor color(int index) const;
QVariantList labels() const; QVariantList labels() const;