Use SortedTimelineModel for pixmap cache events

Change-Id: Ib84da3bd94d37a228f0a4bdd649a358ad0d3c4b4
Reviewed-by: Ulf Hermann <ulf.hermann@digia.com>
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Ulf Hermann
2013-12-04 18:53:45 +01:00
parent eb4c101f9b
commit 96e0cbacb2
2 changed files with 49 additions and 100 deletions

View File

@@ -19,6 +19,7 @@
#include "pixmapcachemodel.h" #include "pixmapcachemodel.h"
#include "qmldebug/qmlprofilereventtypes.h" #include "qmldebug/qmlprofilereventtypes.h"
#include "qmlprofiler/qmlprofilermodelmanager.h" #include "qmlprofiler/qmlprofilermodelmanager.h"
#include "qmlprofiler/sortedtimelinemodel.h"
#include <QDebug> #include <QDebug>
@@ -27,7 +28,7 @@ namespace Internal {
using namespace QmlProfiler; using namespace QmlProfiler;
class PixmapCacheModel::PixmapCacheModelPrivate { class PixmapCacheModel::PixmapCacheModelPrivate : public SortedTimelineModel<PixmapCacheEvent> {
public: public:
PixmapCacheModelPrivate(PixmapCacheModel *qq):q(qq) {} PixmapCacheModelPrivate(PixmapCacheModel *qq):q(qq) {}
@@ -40,7 +41,6 @@ public:
void flattenLoads(); void flattenLoads();
void computeRowCounts(); void computeRowCounts();
QVector < PixmapCacheModel::PixmapCacheEvent > eventList;
QVector < QString > pixmapUrls; QVector < QString > pixmapUrls;
QVector < QPair<int, int> > pixmapSizes; QVector < QPair<int, int> > pixmapSizes;
bool isExpanded; bool isExpanded;
@@ -83,12 +83,12 @@ QString PixmapCacheModel::name() const
int PixmapCacheModel::count() const int PixmapCacheModel::count() const
{ {
return d->eventList.count(); return d->count();
} }
bool PixmapCacheModel::isEmpty() const bool PixmapCacheModel::isEmpty() const
{ {
return d->eventList.isEmpty(); return d->count() == 0;
} }
bool PixmapCacheModel::eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const bool PixmapCacheModel::eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const
@@ -98,7 +98,7 @@ bool PixmapCacheModel::eventAccepted(const QmlProfilerSimpleModel::QmlEventData
qint64 PixmapCacheModel::lastTimeMark() const qint64 PixmapCacheModel::lastTimeMark() const
{ {
return d->eventList.last().startTime; return d->lastEndTime();
} }
bool PixmapCacheModel::expanded(int ) const bool PixmapCacheModel::expanded(int ) const
@@ -135,54 +135,17 @@ const QString PixmapCacheModel::categoryLabel(int categoryIndex) const
int PixmapCacheModel::findFirstIndex(qint64 startTime) const int PixmapCacheModel::findFirstIndex(qint64 startTime) const
{ {
int candidate = findFirstIndexNoParents(startTime); return d->findFirstIndex(startTime);
return candidate;
} }
int PixmapCacheModel::findFirstIndexNoParents(qint64 startTime) const int PixmapCacheModel::findFirstIndexNoParents(qint64 startTime) const
{ {
if (d->eventList.isEmpty()) return d->findFirstIndexNoParents(startTime);
return -1;
if (d->eventList.count() == 1 || d->eventList.first().startTime+d->eventList.first().duration >= startTime)
return 0;
else
if (d->eventList.last().startTime+d->eventList.last().duration <= startTime)
return -1;
int fromIndex = 0;
int toIndex = d->eventList.count()-1;
while (toIndex - fromIndex > 1) {
int midIndex = (fromIndex + toIndex)/2;
if (d->eventList[midIndex].startTime + d->eventList[midIndex].duration < startTime)
fromIndex = midIndex;
else
toIndex = midIndex;
}
return toIndex;
} }
int PixmapCacheModel::findLastIndex(qint64 endTime) const int PixmapCacheModel::findLastIndex(qint64 endTime) const
{ {
if (d->eventList.isEmpty()) return d->findLastIndex(endTime);
return -1;
if (d->eventList.first().startTime >= endTime)
return -1;
if (d->eventList.count() == 1)
return 0;
if (d->eventList.last().startTime <= endTime)
return d->eventList.count()-1;
int fromIndex = 0;
int toIndex = d->eventList.count()-1;
while (toIndex - fromIndex > 1) {
int midIndex = (fromIndex + toIndex)/2;
if (d->eventList[midIndex].startTime < endTime)
fromIndex = midIndex;
else
toIndex = midIndex;
}
return fromIndex;
} }
int PixmapCacheModel::getEventType(int index) const int PixmapCacheModel::getEventType(int index) const
@@ -200,18 +163,18 @@ int PixmapCacheModel::getEventCategory(int index) const
int PixmapCacheModel::getEventRow(int index) const int PixmapCacheModel::getEventRow(int index) const
{ {
if (d->isExpanded) if (d->isExpanded)
return d->eventList[index].rowNumberExpanded; return d->range(index).rowNumberExpanded;
return d->eventList[index].rowNumberCollapsed; return d->range(index).rowNumberCollapsed;
} }
qint64 PixmapCacheModel::getDuration(int index) const qint64 PixmapCacheModel::getDuration(int index) const
{ {
return d->eventList[index].duration; return d->range(index).duration;
} }
qint64 PixmapCacheModel::getStartTime(int index) const qint64 PixmapCacheModel::getStartTime(int index) const
{ {
return d->eventList[index].startTime; return d->range(index).start;
} }
qint64 PixmapCacheModel::getEndTime(int index) const qint64 PixmapCacheModel::getEndTime(int index) const
@@ -221,12 +184,12 @@ qint64 PixmapCacheModel::getEndTime(int index) const
int PixmapCacheModel::getEventId(int index) const int PixmapCacheModel::getEventId(int index) const
{ {
return d->eventList[index].eventId; return d->range(index).eventId;
} }
QColor PixmapCacheModel::getColor(int index) const QColor PixmapCacheModel::getColor(int index) const
{ {
if (d->eventList[index].pixmapEventType == PixmapCacheCountChanged) if (d->range(index).pixmapEventType == PixmapCacheCountChanged)
return QColor::fromHsl(240, 76, 166); return QColor::fromHsl(240, 76, 166);
int ndx = getEventId(index); int ndx = getEventId(index);
@@ -235,11 +198,11 @@ QColor PixmapCacheModel::getColor(int index) const
float PixmapCacheModel::getHeight(int index) const float PixmapCacheModel::getHeight(int index) const
{ {
if (d->eventList[index].pixmapEventType == PixmapCacheCountChanged) { if (d->range(index).pixmapEventType == PixmapCacheCountChanged) {
float scale = d->maxCacheSize - d->minCacheSize; float scale = d->maxCacheSize - d->minCacheSize;
float fraction = 1.0f; float fraction = 1.0f;
if (scale > 1) if (scale > 1)
fraction = (float)(d->eventList[index].cacheSize - fraction = (float)(d->range(index).cacheSize -
d->minCacheSize) / scale; d->minCacheSize) / scale;
return fraction * 0.85f + 0.15f; return fraction * 0.85f + 0.15f;
@@ -308,7 +271,7 @@ void PixmapCacheModel::PixmapCacheModelPrivate::addVP(QVariantList &l, QString l
const QVariantList PixmapCacheModel::getEventDetails(int index) const const QVariantList PixmapCacheModel::getEventDetails(int index) const
{ {
QVariantList result; QVariantList result;
PixmapCacheEvent *ev = &d->eventList[index]; const PixmapCacheModelPrivate::Range *ev = &d->range(index);
{ {
QVariantMap res; QVariantMap res;
@@ -363,11 +326,6 @@ int PixmapCacheModel::getEventIdForLocation(const QString &/*filename*/, int /*l
return -1; return -1;
} }
bool compareStartTimes(const PixmapCacheModel::PixmapCacheEvent&t1, const PixmapCacheModel::PixmapCacheEvent &t2)
{
return t1.startTime < t2.startTime;
}
void PixmapCacheModel::loadData() void PixmapCacheModel::loadData()
{ {
clear(); clear();
@@ -385,8 +343,7 @@ void PixmapCacheModel::loadData()
PixmapCacheEvent newEvent; PixmapCacheEvent newEvent;
newEvent.pixmapEventType = event.bindingType; newEvent.pixmapEventType = event.bindingType;
newEvent.startTime = event.startTime; qint64 startTime = event.startTime;
newEvent.duration = 0;
bool isNewEntry = false; bool isNewEntry = false;
newEvent.urlIndex = d->pixmapUrls.indexOf(event.location.filename); newEvent.urlIndex = d->pixmapUrls.indexOf(event.location.filename);
@@ -406,7 +363,7 @@ void PixmapCacheModel::loadData()
d->pixmapSizes[newEvent.urlIndex] = QPair<int,int>((int)event.numericData1, (int)event.numericData2); d->pixmapSizes[newEvent.urlIndex] = QPair<int,int>((int)event.numericData1, (int)event.numericData2);
break; break;
case PixmapCacheCountChanged: {// Cache Size Changed Event case PixmapCacheCountChanged: {// Cache Size Changed Event
newEvent.startTime = event.startTime + 1; // delay 1 ns for proper sorting startTime = event.startTime + 1; // delay 1 ns for proper sorting
newEvent.eventId = 0; newEvent.eventId = 0;
newEvent.rowNumberExpanded = 1; newEvent.rowNumberExpanded = 1;
newEvent.rowNumberCollapsed = 1; newEvent.rowNumberCollapsed = 1;
@@ -414,68 +371,61 @@ void PixmapCacheModel::loadData()
qint64 pixSize = d->pixmapSizes[newEvent.urlIndex].first * d->pixmapSizes[newEvent.urlIndex].second; qint64 pixSize = d->pixmapSizes[newEvent.urlIndex].first * d->pixmapSizes[newEvent.urlIndex].second;
qint64 prevSize = 0; qint64 prevSize = 0;
if (lastCacheSizeEvent != -1) { if (lastCacheSizeEvent != -1) {
prevSize = d->eventList[lastCacheSizeEvent].cacheSize; prevSize = d->range(lastCacheSizeEvent).cacheSize;
if (event.numericData3 < cumulatedCount) if (event.numericData3 < cumulatedCount)
pixSize = -pixSize; pixSize = -pixSize;
cumulatedCount = event.numericData3; cumulatedCount = event.numericData3;
d->insertEnd(lastCacheSizeEvent, startTime - d->range(lastCacheSizeEvent).start);
d->eventList[lastCacheSizeEvent].duration = newEvent.startTime - d->eventList[lastCacheSizeEvent].startTime;
} }
newEvent.cacheSize = prevSize + pixSize; newEvent.cacheSize = prevSize + pixSize;
d->eventList << newEvent; lastCacheSizeEvent = d->insertStart(startTime, newEvent);
lastCacheSizeEvent = d->eventList.count() - 1;
break; break;
} }
case PixmapLoadingStarted: // Load case PixmapLoadingStarted: // Load
pixmapStartPoints[newEvent.urlIndex] = d->eventList.count(); pixmapStartPoints[newEvent.urlIndex] = d->insertStart(startTime, newEvent);
d->eventList << newEvent;
break; break;
case PixmapLoadingFinished: case PixmapLoadingFinished:
case PixmapLoadingError: { case PixmapLoadingError: {
int loadIndex = pixmapStartPoints[newEvent.urlIndex]; int loadIndex = pixmapStartPoints[newEvent.urlIndex];
if (!isNewEntry && loadIndex != -1) { if (!isNewEntry && loadIndex != -1) {
d->eventList[loadIndex].duration = event.startTime - d->eventList[loadIndex].startTime; d->insertEnd(loadIndex, startTime - d->range(loadIndex).start);
} else { } else {
// if it's a new entry it means that we don't have a corresponding start // if it's a new entry it means that we don't have a corresponding start
newEvent.pixmapEventType = PixmapLoadingStarted; newEvent.pixmapEventType = PixmapLoadingStarted;
newEvent.rowNumberExpanded = newEvent.urlIndex + 2; newEvent.rowNumberExpanded = newEvent.urlIndex + 2;
newEvent.startTime = traceStartTime(); loadIndex = d->insert(traceStartTime(), startTime - traceStartTime(), newEvent);
newEvent.duration = event.startTime - traceStartTime();
loadIndex = d->eventList.count();
d->eventList << newEvent;
pixmapStartPoints[newEvent.urlIndex] = loadIndex; pixmapStartPoints[newEvent.urlIndex] = loadIndex;
} }
if (event.bindingType == PixmapLoadingFinished) if (event.bindingType == PixmapLoadingFinished)
d->eventList[loadIndex].cacheSize = 1; // use count to mark success d->data(loadIndex).cacheSize = 1; // use count to mark success
else else
d->eventList[loadIndex].cacheSize = -1; // ... or failure d->data(loadIndex).cacheSize = -1; // ... or failure
break; break;
} }
default: default:
break; break;
} }
m_modelManager->modelProxyCountUpdated(m_modelId, d->eventList.count(), 2*simpleModel->getEvents().count()); m_modelManager->modelProxyCountUpdated(m_modelId, d->count(), 2*simpleModel->getEvents().count());
} }
if (lastCacheSizeEvent != -1) { if (lastCacheSizeEvent != -1) {
d->eventList[lastCacheSizeEvent].duration = traceEndTime() - d->eventList[lastCacheSizeEvent].startTime; d->insertEnd(lastCacheSizeEvent, traceEndTime() - d->range(lastCacheSizeEvent).start);
} }
d->resizeUnfinishedLoads(); d->resizeUnfinishedLoads();
qSort(d->eventList.begin(), d->eventList.end(), compareStartTimes);
d->computeCacheSizes(); d->computeCacheSizes();
d->flattenLoads(); d->flattenLoads();
d->computeRowCounts(); d->computeRowCounts();
d->computeNesting();
m_modelManager->modelProxyCountUpdated(m_modelId, 1, 1); m_modelManager->modelProxyCountUpdated(m_modelId, 1, 1);
} }
void PixmapCacheModel::clear() void PixmapCacheModel::clear()
{ {
d->eventList.clear(); d->SortedTimelineModel::clear();
d->pixmapUrls.clear(); d->pixmapUrls.clear();
d->pixmapSizes.clear(); d->pixmapSizes.clear();
d->collapsedRowCount = 1; d->collapsedRowCount = 1;
@@ -489,7 +439,7 @@ void PixmapCacheModel::PixmapCacheModelPrivate::computeCacheSizes()
{ {
minCacheSize = -1; minCacheSize = -1;
maxCacheSize = -1; maxCacheSize = -1;
foreach (const PixmapCacheModel::PixmapCacheEvent &event, eventList) { foreach (const PixmapCacheModel::PixmapCacheEvent &event, ranges) {
if (event.pixmapEventType == PixmapCacheModel::PixmapCacheCountChanged) { if (event.pixmapEventType == PixmapCacheModel::PixmapCacheCountChanged) {
if (minCacheSize == -1 || event.cacheSize < minCacheSize) if (minCacheSize == -1 || event.cacheSize < minCacheSize)
minCacheSize = event.cacheSize; minCacheSize = event.cacheSize;
@@ -502,10 +452,10 @@ void PixmapCacheModel::PixmapCacheModelPrivate::computeCacheSizes()
void PixmapCacheModel::PixmapCacheModelPrivate::resizeUnfinishedLoads() void PixmapCacheModel::PixmapCacheModelPrivate::resizeUnfinishedLoads()
{ {
// all the "load start" events with duration 0 continue till the end of the trace // all the "load start" events with duration 0 continue till the end of the trace
for (int i = 0; i < eventList.count(); i++) { for (int i = 0; i < count(); i++) {
if (eventList[i].pixmapEventType == PixmapCacheModel::PixmapLoadingStarted && if (range(i).pixmapEventType == PixmapCacheModel::PixmapLoadingStarted &&
eventList[i].duration == 0) { range(i).duration == 0) {
eventList[i].duration = q->traceEndTime() - eventList[i].startTime; insertEnd(i, q->traceEndTime() - range(i).start);
} }
} }
} }
@@ -514,20 +464,21 @@ void PixmapCacheModel::PixmapCacheModelPrivate::flattenLoads()
{ {
// computes "compressed row" // computes "compressed row"
QVector <qint64> eventEndTimes; QVector <qint64> eventEndTimes;
for (int i = 0; i < eventList.count(); i++) { for (int i = 0; i < count(); i++) {
PixmapCacheModel::PixmapCacheEvent *event = &eventList[i]; PixmapCacheModel::PixmapCacheEvent &event = data(i);
if (event->pixmapEventType == PixmapCacheModel::PixmapLoadingStarted) { const Range &start = range(i);
event->rowNumberCollapsed = 0; if (event.pixmapEventType == PixmapCacheModel::PixmapLoadingStarted) {
while (eventEndTimes.count() > event->rowNumberCollapsed && event.rowNumberCollapsed = 0;
eventEndTimes[event->rowNumberCollapsed] > event->startTime) while (eventEndTimes.count() > event.rowNumberCollapsed &&
event->rowNumberCollapsed++; eventEndTimes[event.rowNumberCollapsed] > start.start)
event.rowNumberCollapsed++;
if (eventEndTimes.count() == event->rowNumberCollapsed) if (eventEndTimes.count() == event.rowNumberCollapsed)
eventEndTimes << 0; // increase stack length, proper value added below eventEndTimes << 0; // increase stack length, proper value added below
eventEndTimes[event->rowNumberCollapsed] = event->startTime + event->duration; eventEndTimes[event.rowNumberCollapsed] = start.start + start.duration;
// readjust to account for category empty row and bargraph // readjust to account for category empty row and bargraph
event->rowNumberCollapsed += 2; event.rowNumberCollapsed += 2;
} }
} }
} }
@@ -536,7 +487,7 @@ void PixmapCacheModel::PixmapCacheModelPrivate::computeRowCounts()
{ {
expandedRowCount = 0; expandedRowCount = 0;
collapsedRowCount = 0; collapsedRowCount = 0;
foreach (const PixmapCacheModel::PixmapCacheEvent &event, eventList) { foreach (const PixmapCacheModel::PixmapCacheEvent &event, ranges) {
if (event.rowNumberExpanded > expandedRowCount) if (event.rowNumberExpanded > expandedRowCount)
expandedRowCount = event.rowNumberExpanded; expandedRowCount = event.rowNumberExpanded;
if (event.rowNumberCollapsed > collapsedRowCount) if (event.rowNumberCollapsed > collapsedRowCount)

View File

@@ -19,7 +19,7 @@
#ifndef PIXMAPCACHEMODEL_H #ifndef PIXMAPCACHEMODEL_H
#define PIXMAPCACHEMODEL_H #define PIXMAPCACHEMODEL_H
#include "qmlprofiler/abstracttimelinemodel.h" #include "qmlprofiler/qmlprofilertimelinemodelproxy.h"
#include "qmlprofiler/qmlprofilermodelmanager.h" #include "qmlprofiler/qmlprofilermodelmanager.h"
#include "qmlprofiler/qmlprofilersimplemodel.h" #include "qmlprofiler/qmlprofilersimplemodel.h"
@@ -36,8 +36,6 @@ public:
struct PixmapCacheEvent { struct PixmapCacheEvent {
int eventId; int eventId;
qint64 startTime;
qint64 duration;
int pixmapEventType; int pixmapEventType;
int urlIndex; int urlIndex;
qint64 cacheSize; qint64 cacheSize;