Commit 93648031 authored by Ulf Hermann's avatar Ulf Hermann Committed by Ulf Hermann
Browse files

QmlProfiler: Don't needlessly use AbstractTimelineModelPrivate



We can easily implement all specialized models with only the public
interface.

Change-Id: I2fc75ad4a4270d9dd40068e78f9364f3963805e0
Reviewed-by: default avatarKai Koehne <kai.koehne@theqtcompany.com>
parent b2c8e701
......@@ -46,25 +46,11 @@
namespace QmlProfiler {
namespace Internal {
class QmlProfilerAnimationsModel::QmlProfilerAnimationsModelPrivate : public AbstractTimelineModelPrivate
{
public:
QVector<QmlProfilerAnimationsModel::QmlPaintEventData> data;
int maxGuiThreadAnimations;
int maxRenderThreadAnimations;
int rowFromThreadId(QmlDebug::AnimationThread threadId) const;
private:
Q_DECLARE_PUBLIC(QmlProfilerAnimationsModel)
};
QmlProfilerAnimationsModel::QmlProfilerAnimationsModel(QObject *parent)
: AbstractTimelineModel(new QmlProfilerAnimationsModelPrivate,
tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileAnimations)),
: AbstractTimelineModel(tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileAnimations)),
QmlDebug::Event, QmlDebug::MaximumRangeType, parent)
{
Q_D(QmlProfilerAnimationsModel);
d->maxGuiThreadAnimations = d->maxRenderThreadAnimations = 0;
m_maxGuiThreadAnimations = m_maxRenderThreadAnimations = 0;
}
quint64 QmlProfilerAnimationsModel::features() const
......@@ -74,9 +60,8 @@ quint64 QmlProfilerAnimationsModel::features() const
void QmlProfilerAnimationsModel::clear()
{
Q_D(QmlProfilerAnimationsModel);
d->maxGuiThreadAnimations = d->maxRenderThreadAnimations = 0;
d->data.clear();
m_maxGuiThreadAnimations = m_maxRenderThreadAnimations = 0;
m_data.clear();
AbstractTimelineModel::clear();
}
......@@ -88,9 +73,8 @@ bool QmlProfilerAnimationsModel::accepted(const QmlProfilerDataModel::QmlEventTy
void QmlProfilerAnimationsModel::loadData()
{
Q_D(QmlProfilerAnimationsModel);
clear();
QmlProfilerDataModel *simpleModel = d->modelManager->qmlModel();
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
......@@ -127,49 +111,43 @@ void QmlProfilerAnimationsModel::loadData()
lastEvent.animationcount = (int)event.numericData2;
QTC_ASSERT(lastEvent.animationcount > 0, continue);
d->data.insert(insert(realStartTime, realEndTime - realStartTime, event.typeIndex),
lastEvent);
m_data.insert(insert(realStartTime, realEndTime - realStartTime, event.typeIndex), lastEvent);
if (lastEvent.threadId == QmlDebug::GuiThread)
d->maxGuiThreadAnimations = qMax(lastEvent.animationcount, d->maxGuiThreadAnimations);
m_maxGuiThreadAnimations = qMax(lastEvent.animationcount, m_maxGuiThreadAnimations);
else
d->maxRenderThreadAnimations =
qMax(lastEvent.animationcount, d->maxRenderThreadAnimations);
m_maxRenderThreadAnimations = qMax(lastEvent.animationcount, m_maxRenderThreadAnimations);
minNextStartTimes[lastEvent.threadId] = event.startTime + 1;
d->modelManager->modelProxyCountUpdated(d->modelId, count(), referenceList.count());
updateProgress(count(), referenceList.count());
}
computeNesting();
d->expandedRowCount = d->collapsedRowCount =
(d->maxGuiThreadAnimations == 0 || d->maxRenderThreadAnimations == 0) ? 2 : 3;
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
setExpandedRowCount((m_maxGuiThreadAnimations == 0 || m_maxRenderThreadAnimations == 0) ? 2 : 3);
setCollapsedRowCount(expandedRowCount());
updateProgress(1, 1);
}
/////////////////// QML interface
int QmlProfilerAnimationsModel::QmlProfilerAnimationsModelPrivate::rowFromThreadId(
QmlDebug::AnimationThread threadId) const
int QmlProfilerAnimationsModel::rowFromThreadId(QmlDebug::AnimationThread threadId) const
{
return (threadId == QmlDebug::GuiThread || maxGuiThreadAnimations == 0) ? 1 : 2;
return (threadId == QmlDebug::GuiThread || m_maxGuiThreadAnimations == 0) ? 1 : 2;
}
int QmlProfilerAnimationsModel::row(int index) const
{
Q_D(const QmlProfilerAnimationsModel);
return d->rowFromThreadId(d->data[index].threadId);
return rowFromThreadId(m_data[index].threadId);
}
int QmlProfilerAnimationsModel::rowMaxValue(int rowNumber) const
{
Q_D(const QmlProfilerAnimationsModel);
switch (rowNumber) {
case 1:
return d->maxGuiThreadAnimations > 0 ? d->maxGuiThreadAnimations :
d->maxRenderThreadAnimations;
return m_maxGuiThreadAnimations > 0 ? m_maxGuiThreadAnimations : m_maxRenderThreadAnimations;
case 2:
return d->maxRenderThreadAnimations;
return m_maxRenderThreadAnimations;
default:
return AbstractTimelineModel::rowMaxValue(rowNumber);
}
......@@ -177,14 +155,12 @@ int QmlProfilerAnimationsModel::rowMaxValue(int rowNumber) const
int QmlProfilerAnimationsModel::selectionId(int index) const
{
Q_D(const QmlProfilerAnimationsModel);
return d->data[index].threadId;
return m_data[index].threadId;
}
QColor QmlProfilerAnimationsModel::color(int index) const
{
Q_D(const QmlProfilerAnimationsModel);
double fpsFraction = d->data[index].framerate / 60.0;
double fpsFraction = m_data[index].framerate / 60.0;
if (fpsFraction > 1.0)
fpsFraction = 1.0;
if (fpsFraction < 0.0)
......@@ -194,25 +170,23 @@ QColor QmlProfilerAnimationsModel::color(int index) const
float QmlProfilerAnimationsModel::relativeHeight(int index) const
{
Q_D(const QmlProfilerAnimationsModel);
const QmlPaintEventData &data = d->data[index];
const QmlPaintEventData &data = m_data[index];
// Add some height to the events if we're far from the scale threshold of 2 * DefaultRowHeight.
// Like that you can see the smaller events more easily.
int scaleThreshold = 2 * defaultRowHeight() - rowHeight(d->rowFromThreadId(data.threadId));
int scaleThreshold = 2 * defaultRowHeight() - rowHeight(rowFromThreadId(data.threadId));
float boost = scaleThreshold > 0 ? (0.15 * scaleThreshold / defaultRowHeight()) : 0;
return boost + (1.0 - boost) * (float)data.animationcount /
(float)(data.threadId == QmlDebug::GuiThread ? d->maxGuiThreadAnimations :
d->maxRenderThreadAnimations);
(float)(data.threadId == QmlDebug::GuiThread ? m_maxGuiThreadAnimations :
m_maxRenderThreadAnimations);
}
QVariantList QmlProfilerAnimationsModel::labels() const
{
Q_D(const QmlProfilerAnimationsModel);
QVariantList result;
if (!d->hidden && d->maxGuiThreadAnimations > 0) {
if (!hidden() && m_maxGuiThreadAnimations > 0) {
QVariantMap element;
element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
element.insert(QLatin1String("description"), QVariant(tr("GUI Thread")));
......@@ -220,7 +194,7 @@ QVariantList QmlProfilerAnimationsModel::labels() const
result << element;
}
if (!d->hidden && d->maxRenderThreadAnimations > 0) {
if (!hidden() && m_maxRenderThreadAnimations > 0) {
QVariantMap element;
element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
element.insert(QLatin1String("description"), QVariant(tr("Render Thread")));
......@@ -233,14 +207,13 @@ QVariantList QmlProfilerAnimationsModel::labels() const
QVariantMap QmlProfilerAnimationsModel::details(int index) const
{
Q_D(const QmlProfilerAnimationsModel);
QVariantMap result;
result.insert(QStringLiteral("displayName"), displayName());
result.insert(tr("Duration"), QmlProfilerBaseModel::formatTime(duration(index)));
result.insert(tr("Framerate"), QString::fromLatin1("%1 FPS").arg(d->data[index].framerate));
result.insert(tr("Animations"), QString::fromLatin1("%1").arg(d->data[index].animationcount));
result.insert(tr("Context"), tr(d->data[index].threadId == QmlDebug::GuiThread ?
result.insert(tr("Framerate"), QString::fromLatin1("%1 FPS").arg(m_data[index].framerate));
result.insert(tr("Animations"), QString::fromLatin1("%1").arg(m_data[index].animationcount));
result.insert(tr("Context"), tr(m_data[index].threadId == QmlDebug::GuiThread ?
"GUI Thread" : "Render Thread"));
return result;
}
......
......@@ -81,8 +81,10 @@ protected:
void clear();
private:
class QmlProfilerAnimationsModelPrivate;
Q_DECLARE_PRIVATE(QmlProfilerAnimationsModel)
QVector<QmlProfilerAnimationsModel::QmlPaintEventData> m_data;
int m_maxGuiThreadAnimations;
int m_maxRenderThreadAnimations;
int rowFromThreadId(QmlDebug::AnimationThread threadId) const;
};
}
......
......@@ -31,7 +31,6 @@
#include "qmlprofilerrangemodel.h"
#include "qmlprofilermodelmanager.h"
#include "qmlprofilerdatamodel.h"
#include "abstracttimelinemodel_p.h"
#include <QCoreApplication>
#include <QVector>
......@@ -45,48 +44,30 @@
namespace QmlProfiler {
namespace Internal {
class QmlProfilerRangeModel::QmlProfilerRangeModelPrivate : public AbstractTimelineModelPrivate
{
public:
// convenience functions
void computeNestingContracted();
void computeExpandedLevels();
void findBindingLoops();
QVector<QmlRangeEventStartInstance> data;
QVector<int> expandedRowTypes;
private:
Q_DECLARE_PUBLIC(QmlProfilerRangeModel)
};
QmlProfilerRangeModel::QmlProfilerRangeModel(QmlDebug::RangeType rangeType, QObject *parent)
: AbstractTimelineModel(new QmlProfilerRangeModelPrivate, categoryLabel(rangeType),
QmlDebug::MaximumMessage, rangeType, parent)
: AbstractTimelineModel(categoryLabel(rangeType), QmlDebug::MaximumMessage, rangeType, parent)
{
Q_D(QmlProfilerRangeModel);
d->expandedRowTypes << -1;
m_expandedRowTypes << -1;
}
quint64 QmlProfilerRangeModel::features() const
{
Q_D(const QmlProfilerRangeModel);
return 1ULL << QmlDebug::featureFromRangeType(d->rangeType);
return 1ULL << QmlDebug::featureFromRangeType(rangeType());
}
void QmlProfilerRangeModel::clear()
{
Q_D(QmlProfilerRangeModel);
d->expandedRowTypes.clear();
d->expandedRowTypes << -1;
d->data.clear();
m_expandedRowTypes.clear();
m_expandedRowTypes << -1;
m_data.clear();
AbstractTimelineModel::clear();
}
void QmlProfilerRangeModel::loadData()
{
Q_D(QmlProfilerRangeModel);
clear();
QmlProfilerDataModel *simpleModel = d->modelManager->qmlModel();
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
if (simpleModel->isEmpty())
return;
......@@ -99,46 +80,45 @@ void QmlProfilerRangeModel::loadData()
continue;
// store starttime-based instance
d->data.insert(insert(event.startTime, event.duration, event.typeIndex),
QmlRangeEventStartInstance());
d->modelManager->modelProxyCountUpdated(d->modelId, count(), eventList.count() * 6);
m_data.insert(insert(event.startTime, event.duration, event.typeIndex),
QmlRangeEventStartInstance());
updateProgress(count(), eventList.count() * 6);
}
d->modelManager->modelProxyCountUpdated(d->modelId, 2, 6);
updateProgress(2, 6);
// compute range nesting
computeNesting();
// compute nestingLevel - nonexpanded
d->computeNestingContracted();
computeNestingContracted();
d->modelManager->modelProxyCountUpdated(d->modelId, 3, 6);
updateProgress(3, 6);
// compute nestingLevel - expanded
d->computeExpandedLevels();
computeExpandedLevels();
d->modelManager->modelProxyCountUpdated(d->modelId, 4, 6);
updateProgress(4, 6);
d->findBindingLoops();
findBindingLoops();
d->modelManager->modelProxyCountUpdated(d->modelId, 5, 6);
updateProgress(5, 6);
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
updateProgress(1, 1);
}
void QmlProfilerRangeModel::QmlProfilerRangeModelPrivate::computeNestingContracted()
void QmlProfilerRangeModel::computeNestingContracted()
{
Q_Q(QmlProfilerRangeModel);
int i;
int eventCount = q->count();
int eventCount = count();
int nestingLevels = QmlDebug::Constants::QML_MIN_LEVEL;
collapsedRowCount = nestingLevels + 1;
int collapsedRowCount = nestingLevels + 1;
QVector<qint64> nestingEndTimes;
nestingEndTimes.fill(0, nestingLevels + 1);
for (i = 0; i < eventCount; i++) {
qint64 st = ranges[i].start;
qint64 st = startTime(i);
// per type
if (nestingEndTimes[nestingLevels] > st) {
......@@ -151,56 +131,53 @@ void QmlProfilerRangeModel::QmlProfilerRangeModelPrivate::computeNestingContract
nestingEndTimes[nestingLevels-1] <= st)
nestingLevels--;
}
nestingEndTimes[nestingLevels] = st + ranges[i].duration;
nestingEndTimes[nestingLevels] = st + duration(i);
data[i].displayRowCollapsed = nestingLevels;
m_data[i].displayRowCollapsed = nestingLevels;
}
setCollapsedRowCount(collapsedRowCount);
}
void QmlProfilerRangeModel::QmlProfilerRangeModelPrivate::computeExpandedLevels()
void QmlProfilerRangeModel::computeExpandedLevels()
{
Q_Q(QmlProfilerRangeModel);
QHash<int, int> eventRow;
int eventCount = q->count();
int eventCount = count();
for (int i = 0; i < eventCount; i++) {
int typeId = ranges[i].typeId;
if (!eventRow.contains(typeId)) {
eventRow[typeId] = expandedRowTypes.size();
expandedRowTypes << typeId;
int eventTypeId = typeId(i);
if (!eventRow.contains(eventTypeId)) {
eventRow[eventTypeId] = m_expandedRowTypes.size();
m_expandedRowTypes << eventTypeId;
}
data[i].displayRowExpanded = eventRow[typeId];
m_data[i].displayRowExpanded = eventRow[eventTypeId];
}
expandedRowCount = expandedRowTypes.size();
setExpandedRowCount(m_expandedRowTypes.size());
}
void QmlProfilerRangeModel::QmlProfilerRangeModelPrivate::findBindingLoops()
void QmlProfilerRangeModel::findBindingLoops()
{
Q_Q(QmlProfilerRangeModel);
if (rangeType != QmlDebug::Binding && rangeType != QmlDebug::HandlingSignal)
if (rangeType() != QmlDebug::Binding && rangeType() != QmlDebug::HandlingSignal)
return;
typedef QPair<int, int> CallStackEntry;
QStack<CallStackEntry> callStack;
for (int i = 0; i < q->count(); ++i) {
const Range *potentialParent = callStack.isEmpty()
? 0 : &ranges[callStack.top().second];
for (int i = 0; i < count(); ++i) {
int potentialParent = callStack.isEmpty() ? -1 : callStack.top().second;
while (potentialParent
&& !(potentialParent->start + potentialParent->duration > ranges[i].start)) {
while (potentialParent != -1 && !(endTime(potentialParent) > startTime(i))) {
callStack.pop();
potentialParent = callStack.isEmpty() ? 0 : &ranges[callStack.top().second];
potentialParent = callStack.isEmpty() ? -1 : callStack.top().second;
}
// check whether event is already in stack
for (int ii = 0; ii < callStack.size(); ++ii) {
if (callStack.at(ii).first == ranges[i].typeId) {
data[i].bindingLoopHead = callStack.at(ii).second;
if (callStack.at(ii).first == typeId(i)) {
m_data[i].bindingLoopHead = callStack.at(ii).second;
break;
}
}
CallStackEntry newEntry(ranges[i].typeId, i);
CallStackEntry newEntry(typeId(i), i);
callStack.push(newEntry);
}
......@@ -216,17 +193,15 @@ QString QmlProfilerRangeModel::categoryLabel(QmlDebug::RangeType rangeType)
int QmlProfilerRangeModel::row(int index) const
{
Q_D(const QmlProfilerRangeModel);
if (d->expanded)
return d->data[index].displayRowExpanded;
if (expanded())
return m_data[index].displayRowExpanded;
else
return d->data[index].displayRowCollapsed;
return m_data[index].displayRowCollapsed;
}
int QmlProfilerRangeModel::bindingLoopDest(int index) const
{
Q_D(const QmlProfilerRangeModel);
return d->data[index].bindingLoopHead;
return m_data[index].bindingLoopHead;
}
QColor QmlProfilerRangeModel::color(int index) const
......@@ -236,15 +211,14 @@ QColor QmlProfilerRangeModel::color(int index) const
QVariantList QmlProfilerRangeModel::labels() const
{
Q_D(const QmlProfilerRangeModel);
QVariantList result;
if (d->expanded && !d->hidden) {
if (expanded() && !hidden()) {
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
d->modelManager->qmlModel()->getEventTypes();
for (int i = 1; i < d->expandedRowCount; i++) { // Ignore the -1 for the first row
modelManager()->qmlModel()->getEventTypes();
for (int i = 1; i < expandedRowCount(); i++) { // Ignore the -1 for the first row
QVariantMap element;
int typeId = d->expandedRowTypes[i];
int typeId = m_expandedRowTypes[i];
element.insert(QLatin1String("displayName"), QVariant(types[typeId].displayName));
element.insert(QLatin1String("description"), QVariant(types[typeId].data));
element.insert(QLatin1String("id"), QVariant(typeId));
......@@ -257,13 +231,12 @@ QVariantList QmlProfilerRangeModel::labels() const
QVariantMap QmlProfilerRangeModel::details(int index) const
{
Q_D(const QmlProfilerRangeModel);
QVariantMap result;
int id = selectionId(index);
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
d->modelManager->qmlModel()->getEventTypes();
modelManager()->qmlModel()->getEventTypes();
result.insert(QStringLiteral("displayName"), categoryLabel(d->rangeType));
result.insert(QStringLiteral("displayName"), categoryLabel(rangeType()));
result.insert(tr("Duration"), QmlProfilerBaseModel::formatTime(duration(index)));
result.insert(tr("Details"), types[id].data);
......@@ -273,12 +246,11 @@ QVariantMap QmlProfilerRangeModel::details(int index) const
QVariantMap QmlProfilerRangeModel::location(int index) const
{
Q_D(const QmlProfilerRangeModel);
QVariantMap result;
int id = selectionId(index);
const QmlDebug::QmlEventLocation &location
= d->modelManager->qmlModel()->getEventTypes().at(id).location;
= modelManager()->qmlModel()->getEventTypes().at(id).location;
result.insert(QStringLiteral("file"), location.filename);
result.insert(QStringLiteral("line"), location.line);
......@@ -289,24 +261,22 @@ QVariantMap QmlProfilerRangeModel::location(int index) const
bool QmlProfilerRangeModel::isSelectionIdValid(int typeId) const
{
Q_D(const QmlProfilerRangeModel);
if (typeId < 0)
return false;
const QmlProfilerDataModel::QmlEventTypeData &type =
d->modelManager->qmlModel()->getEventTypes().at(typeId);
if (type.message != d->message || type.rangeType != d->rangeType)
modelManager()->qmlModel()->getEventTypes().at(typeId);
if (type.message != message() || type.rangeType != rangeType())
return false;
return true;
}
int QmlProfilerRangeModel::selectionIdForLocation(const QString &filename, int line, int column) const
{
Q_D(const QmlProfilerRangeModel);
// if this is called from v8 view, we don't have the column number, it will be -1
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
d->modelManager->qmlModel()->getEventTypes();
for (int i = 1; i < d->expandedRowCount; ++i) {
int typeId = d->expandedRowTypes[i];
modelManager()->qmlModel()->getEventTypes();
for (int i = 1; i < expandedRowCount(); ++i) {
int typeId = m_expandedRowTypes[i];
const QmlProfilerDataModel::QmlEventTypeData &eventData = types[typeId];
if (eventData.location.filename == filename &&
eventData.location.line == line &&
......
......@@ -82,8 +82,12 @@ protected:
void clear();
private:
class QmlProfilerRangeModelPrivate;
Q_DECLARE_PRIVATE(QmlProfilerRangeModel)
void computeNestingContracted();
void computeExpandedLevels();
void findBindingLoops();
QVector<QmlRangeEventStartInstance> m_data;
QVector<int> m_expandedRowTypes;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment