Don't use AbstractTimelineModel's private class

We can easily implement all needed functionality with only the public
interface.

Change-Id: Ibf22f2e4bc27a8b506f0164e0e1fdf529b1a9e45
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
This commit is contained in:
Ulf Hermann
2014-10-27 19:54:23 +01:00
committed by Ulf Hermann
parent 587caba5e7
commit bfbad9b941
8 changed files with 254 additions and 344 deletions

View File

@@ -19,21 +19,14 @@
#include "inputeventsmodel.h"
#include "qmldebug/qmlprofilereventtypes.h"
#include "qmlprofiler/qmlprofilermodelmanager.h"
#include "qmlprofiler/abstracttimelinemodel_p.h"
namespace QmlProfilerExtension {
namespace Internal {
using namespace QmlProfiler;
class InputEventsModel::InputEventsModelPrivate : public AbstractTimelineModelPrivate
{
Q_DECLARE_PUBLIC(InputEventsModel)
};
InputEventsModel::InputEventsModel(QObject *parent)
: AbstractTimelineModel(new InputEventsModelPrivate(),
tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileInputEvents)),
: AbstractTimelineModel(tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileInputEvents)),
QmlDebug::Event, QmlDebug::MaximumRangeType, parent)
{
}
@@ -45,8 +38,7 @@ quint64 InputEventsModel::features() const
int InputEventsModel::selectionId(int index) const
{
Q_D(const InputEventsModel);
return d->modelManager->qmlModel()->getEventTypes()[typeId(index)].detailType;
return modelManager()->qmlModel()->getEventTypes()[typeId(index)].detailType;
}
QColor InputEventsModel::color(int index) const
@@ -56,10 +48,9 @@ QColor InputEventsModel::color(int index) const
QVariantList InputEventsModel::labels() const
{
Q_D(const InputEventsModel);
QVariantList result;
if (d->expanded && !d->hidden && !isEmpty()) {
if (expanded() && !hidden() && !isEmpty()) {
{
QVariantMap element;
element.insert(QLatin1String("description"), QVariant(tr("Mouse Events")));
@@ -96,9 +87,8 @@ int InputEventsModel::row(int index) const
void InputEventsModel::loadData()
{
Q_D(InputEventsModel);
clear();
QmlProfilerDataModel *simpleModel = d->modelManager->qmlModel();
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
@@ -108,12 +98,11 @@ void InputEventsModel::loadData()
if (!accepted(type))
continue;
insert(event.startTime, 0, event.typeIndex);
d->modelManager->modelProxyCountUpdated(d->modelId, count(),
simpleModel->getEvents().count());
updateProgress(count(), simpleModel->getEvents().count());
}
d->collapsedRowCount = 2;
d->expandedRowCount = 3;
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
setCollapsedRowCount(2);
setExpandedRowCount(3);
updateProgress(1, 1);
}
bool InputEventsModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const

View File

@@ -27,8 +27,6 @@ namespace Internal {
class InputEventsModel : public QmlProfiler::AbstractTimelineModel
{
Q_OBJECT
class InputEventsModelPrivate;
Q_DECLARE_PRIVATE(InputEventsModel)
protected:
bool accepted(const QmlProfiler::QmlProfilerDataModel::QmlEventTypeData &event) const;

View File

@@ -19,7 +19,6 @@
#include "memoryusagemodel.h"
#include "qmldebug/qmlprofilereventtypes.h"
#include "qmlprofiler/qmlprofilermodelmanager.h"
#include "qmlprofiler/abstracttimelinemodel_p.h"
#include <QStack>
@@ -28,20 +27,8 @@ namespace Internal {
using namespace QmlProfiler;
class MemoryUsageModel::MemoryUsageModelPrivate : public AbstractTimelineModelPrivate
{
public:
static QString memoryTypeName(int type);
QVector<MemoryAllocation> data;
qint64 maxSize;
private:
Q_DECLARE_PUBLIC(MemoryUsageModel)
};
MemoryUsageModel::MemoryUsageModel(QObject *parent)
: AbstractTimelineModel(new MemoryUsageModelPrivate(),
tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileMemory)),
: AbstractTimelineModel(tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileMemory)),
QmlDebug::MemoryAllocation, QmlDebug::MaximumRangeType, parent)
{
}
@@ -54,15 +41,13 @@ quint64 MemoryUsageModel::features() const
int MemoryUsageModel::rowMaxValue(int rowNumber) const
{
Q_D(const MemoryUsageModel);
Q_UNUSED(rowNumber);
return d->maxSize;
return m_maxSize;
}
int MemoryUsageModel::row(int index) const
{
Q_D(const MemoryUsageModel);
QmlDebug::MemoryType type = d->data[index].type;
QmlDebug::MemoryType type = m_data[index].type;
if (type == QmlDebug::HeapPage || type == QmlDebug::LargeItem)
return 1;
else
@@ -71,8 +56,7 @@ int MemoryUsageModel::row(int index) const
int MemoryUsageModel::selectionId(int index) const
{
Q_D(const MemoryUsageModel);
return d->data[index].type;
return m_data[index].type;
}
QColor MemoryUsageModel::color(int index) const
@@ -82,8 +66,7 @@ QColor MemoryUsageModel::color(int index) const
float MemoryUsageModel::relativeHeight(int index) const
{
Q_D(const MemoryUsageModel);
return qMin(1.0f, (float)d->data[index].size / (float)d->maxSize);
return qMin(1.0f, (float)m_data[index].size / (float)m_maxSize);
}
QVariantMap MemoryUsageModel::location(int index) const
@@ -92,13 +75,12 @@ QVariantMap MemoryUsageModel::location(int index) const
static const QLatin1String line("line");
static const QLatin1String column("column");
Q_D(const MemoryUsageModel);
QVariantMap result;
int originType = d->data[index].originTypeIndex;
int originType = m_data[index].originTypeIndex;
if (originType > -1) {
const QmlDebug::QmlEventLocation &location =
d->modelManager->qmlModel()->getEventTypes().at(originType).location;
modelManager()->qmlModel()->getEventTypes().at(originType).location;
result.insert(file, location.filename);
result.insert(line, location.line);
@@ -110,10 +92,9 @@ QVariantMap MemoryUsageModel::location(int index) const
QVariantList MemoryUsageModel::labels() const
{
Q_D(const MemoryUsageModel);
QVariantList result;
if (d->expanded && !d->hidden && !isEmpty()) {
if (expanded() && !hidden() && !isEmpty()) {
{
QVariantMap element;
element.insert(QLatin1String("description"), QVariant(tr("Memory Allocation")));
@@ -136,10 +117,8 @@ QVariantList MemoryUsageModel::labels() const
QVariantMap MemoryUsageModel::details(int index) const
{
Q_D(const MemoryUsageModel);
QVariantMap result;
const MemoryAllocation *ev = &d->data[index];
const MemoryAllocation *ev = &m_data[index];
if (ev->allocated >= -ev->deallocated)
result.insert(QLatin1String("displayName"), tr("Memory Allocated"));
@@ -155,11 +134,11 @@ QVariantMap MemoryUsageModel::details(int index) const
result.insert(tr("Deallocated"), QString::fromLatin1("%1 bytes").arg(-ev->deallocated));
result.insert(tr("Deallocations"), QString::number(ev->deallocations));
}
result.insert(tr("Type"), QVariant(MemoryUsageModelPrivate::memoryTypeName(ev->type)));
result.insert(tr("Type"), QVariant(memoryTypeName(ev->type)));
if (ev->originTypeIndex != -1) {
result.insert(tr("Location"),
d->modelManager->qmlModel()->getEventTypes().at(ev->originTypeIndex).displayName);
modelManager()->qmlModel()->getEventTypes().at(ev->originTypeIndex).displayName);
}
return result;
}
@@ -175,9 +154,8 @@ struct RangeStackFrame {
void MemoryUsageModel::loadData()
{
Q_D(MemoryUsageModel);
clear();
QmlProfilerDataModel *simpleModel = d->modelManager->qmlModel();
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
@@ -203,7 +181,7 @@ void MemoryUsageModel::loadData()
}
if (type.detailType == QmlDebug::SmallItem || type.detailType == QmlDebug::LargeItem) {
MemoryAllocation &last = currentUsageIndex > -1 ? d->data[currentUsageIndex] : dummy;
MemoryAllocation &last = currentUsageIndex > -1 ? m_data[currentUsageIndex] : dummy;
if (!rangeStack.empty() && type.detailType == last.type &&
last.originTypeIndex == rangeStack.top().originTypeIndex &&
rangeStack.top().startTime < startTime(currentUsageIndex)) {
@@ -220,12 +198,12 @@ void MemoryUsageModel::loadData()
event.startTime - startTime(currentUsageIndex) - 1);
}
currentUsageIndex = insertStart(event.startTime, event.typeIndex);
d->data.insert(currentUsageIndex, allocation);
m_data.insert(currentUsageIndex, allocation);
}
}
if (type.detailType == QmlDebug::HeapPage || type.detailType == QmlDebug::LargeItem) {
MemoryAllocation &last = currentJSHeapIndex > -1 ? d->data[currentJSHeapIndex] : dummy;
MemoryAllocation &last = currentJSHeapIndex > -1 ? m_data[currentJSHeapIndex] : dummy;
if (!rangeStack.empty() && type.detailType == last.type &&
last.originTypeIndex == rangeStack.top().originTypeIndex &&
rangeStack.top().startTime < startTime(currentJSHeapIndex)) {
@@ -237,42 +215,41 @@ void MemoryUsageModel::loadData()
allocation.update(event.numericData1);
currentSize = allocation.size;
if (currentSize > d->maxSize)
d->maxSize = currentSize;
if (currentSize > m_maxSize)
m_maxSize = currentSize;
if (currentJSHeapIndex != -1)
insertEnd(currentJSHeapIndex,
event.startTime - startTime(currentJSHeapIndex) - 1);
currentJSHeapIndex = insertStart(event.startTime, event.typeIndex);
d->data.insert(currentJSHeapIndex, allocation);
m_data.insert(currentJSHeapIndex, allocation);
}
}
d->modelManager->modelProxyCountUpdated(d->modelId, count(),
simpleModel->getEvents().count());
updateProgress(count(), simpleModel->getEvents().count());
}
if (currentJSHeapIndex != -1)
insertEnd(currentJSHeapIndex, d->modelManager->traceTime()->endTime() -
insertEnd(currentJSHeapIndex, modelManager()->traceTime()->endTime() -
startTime(currentJSHeapIndex) - 1);
if (currentUsageIndex != -1)
insertEnd(currentUsageIndex, d->modelManager->traceTime()->endTime() -
insertEnd(currentUsageIndex, modelManager()->traceTime()->endTime() -
startTime(currentUsageIndex) - 1);
computeNesting();
d->expandedRowCount = d->collapsedRowCount = 3;
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
setExpandedRowCount(3);
setCollapsedRowCount(3);
updateProgress(1, 1);
}
void MemoryUsageModel::clear()
{
Q_D(MemoryUsageModel);
d->data.clear();
d->maxSize = 1;
m_data.clear();
m_maxSize = 1;
AbstractTimelineModel::clear();
}
QString MemoryUsageModel::MemoryUsageModelPrivate::memoryTypeName(int type)
QString MemoryUsageModel::memoryTypeName(int type)
{
switch (type) {
case QmlDebug::HeapPage: return tr("Heap Allocation");

View File

@@ -67,8 +67,10 @@ protected:
void clear();
private:
class MemoryUsageModelPrivate;
Q_DECLARE_PRIVATE(MemoryUsageModel)
static QString memoryTypeName(int type);
QVector<MemoryAllocation> m_data;
qint64 m_maxSize;
};
} // namespace Internal

View File

@@ -19,72 +19,17 @@
#include "pixmapcachemodel.h"
#include "qmldebug/qmlprofilereventtypes.h"
#include "qmlprofiler/qmlprofilermodelmanager.h"
#include "qmlprofiler/abstracttimelinemodel_p.h"
#include <QDebug>
#include <QSize>
namespace QmlProfilerExtension {
namespace Internal {
using namespace QmlProfiler;
enum CacheState {
Uncached, // After loading started (or some other proof of existence) or after uncaching
ToBeCached, // After determining the pixmap is to be cached but before knowing its size
Cached, // After caching a pixmap or determining the size of a ToBeCached pixmap
Uncacheable, // If loading failed without ToBeCached or after a corrupt pixmap has been uncached
Corrupt // If after ToBeCached we learn that loading failed
};
enum LoadState {
Initial,
Loading,
Finished,
Error
};
struct PixmapState {
PixmapState(int width, int height, CacheState cache = Uncached) :
size(width, height), started(-1), loadState(Initial), cacheState(cache) {}
PixmapState(CacheState cache = Uncached) : started(-1), loadState(Initial), cacheState(cache) {}
QSize size;
int started;
LoadState loadState;
CacheState cacheState;
};
struct Pixmap {
Pixmap() {}
Pixmap(const QString &url) : url(url), sizes(1) {}
QString url;
QVector<PixmapState> sizes;
};
class PixmapCacheModel::PixmapCacheModelPrivate : public AbstractTimelineModelPrivate
{
public:
void computeMaxCacheSize();
void resizeUnfinishedLoads();
void flattenLoads();
int updateCacheCount(int lastCacheSizeEvent, qint64 startTime, qint64 pixSize,
PixmapCacheEvent &newEvent, int typeId);
QVector<PixmapCacheEvent> data;
QVector<Pixmap> pixmaps;
qint64 maxCacheSize;
private:
Q_DECLARE_PUBLIC(PixmapCacheModel)
};
PixmapCacheModel::PixmapCacheModel(QObject *parent)
: AbstractTimelineModel(new PixmapCacheModelPrivate(),
tr(QmlProfilerModelManager::featureName(QmlDebug::ProfilePixmapCache)),
: AbstractTimelineModel(tr(QmlProfilerModelManager::featureName(QmlDebug::ProfilePixmapCache)),
QmlDebug::PixmapCacheEvent, QmlDebug::MaximumRangeType, parent)
{
Q_D(PixmapCacheModel);
d->maxCacheSize = 1;
m_maxCacheSize = 1;
}
quint64 PixmapCacheModel::features() const
@@ -94,9 +39,8 @@ quint64 PixmapCacheModel::features() const
int PixmapCacheModel::rowMaxValue(int rowNumber) const
{
Q_D(const PixmapCacheModel);
if (rowNumber == 1) {
return d->maxCacheSize;
return m_maxCacheSize;
} else {
return AbstractTimelineModel::rowMaxValue(rowNumber);
}
@@ -104,33 +48,29 @@ int PixmapCacheModel::rowMaxValue(int rowNumber) const
int PixmapCacheModel::row(int index) const
{
Q_D(const PixmapCacheModel);
if (d->expanded)
if (expanded())
return selectionId(index) + 1;
return d->data[index].rowNumberCollapsed;
return m_data[index].rowNumberCollapsed;
}
int PixmapCacheModel::selectionId(int index) const
{
Q_D(const PixmapCacheModel);
return d->data[index].pixmapEventType == PixmapCacheCountChanged ?
0 : d->data[index].urlIndex + 1;
return m_data[index].pixmapEventType == PixmapCacheCountChanged ?
0 : m_data[index].urlIndex + 1;
}
QColor PixmapCacheModel::color(int index) const
{
Q_D(const PixmapCacheModel);
if (d->data[index].pixmapEventType == PixmapCacheCountChanged)
return colorByHue(PixmapCacheCountHue);
if (m_data[index].pixmapEventType == PixmapCacheCountChanged)
return colorByHue(s_pixmapCacheCountHue);
return colorBySelectionId(index);
}
float PixmapCacheModel::relativeHeight(int index) const
{
Q_D(const PixmapCacheModel);
if (d->data[index].pixmapEventType == PixmapCacheCountChanged)
return (float)d->data[index].cacheSize / (float)d->maxCacheSize;
if (m_data[index].pixmapEventType == PixmapCacheCountChanged)
return (float)m_data[index].cacheSize / (float)m_maxCacheSize;
else
return 1.0f;
}
@@ -145,10 +85,9 @@ QString getFilenameOnly(QString absUrl)
QVariantList PixmapCacheModel::labels() const
{
Q_D(const PixmapCacheModel);
QVariantList result;
if (d->expanded && !d->hidden && !isEmpty()) {
if (expanded() && !hidden() && !isEmpty()) {
{
// Cache Size
QVariantMap element;
@@ -158,12 +97,12 @@ QVariantList PixmapCacheModel::labels() const
result << element;
}
for (int i=0; i < d->pixmaps.count(); i++) {
for (int i=0; i < m_pixmaps.count(); i++) {
// Loading
QVariantMap element;
element.insert(QLatin1String("displayName"), d->pixmaps[i].url);
element.insert(QLatin1String("displayName"), m_pixmaps[i].url);
element.insert(QLatin1String("description"),
QVariant(getFilenameOnly(d->pixmaps[i].url)));
QVariant(getFilenameOnly(m_pixmaps[i].url)));
element.insert(QLatin1String("id"), QVariant(i+1));
result << element;
@@ -175,27 +114,26 @@ QVariantList PixmapCacheModel::labels() const
QVariantMap PixmapCacheModel::details(int index) const
{
Q_D(const PixmapCacheModel);
QVariantMap result;
const PixmapCacheEvent *ev = &d->data[index];
const PixmapCacheEvent *ev = &m_data[index];
if (ev->pixmapEventType == PixmapCacheCountChanged) {
result.insert(QLatin1String("displayName"), tr("Image Cached"));
} else {
if (ev->pixmapEventType == PixmapLoadingStarted) {
result.insert(QLatin1String("displayName"), tr("Image Loaded"));
if (d->pixmaps[ev->urlIndex].sizes[ev->sizeIndex].loadState != Finished)
if (m_pixmaps[ev->urlIndex].sizes[ev->sizeIndex].loadState != Finished)
result.insert(tr("Result"), tr("Load Error"));
}
result.insert(tr("Duration"), QmlProfilerBaseModel::formatTime(duration(index)));
}
result.insert(tr("Cache Size"), QString::fromLatin1("%1 px").arg(ev->cacheSize));
result.insert(tr("File"), getFilenameOnly(d->pixmaps[ev->urlIndex].url));
result.insert(tr("File"), getFilenameOnly(m_pixmaps[ev->urlIndex].url));
result.insert(tr("Width"), QString::fromLatin1("%1 px")
.arg(d->pixmaps[ev->urlIndex].sizes[ev->sizeIndex].size.width()));
.arg(m_pixmaps[ev->urlIndex].sizes[ev->sizeIndex].size.width()));
result.insert(tr("Height"), QString::fromLatin1("%1 px")
.arg(d->pixmaps[ev->urlIndex].sizes[ev->sizeIndex].size.height()));
.arg(m_pixmaps[ev->urlIndex].sizes[ev->sizeIndex].size.height()));
return result;
}
@@ -231,9 +169,8 @@ QVariantMap PixmapCacheModel::details(int index) const
void PixmapCacheModel::loadData()
{
Q_D(PixmapCacheModel);
clear();
QmlProfilerDataModel *simpleModel = d->modelManager->qmlModel();
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
@@ -247,24 +184,24 @@ void PixmapCacheModel::loadData()
continue;
PixmapCacheEvent newEvent;
newEvent.pixmapEventType = type.detailType;
newEvent.pixmapEventType = static_cast<PixmapEventType>(type.detailType);
qint64 pixmapStartTime = event.startTime;
newEvent.urlIndex = -1;
for (QVector<Pixmap>::const_iterator it(d->pixmaps.cend()); it != d->pixmaps.cbegin();) {
for (QVector<Pixmap>::const_iterator it(m_pixmaps.cend()); it != m_pixmaps.cbegin();) {
if ((--it)->url == type.location.filename) {
newEvent.urlIndex = it - d->pixmaps.cbegin();
newEvent.urlIndex = it - m_pixmaps.cbegin();
break;
}
}
newEvent.sizeIndex = -1;
if (newEvent.urlIndex == -1) {
newEvent.urlIndex = d->pixmaps.count();
d->pixmaps << Pixmap(type.location.filename);
newEvent.urlIndex = m_pixmaps.count();
m_pixmaps << Pixmap(type.location.filename);
}
Pixmap &pixmap = d->pixmaps[newEvent.urlIndex];
Pixmap &pixmap = m_pixmaps[newEvent.urlIndex];
switch (newEvent.pixmapEventType) {
case PixmapSizeKnown: {// pixmap size
// Look for pixmaps for which we don't know the size, yet and which have actually been
@@ -290,7 +227,7 @@ void PixmapCacheModel::loadData()
PixmapState &state = pixmap.sizes[newEvent.sizeIndex];
if (state.cacheState == ToBeCached) {
lastCacheSizeEvent = d->updateCacheCount(lastCacheSizeEvent, pixmapStartTime,
lastCacheSizeEvent = updateCacheCount(lastCacheSizeEvent, pixmapStartTime,
state.size.width() * state.size.height(), newEvent,
event.typeIndex);
state.cacheState = Cached;
@@ -351,8 +288,8 @@ void PixmapCacheModel::loadData()
pixmap.sizes << PixmapState(uncache ? Uncached : ToBeCached);
}
lastCacheSizeEvent = d->updateCacheCount(lastCacheSizeEvent, pixmapStartTime, pixSize,
newEvent, event.typeIndex);
lastCacheSizeEvent = updateCacheCount(lastCacheSizeEvent, pixmapStartTime, pixSize,
newEvent, event.typeIndex);
break;
}
case PixmapLoadingStarted: { // Load
@@ -373,7 +310,7 @@ void PixmapCacheModel::loadData()
PixmapState &state = pixmap.sizes[newEvent.sizeIndex];
state.loadState = Loading;
state.started = insertStart(pixmapStartTime, event.typeIndex);
d->data.insert(state.started, newEvent);
m_data.insert(state.started, newEvent);
break;
}
case PixmapLoadingFinished:
@@ -416,16 +353,16 @@ void PixmapCacheModel::loadData()
// If the pixmap loading wasn't started, start it at traceStartTime()
if (state.loadState == Initial) {
newEvent.pixmapEventType = PixmapLoadingStarted;
state.started = insert(d->modelManager->traceTime()->startTime(), pixmapStartTime -
d->modelManager->traceTime()->startTime(), event.typeIndex);
d->data.insert(state.started, newEvent);
state.started = insert(modelManager()->traceTime()->startTime(), pixmapStartTime -
modelManager()->traceTime()->startTime(), event.typeIndex);
m_data.insert(state.started, newEvent);
// All other indices are wrong now as we've prepended. Fix them ...
if (lastCacheSizeEvent >= state.started)
++lastCacheSizeEvent;
for (int pixmapIndex = 0; pixmapIndex < d->pixmaps.count(); ++pixmapIndex) {
Pixmap &brokenPixmap = d->pixmaps[pixmapIndex];
for (int pixmapIndex = 0; pixmapIndex < m_pixmaps.count(); ++pixmapIndex) {
Pixmap &brokenPixmap = m_pixmaps[pixmapIndex];
for (int sizeIndex = 0; sizeIndex < brokenPixmap.sizes.count(); ++sizeIndex) {
PixmapState &brokenSize = brokenPixmap.sizes[sizeIndex];
if ((pixmapIndex != newEvent.urlIndex || sizeIndex != newEvent.sizeIndex) &&
@@ -461,74 +398,69 @@ void PixmapCacheModel::loadData()
break;
}
d->modelManager->modelProxyCountUpdated(d->modelId, count(),
2 * simpleModel->getEvents().count());
updateProgress(count(), 2 * simpleModel->getEvents().count());
}
if (lastCacheSizeEvent != -1)
insertEnd(lastCacheSizeEvent, d->modelManager->traceTime()->endTime() -
insertEnd(lastCacheSizeEvent, modelManager()->traceTime()->endTime() -
startTime(lastCacheSizeEvent));
d->resizeUnfinishedLoads();
resizeUnfinishedLoads();
d->computeMaxCacheSize();
d->flattenLoads();
computeMaxCacheSize();
flattenLoads();
computeNesting();
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
updateProgress(1, 1);
}
void PixmapCacheModel::clear()
{
Q_D(PixmapCacheModel);
d->pixmaps.clear();
d->maxCacheSize = 1;
d->data.clear();
m_pixmaps.clear();
m_maxCacheSize = 1;
m_data.clear();
AbstractTimelineModel::clear();
}
void PixmapCacheModel::PixmapCacheModelPrivate::computeMaxCacheSize()
void PixmapCacheModel::computeMaxCacheSize()
{
maxCacheSize = 1;
foreach (const PixmapCacheModel::PixmapCacheEvent &event, data) {
m_maxCacheSize = 1;
foreach (const PixmapCacheModel::PixmapCacheEvent &event, m_data) {
if (event.pixmapEventType == PixmapCacheModel::PixmapCacheCountChanged) {
if (event.cacheSize > maxCacheSize)
maxCacheSize = event.cacheSize;
if (event.cacheSize > m_maxCacheSize)
m_maxCacheSize = event.cacheSize;
}
}
}
void PixmapCacheModel::PixmapCacheModelPrivate::resizeUnfinishedLoads()
void PixmapCacheModel::resizeUnfinishedLoads()
{
Q_Q(PixmapCacheModel);
// all the "load start" events with duration 0 continue till the end of the trace
for (int i = 0; i < q->count(); i++) {
if (data[i].pixmapEventType == PixmapCacheModel::PixmapLoadingStarted &&
ranges[i].duration == 0) {
q->insertEnd(i, modelManager->traceTime()->endTime() - ranges[i].start);
for (int i = 0; i < count(); i++) {
if (m_data[i].pixmapEventType == PixmapCacheModel::PixmapLoadingStarted &&
duration(i) == 0) {
insertEnd(i, modelManager()->traceTime()->endTime() - startTime(i));
}
}
}
void PixmapCacheModel::PixmapCacheModelPrivate::flattenLoads()
void PixmapCacheModel::flattenLoads()
{
Q_Q(PixmapCacheModel);
collapsedRowCount = 0;
int collapsedRowCount = 0;
// computes "compressed row"
QVector <qint64> eventEndTimes;
for (int i = 0; i < q->count(); i++) {
PixmapCacheModel::PixmapCacheEvent &event = data[i];
const Range &start = ranges[i];
for (int i = 0; i < count(); i++) {
PixmapCacheModel::PixmapCacheEvent &event = m_data[i];
if (event.pixmapEventType == PixmapCacheModel::PixmapLoadingStarted) {
event.rowNumberCollapsed = 0;
while (eventEndTimes.count() > event.rowNumberCollapsed &&
eventEndTimes[event.rowNumberCollapsed] > start.start)
eventEndTimes[event.rowNumberCollapsed] > startTime(i))
event.rowNumberCollapsed++;
if (eventEndTimes.count() == event.rowNumberCollapsed)
eventEndTimes << 0; // increase stack length, proper value added below
eventEndTimes[event.rowNumberCollapsed] = start.start + start.duration;
eventEndTimes[event.rowNumberCollapsed] = endTime(i);
// readjust to account for category empty row and bargraph
event.rowNumberCollapsed += 2;
@@ -538,26 +470,25 @@ void PixmapCacheModel::PixmapCacheModelPrivate::flattenLoads()
}
// Starting from 0, count is maxIndex+1
collapsedRowCount++;
expandedRowCount = pixmaps.count() + 2;
setCollapsedRowCount(collapsedRowCount + 1);
setExpandedRowCount(m_pixmaps.count() + 2);
}
int PixmapCacheModel::PixmapCacheModelPrivate::updateCacheCount(int lastCacheSizeEvent,
qint64 startTime, qint64 pixSize, PixmapCacheEvent &newEvent, int typeId)
int PixmapCacheModel::updateCacheCount(int lastCacheSizeEvent,
qint64 pixmapStartTime, qint64 pixSize, PixmapCacheEvent &newEvent, int typeId)
{
Q_Q(PixmapCacheModel);
newEvent.pixmapEventType = PixmapCacheCountChanged;
newEvent.rowNumberCollapsed = 1;
qint64 prevSize = 0;
if (lastCacheSizeEvent != -1) {
prevSize = data[lastCacheSizeEvent].cacheSize;
q->insertEnd(lastCacheSizeEvent, startTime - ranges[lastCacheSizeEvent].start);
prevSize = m_data[lastCacheSizeEvent].cacheSize;
insertEnd(lastCacheSizeEvent, pixmapStartTime - startTime(lastCacheSizeEvent));
}
newEvent.cacheSize = prevSize + pixSize;
int index = q->insertStart(startTime, typeId);
data.insert(index, newEvent);
int index = insertStart(pixmapStartTime, typeId);
m_data.insert(index, newEvent);
return index;
}

View File

@@ -24,6 +24,7 @@
#include <QStringList>
#include <QColor>
#include <QSize>
namespace QmlProfilerExtension {
namespace Internal {
@@ -32,13 +33,36 @@ class PixmapCacheModel : public QmlProfiler::AbstractTimelineModel
{
Q_OBJECT
public:
enum CacheState {
Uncached, // After loading started (or some other proof of existence) or after uncaching
ToBeCached, // After determining the pixmap is to be cached but before knowing its size
Cached, // After caching a pixmap or determining the size of a ToBeCached pixmap
Uncacheable, // If loading failed without ToBeCached or after a corrupt pixmap has been uncached
Corrupt // If after ToBeCached we learn that loading failed
};
struct PixmapCacheEvent {
int pixmapEventType;
int urlIndex;
int sizeIndex;
int rowNumberCollapsed;
qint64 cacheSize;
enum LoadState {
Initial,
Loading,
Finished,
Error
};
struct PixmapState {
PixmapState(int width, int height, CacheState cache = Uncached) :
size(width, height), started(-1), loadState(Initial), cacheState(cache) {}
PixmapState(CacheState cache = Uncached) : started(-1), loadState(Initial), cacheState(cache) {}
QSize size;
int started;
LoadState loadState;
CacheState cacheState;
};
struct Pixmap {
Pixmap() {}
Pixmap(const QString &url) : url(url), sizes(1) {}
QString url;
QVector<PixmapState> sizes;
};
enum PixmapEventType {
@@ -52,6 +76,14 @@ public:
MaximumPixmapEventType
};
struct PixmapCacheEvent {
PixmapEventType pixmapEventType;
int urlIndex;
int sizeIndex;
int rowNumberCollapsed;
qint64 cacheSize;
};
PixmapCacheModel(QObject *parent = 0);
quint64 features() const;
@@ -71,10 +103,17 @@ protected:
void clear();
private:
static const int PixmapCacheCountHue = 240;
void computeMaxCacheSize();
void resizeUnfinishedLoads();
void flattenLoads();
int updateCacheCount(int lastCacheSizeEvent, qint64 startTime, qint64 pixSize,
PixmapCacheEvent &newEvent, int typeId);
class PixmapCacheModelPrivate;
Q_DECLARE_PRIVATE(PixmapCacheModel)
QVector<PixmapCacheEvent> m_data;
QVector<Pixmap> m_pixmaps;
qint64 m_maxCacheSize;
static const int s_pixmapCacheCountHue = 240;
};
} // namespace Internal

View File

@@ -19,7 +19,6 @@
#include "scenegraphtimelinemodel.h"
#include "qmldebug/qmlprofilereventtypes.h"
#include "qmlprofiler/qmlprofilermodelmanager.h"
#include "qmlprofiler/abstracttimelinemodel_p.h"
#include <QCoreApplication>
#include <QDebug>
@@ -66,64 +65,11 @@ enum SceneGraphCategoryType {
MaximumSceneGraphCategoryType
};
enum SceneGraphStage {
MinimumSceneGraphStage = 0,
Polish = MinimumSceneGraphStage,
Wait,
GUIThreadSync,
Animations,
MaximumGUIThreadStage,
RenderThreadSync = MaximumGUIThreadStage,
Render,
Swap,
MaximumRenderThreadStage,
RenderPreprocess = MaximumRenderThreadStage,
RenderUpdate,
RenderBind,
RenderRender,
MaximumRenderStage,
Material = MaximumRenderStage,
MaximumMaterialStage,
GlyphRender = MaximumMaterialStage,
GlyphStore,
MaximumGlyphStage,
TextureBind = MaximumGlyphStage,
TextureConvert,
TextureSwizzle,
TextureUpload,
TextureMipmap,
TextureDeletion,
MaximumTextureStage,
MaximumSceneGraphStage = MaximumTextureStage
};
Q_STATIC_ASSERT(sizeof(StageLabels) == MaximumSceneGraphStage * sizeof(const char *));
class SceneGraphTimelineModel::SceneGraphTimelineModelPrivate :
public AbstractTimelineModel::AbstractTimelineModelPrivate
{
public:
void flattenLoads();
QVector<SceneGraphEvent> data;
qint64 insert(qint64 start, qint64 duration, int typeIndex, SceneGraphStage stage,
int glyphCount = -1);
static const char *threadLabel(SceneGraphStage stage);
private:
Q_DECLARE_PUBLIC(SceneGraphTimelineModel)
};
Q_STATIC_ASSERT(sizeof(StageLabels) ==
SceneGraphTimelineModel::MaximumSceneGraphStage * sizeof(const char *));
SceneGraphTimelineModel::SceneGraphTimelineModel(QObject *parent)
: AbstractTimelineModel(new SceneGraphTimelineModelPrivate,
tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileSceneGraph)),
: AbstractTimelineModel(tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileSceneGraph)),
QmlDebug::SceneGraphFrame, QmlDebug::MaximumRangeType, parent)
{
}
@@ -135,14 +81,12 @@ quint64 SceneGraphTimelineModel::features() const
int SceneGraphTimelineModel::row(int index) const
{
Q_D(const SceneGraphTimelineModel);
return expanded() ? (d->data[index].stage + 1) : d->data[index].rowNumberCollapsed;
return expanded() ? (m_data[index].stage + 1) : m_data[index].rowNumberCollapsed;
}
int SceneGraphTimelineModel::selectionId(int index) const
{
Q_D(const SceneGraphTimelineModel);
return d->data[index].stage;
return m_data[index].stage;
}
QColor SceneGraphTimelineModel::color(int index) const
@@ -152,14 +96,13 @@ QColor SceneGraphTimelineModel::color(int index) const
QVariantList SceneGraphTimelineModel::labels() const
{
Q_D(const SceneGraphTimelineModel);
QVariantList result;
if (d->expanded && !d->hidden && !isEmpty()) {
if (expanded() && !hidden() && !isEmpty()) {
for (SceneGraphStage i = MinimumSceneGraphStage; i < MaximumSceneGraphStage;
i = static_cast<SceneGraphStage>(i + 1)) {
QVariantMap element;
element.insert(QLatin1String("displayName"), tr(d->threadLabel(i)));
element.insert(QLatin1String("displayName"), tr(threadLabel(i)));
element.insert(QLatin1String("description"), tr(StageLabels[i]));
element.insert(QLatin1String("id"), i);
result << element;
@@ -171,12 +114,11 @@ QVariantList SceneGraphTimelineModel::labels() const
QVariantMap SceneGraphTimelineModel::details(int index) const
{
Q_D(const SceneGraphTimelineModel);
QVariantMap result;
const SceneGraphEvent *ev = &d->data[index];
const SceneGraphEvent *ev = &m_data[index];
result.insert(QLatin1String("displayName"),
tr(d->threadLabel(static_cast<SceneGraphStage>(ev->stage))));
tr(threadLabel(static_cast<SceneGraphStage>(ev->stage))));
result.insert(tr("Stage"), tr(StageLabels[ev->stage]));
result.insert(tr("Duration"), QmlProfilerBaseModel::formatTime(duration(index)));
if (ev->glyphCount >= 0)
@@ -187,9 +129,8 @@ QVariantMap SceneGraphTimelineModel::details(int index) const
void SceneGraphTimelineModel::loadData()
{
Q_D(SceneGraphTimelineModel);
clear();
QmlProfilerDataModel *simpleModel = d->modelManager->qmlModel();
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
@@ -208,95 +149,91 @@ void SceneGraphTimelineModel::loadData()
// parts of the breakdown are usually very short.
qint64 startTime = event.startTime - event.numericData1 - event.numericData2 -
event.numericData3 - event.numericData4;
startTime += d->insert(startTime, event.numericData1, event.typeIndex,
RenderPreprocess);
startTime += d->insert(startTime, event.numericData2, event.typeIndex, RenderUpdate);
startTime += d->insert(startTime, event.numericData3, event.typeIndex, RenderBind);
d->insert(startTime, event.numericData4, event.typeIndex, RenderRender);
startTime += insert(startTime, event.numericData1, event.typeIndex, RenderPreprocess);
startTime += insert(startTime, event.numericData2, event.typeIndex, RenderUpdate);
startTime += insert(startTime, event.numericData3, event.typeIndex, RenderBind);
insert(startTime, event.numericData4, event.typeIndex, RenderRender);
break;
}
case QmlDebug::SceneGraphAdaptationLayerFrame: {
qint64 startTime = event.startTime - event.numericData2 - event.numericData3;
startTime += d->insert(startTime, event.numericData2, event.typeIndex, GlyphRender,
event.numericData1);
d->insert(startTime, event.numericData3, event.typeIndex, GlyphStore,
event.numericData1);
startTime += insert(startTime, event.numericData2, event.typeIndex, GlyphRender,
event.numericData1);
insert(startTime, event.numericData3, event.typeIndex, GlyphStore, event.numericData1);
break;
}
case QmlDebug::SceneGraphContextFrame: {
d->insert(event.startTime - event.numericData1, event.numericData1, event.typeIndex,
insert(event.startTime - event.numericData1, event.numericData1, event.typeIndex,
Material);
break;
}
case QmlDebug::SceneGraphRenderLoopFrame: {
qint64 startTime = event.startTime - event.numericData1 - event.numericData2 -
event.numericData3;
startTime += d->insert(startTime, event.numericData1, event.typeIndex,
startTime += insert(startTime, event.numericData1, event.typeIndex,
RenderThreadSync);
startTime += d->insert(startTime, event.numericData2, event.typeIndex,
startTime += insert(startTime, event.numericData2, event.typeIndex,
Render);
d->insert(startTime, event.numericData3, event.typeIndex, Swap);
insert(startTime, event.numericData3, event.typeIndex, Swap);
break;
}
case QmlDebug::SceneGraphTexturePrepare: {
qint64 startTime = event.startTime - event.numericData1 - event.numericData2 -
event.numericData3 - event.numericData4 - event.numericData5;
startTime += d->insert(startTime, event.numericData1, event.typeIndex, TextureBind);
startTime += d->insert(startTime, event.numericData2, event.typeIndex, TextureConvert);
startTime += d->insert(startTime, event.numericData3, event.typeIndex, TextureSwizzle);
startTime += d->insert(startTime, event.numericData4, event.typeIndex, TextureUpload);
d->insert(startTime, event.numericData5, event.typeIndex, TextureMipmap);
startTime += insert(startTime, event.numericData1, event.typeIndex, TextureBind);
startTime += insert(startTime, event.numericData2, event.typeIndex, TextureConvert);
startTime += insert(startTime, event.numericData3, event.typeIndex, TextureSwizzle);
startTime += insert(startTime, event.numericData4, event.typeIndex, TextureUpload);
insert(startTime, event.numericData5, event.typeIndex, TextureMipmap);
break;
}
case QmlDebug::SceneGraphTextureDeletion: {
d->insert(event.startTime - event.numericData1, event.numericData1, event.typeIndex,
TextureDeletion);
insert(event.startTime - event.numericData1, event.numericData1, event.typeIndex,
TextureDeletion);
break;
}
case QmlDebug::SceneGraphPolishAndSync: {
qint64 startTime = event.startTime - event.numericData1 - event.numericData2 -
event.numericData3 - event.numericData4;
startTime += d->insert(startTime, event.numericData1, event.typeIndex, Polish);
startTime += d->insert(startTime, event.numericData2, event.typeIndex, Wait);
startTime += d->insert(startTime, event.numericData3, event.typeIndex, GUIThreadSync);
d->insert(startTime, event.numericData4, event.typeIndex, Animations);
startTime += insert(startTime, event.numericData1, event.typeIndex, Polish);
startTime += insert(startTime, event.numericData2, event.typeIndex, Wait);
startTime += insert(startTime, event.numericData3, event.typeIndex, GUIThreadSync);
insert(startTime, event.numericData4, event.typeIndex, Animations);
break;
}
case QmlDebug::SceneGraphWindowsAnimations: {
// GUI thread, separate animations stage
d->insert(event.startTime - event.numericData1, event.numericData1, event.typeIndex,
Animations);
insert(event.startTime - event.numericData1, event.numericData1, event.typeIndex,
Animations);
break;
}
case QmlDebug::SceneGraphPolishFrame: {
// GUI thread, separate polish stage
d->insert(event.startTime - event.numericData1, event.numericData1, event.typeIndex,
Polish);
insert(event.startTime - event.numericData1, event.numericData1, event.typeIndex,
Polish);
break;
}
default: break;
}
d->modelManager->modelProxyCountUpdated(d->modelId, count(), simpleModel->getEvents().count());
updateProgress(count(), simpleModel->getEvents().count());
}
computeNesting();
d->flattenLoads();
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
flattenLoads();
updateProgress(1, 1);
}
void SceneGraphTimelineModel::SceneGraphTimelineModelPrivate::flattenLoads()
void SceneGraphTimelineModel::flattenLoads()
{
Q_Q(SceneGraphTimelineModel);
collapsedRowCount = 0;
int collapsedRowCount = 0;
// computes "compressed row"
QVector <qint64> eventEndTimes;
for (int i = 0; i < q->count(); i++) {
SceneGraphEvent &event = data[i];
const Range &start = ranges[i];
for (int i = 0; i < count(); i++) {
SceneGraphEvent &event = m_data[i];
// Don't try to put render thread events in GUI row and vice versa.
// Rows below those are free for all.
if (event.stage < MaximumGUIThreadStage)
@@ -307,12 +244,12 @@ void SceneGraphTimelineModel::SceneGraphTimelineModelPrivate::flattenLoads()
event.rowNumberCollapsed = SceneGraphRenderThreadDetails;
while (eventEndTimes.count() > event.rowNumberCollapsed &&
eventEndTimes[event.rowNumberCollapsed] > start.start)
eventEndTimes[event.rowNumberCollapsed] > startTime(i))
++event.rowNumberCollapsed;
while (eventEndTimes.count() <= event.rowNumberCollapsed)
eventEndTimes << 0; // increase stack length, proper value added below
eventEndTimes[event.rowNumberCollapsed] = start.start + start.duration;
eventEndTimes[event.rowNumberCollapsed] = endTime(i);
// readjust to account for category empty row
event.rowNumberCollapsed++;
@@ -321,8 +258,8 @@ void SceneGraphTimelineModel::SceneGraphTimelineModelPrivate::flattenLoads()
}
// Starting from 0, count is maxIndex+1
collapsedRowCount++;
expandedRowCount = MaximumSceneGraphStage + 1;
setCollapsedRowCount(collapsedRowCount + 1);
setExpandedRowCount(MaximumSceneGraphStage + 1);
}
/*!
@@ -330,19 +267,18 @@ void SceneGraphTimelineModel::SceneGraphTimelineModelPrivate::flattenLoads()
* \a glyphCount (if it's a \c GlyphRender or \c GlyphStore event) into the scene graph model if its
* \a duration is greater than 0. Returns \a duration in that case; otherwise returns 0.
*/
qint64 SceneGraphTimelineModel::SceneGraphTimelineModelPrivate::insert(qint64 start,
qint64 duration, int typeIndex, SceneGraphStage stage, int glyphCount)
qint64 SceneGraphTimelineModel::insert(qint64 start, qint64 duration, int typeIndex,
SceneGraphStage stage, int glyphCount)
{
if (duration <= 0)
return 0;
Q_Q(SceneGraphTimelineModel);
data.insert(q->insert(start, duration, typeIndex), SceneGraphEvent(stage, glyphCount));
m_data.insert(AbstractTimelineModel::insert(start, duration, typeIndex),
SceneGraphEvent(stage, glyphCount));
return duration;
}
const char *SceneGraphTimelineModel::SceneGraphTimelineModelPrivate::threadLabel(
SceneGraphStage stage)
const char *SceneGraphTimelineModel::threadLabel(SceneGraphStage stage)
{
if (stage < MaximumGUIThreadStage)
return ThreadLabels[SceneGraphGUIThread];
@@ -355,13 +291,11 @@ const char *SceneGraphTimelineModel::SceneGraphTimelineModelPrivate::threadLabel
void SceneGraphTimelineModel::clear()
{
Q_D(SceneGraphTimelineModel);
d->collapsedRowCount = 1;
d->data.clear();
m_data.clear();
AbstractTimelineModel::clear();
}
SceneGraphTimelineModel::SceneGraphEvent::SceneGraphEvent(int stage, int glyphCount) :
SceneGraphTimelineModel::SceneGraphEvent::SceneGraphEvent(SceneGraphStage stage, int glyphCount) :
stage(stage), rowNumberCollapsed(-1), glyphCount(glyphCount)
{
}

View File

@@ -33,10 +33,46 @@ class SceneGraphTimelineModel : public QmlProfiler::AbstractTimelineModel
{
Q_OBJECT
public:
enum SceneGraphStage {
MinimumSceneGraphStage = 0,
Polish = MinimumSceneGraphStage,
Wait,
GUIThreadSync,
Animations,
MaximumGUIThreadStage,
RenderThreadSync = MaximumGUIThreadStage,
Render,
Swap,
MaximumRenderThreadStage,
RenderPreprocess = MaximumRenderThreadStage,
RenderUpdate,
RenderBind,
RenderRender,
MaximumRenderStage,
Material = MaximumRenderStage,
MaximumMaterialStage,
GlyphRender = MaximumMaterialStage,
GlyphStore,
MaximumGlyphStage,
TextureBind = MaximumGlyphStage,
TextureConvert,
TextureSwizzle,
TextureUpload,
TextureMipmap,
TextureDeletion,
MaximumTextureStage,
MaximumSceneGraphStage = MaximumTextureStage
};
struct SceneGraphEvent {
SceneGraphEvent(int stage = -1, int glyphCount = -1);
int stage;
SceneGraphEvent(SceneGraphStage stage = MaximumSceneGraphStage, int glyphCount = -1);
SceneGraphStage stage;
int rowNumberCollapsed;
int glyphCount; // only used for one event type
};
@@ -57,8 +93,12 @@ protected:
void clear();
private:
class SceneGraphTimelineModelPrivate;
Q_DECLARE_PRIVATE(SceneGraphTimelineModel)
void flattenLoads();
qint64 insert(qint64 start, qint64 duration, int typeIndex, SceneGraphStage stage,
int glyphCount = -1);
static const char *threadLabel(SceneGraphStage stage);
QVector<SceneGraphEvent> m_data;
};
} // namespace Internal