2013-08-08 13:28:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2013-08-08 13:28:08 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
#include "qmlprofileranimationsmodel.h"
|
2013-08-08 13:28:08 +02:00
|
|
|
#include "qmlprofilermodelmanager.h"
|
2014-02-18 17:32:20 +01:00
|
|
|
#include "qmlprofilerdatamodel.h"
|
2014-06-12 16:01:04 +02:00
|
|
|
#include "abstracttimelinemodel_p.h"
|
2014-03-07 17:35:56 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QUrl>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStack>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
class QmlProfilerAnimationsModel::QmlProfilerAnimationsModelPrivate : public AbstractTimelineModelPrivate
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2014-10-27 17:41:22 +01:00
|
|
|
QVector<QmlProfilerAnimationsModel::QmlPaintEventData> data;
|
2014-03-07 17:35:56 +01:00
|
|
|
int maxGuiThreadAnimations;
|
|
|
|
|
int maxRenderThreadAnimations;
|
2014-07-02 11:06:56 +02:00
|
|
|
int rowFromThreadId(QmlDebug::AnimationThread threadId) const;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-02-14 16:20:13 +01:00
|
|
|
private:
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_DECLARE_PUBLIC(QmlProfilerAnimationsModel)
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QmlProfilerAnimationsModel::QmlProfilerAnimationsModel(QObject *parent)
|
|
|
|
|
: AbstractTimelineModel(new QmlProfilerAnimationsModelPrivate,
|
2014-09-09 18:22:58 +02:00
|
|
|
tr(QmlProfilerModelManager::featureName(QmlDebug::ProfileAnimations)),
|
|
|
|
|
QmlDebug::Event, QmlDebug::MaximumRangeType, parent)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(QmlProfilerAnimationsModel);
|
2014-03-07 17:35:56 +01:00
|
|
|
d->maxGuiThreadAnimations = d->maxRenderThreadAnimations = 0;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
quint64 QmlProfilerAnimationsModel::features() const
|
2014-09-09 18:22:58 +02:00
|
|
|
{
|
|
|
|
|
return 1 << QmlDebug::ProfileAnimations;
|
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerAnimationsModel::clear()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(QmlProfilerAnimationsModel);
|
2014-03-07 17:35:56 +01:00
|
|
|
d->maxGuiThreadAnimations = d->maxRenderThreadAnimations = 0;
|
2014-07-08 17:18:51 +02:00
|
|
|
d->data.clear();
|
|
|
|
|
AbstractTimelineModel::clear();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
bool QmlProfilerAnimationsModel::accepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-07-08 14:43:15 +02:00
|
|
|
return AbstractTimelineModel::accepted(event) &&
|
2014-06-03 16:57:32 +02:00
|
|
|
event.detailType== QmlDebug::AnimationFrame;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerAnimationsModel::loadData()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(QmlProfilerAnimationsModel);
|
2013-08-08 13:28:08 +02:00
|
|
|
clear();
|
2014-02-18 17:32:20 +01:00
|
|
|
QmlProfilerDataModel *simpleModel = d->modelManager->qmlModel();
|
2013-08-08 13:28:08 +02:00
|
|
|
if (simpleModel->isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// collect events
|
2014-06-13 16:34:30 +02:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventData> &referenceList = simpleModel->getEvents();
|
|
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &typeList = simpleModel->getEventTypes();
|
2013-12-04 16:48:00 +01:00
|
|
|
|
|
|
|
|
QmlPaintEventData lastEvent;
|
2014-03-07 17:35:56 +01:00
|
|
|
qint64 minNextStartTimes[] = {0, 0};
|
2013-12-04 16:48:00 +01:00
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
foreach (const QmlProfilerDataModel::QmlEventData &event, referenceList) {
|
2014-06-13 16:34:30 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventTypeData &type = typeList[event.typeIndex];
|
2014-07-08 14:43:15 +02:00
|
|
|
if (!accepted(type))
|
2013-08-08 13:28:08 +02:00
|
|
|
continue;
|
|
|
|
|
|
2014-03-07 17:35:56 +01:00
|
|
|
lastEvent.threadId = (QmlDebug::AnimationThread)event.numericData3;
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
// initial estimation of the event duration: 1/framerate
|
2014-01-13 11:18:10 +01:00
|
|
|
qint64 estimatedDuration = event.numericData1 > 0 ? 1e9/event.numericData1 : 1;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// the profiler registers the animation events at the end of them
|
2014-01-13 11:18:10 +01:00
|
|
|
qint64 realEndTime = event.startTime;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-01-13 11:18:10 +01:00
|
|
|
// ranges should not overlap. If they do, our estimate wasn't accurate enough
|
2014-03-07 17:35:56 +01:00
|
|
|
qint64 realStartTime = qMax(event.startTime - estimatedDuration, minNextStartTimes[lastEvent.threadId]);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-01-13 11:18:10 +01:00
|
|
|
// Sometimes our estimate is far off or the server has miscalculated the frame rate
|
|
|
|
|
if (realStartTime >= realEndTime)
|
|
|
|
|
realEndTime = realStartTime + 1;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-01-13 11:18:10 +01:00
|
|
|
// Don't "fix" the framerate even if we've fixed the duration.
|
|
|
|
|
// The server should know better after all and if it doesn't we want to see that.
|
2013-12-04 16:48:00 +01:00
|
|
|
lastEvent.framerate = (int)event.numericData1;
|
|
|
|
|
lastEvent.animationcount = (int)event.numericData2;
|
2014-03-07 17:35:56 +01:00
|
|
|
QTC_ASSERT(lastEvent.animationcount > 0, continue);
|
|
|
|
|
|
2014-08-29 19:30:30 +02:00
|
|
|
d->data.insert(insert(realStartTime, realEndTime - realStartTime, event.typeIndex),
|
|
|
|
|
lastEvent);
|
2014-01-13 11:18:10 +01:00
|
|
|
|
2014-03-07 17:35:56 +01:00
|
|
|
if (lastEvent.threadId == QmlDebug::GuiThread)
|
|
|
|
|
d->maxGuiThreadAnimations = qMax(lastEvent.animationcount, d->maxGuiThreadAnimations);
|
|
|
|
|
else
|
|
|
|
|
d->maxRenderThreadAnimations =
|
|
|
|
|
qMax(lastEvent.animationcount, d->maxRenderThreadAnimations);
|
|
|
|
|
|
|
|
|
|
minNextStartTimes[lastEvent.threadId] = event.startTime + 1;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-07-08 17:18:51 +02:00
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, count(), referenceList.count());
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-08 17:18:51 +02:00
|
|
|
computeNesting();
|
2014-09-11 10:57:34 +02:00
|
|
|
d->expandedRowCount = d->collapsedRowCount =
|
|
|
|
|
(d->maxGuiThreadAnimations == 0 || d->maxRenderThreadAnimations == 0) ? 2 : 3;
|
2014-02-14 16:20:13 +01:00
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////// QML interface
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerAnimationsModel::QmlProfilerAnimationsModelPrivate::rowFromThreadId(
|
2014-07-02 11:06:56 +02:00
|
|
|
QmlDebug::AnimationThread threadId) const
|
|
|
|
|
{
|
|
|
|
|
return (threadId == QmlDebug::GuiThread || maxGuiThreadAnimations == 0) ? 1 : 2;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerAnimationsModel::row(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(const QmlProfilerAnimationsModel);
|
2014-07-08 17:18:51 +02:00
|
|
|
return d->rowFromThreadId(d->data[index].threadId);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerAnimationsModel::rowMaxValue(int rowNumber) const
|
2014-06-23 12:38:53 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(const QmlProfilerAnimationsModel);
|
2014-06-23 12:38:53 +02:00
|
|
|
switch (rowNumber) {
|
|
|
|
|
case 1:
|
|
|
|
|
return d->maxGuiThreadAnimations > 0 ? d->maxGuiThreadAnimations :
|
|
|
|
|
d->maxRenderThreadAnimations;
|
|
|
|
|
case 2:
|
|
|
|
|
return d->maxRenderThreadAnimations;
|
|
|
|
|
default:
|
|
|
|
|
return AbstractTimelineModel::rowMaxValue(rowNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerAnimationsModel::selectionId(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(const QmlProfilerAnimationsModel);
|
2014-07-08 17:18:51 +02:00
|
|
|
return d->data[index].threadId;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QColor QmlProfilerAnimationsModel::color(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(const QmlProfilerAnimationsModel);
|
2014-07-08 17:18:51 +02:00
|
|
|
double fpsFraction = d->data[index].framerate / 60.0;
|
2013-08-08 13:28:08 +02:00
|
|
|
if (fpsFraction > 1.0)
|
|
|
|
|
fpsFraction = 1.0;
|
|
|
|
|
if (fpsFraction < 0.0)
|
|
|
|
|
fpsFraction = 0.0;
|
2014-07-08 14:43:15 +02:00
|
|
|
return colorByFraction(fpsFraction);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
float QmlProfilerAnimationsModel::relativeHeight(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(const QmlProfilerAnimationsModel);
|
2014-07-08 17:18:51 +02:00
|
|
|
const QmlPaintEventData &data = d->data[index];
|
2014-07-02 11:06:56 +02:00
|
|
|
|
|
|
|
|
// 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.
|
2014-10-27 18:59:00 +01:00
|
|
|
int scaleThreshold = 2 * defaultRowHeight() - rowHeight(d->rowFromThreadId(data.threadId));
|
|
|
|
|
float boost = scaleThreshold > 0 ? (0.15 * scaleThreshold / defaultRowHeight()) : 0;
|
2014-07-02 11:06:56 +02:00
|
|
|
|
2014-07-08 17:18:51 +02:00
|
|
|
return boost + (1.0 - boost) * (float)data.animationcount /
|
|
|
|
|
(float)(data.threadId == QmlDebug::GuiThread ? d->maxGuiThreadAnimations :
|
|
|
|
|
d->maxRenderThreadAnimations);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QVariantList QmlProfilerAnimationsModel::labels() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(const QmlProfilerAnimationsModel);
|
2013-08-08 13:28:08 +02:00
|
|
|
QVariantList result;
|
|
|
|
|
|
2014-09-11 11:20:52 +02:00
|
|
|
if (!d->hidden && d->maxGuiThreadAnimations > 0) {
|
2013-08-08 13:28:08 +02:00
|
|
|
QVariantMap element;
|
2014-03-07 17:35:56 +01:00
|
|
|
element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(tr("GUI Thread")));
|
|
|
|
|
element.insert(QLatin1String("id"), QVariant(QmlDebug::GuiThread));
|
2013-08-08 13:28:08 +02:00
|
|
|
result << element;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-11 11:20:52 +02:00
|
|
|
if (!d->hidden && d->maxRenderThreadAnimations > 0) {
|
2014-03-07 17:35:56 +01:00
|
|
|
QVariantMap element;
|
|
|
|
|
element.insert(QLatin1String("displayName"), QVariant(tr("Animations")));
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(tr("Render Thread")));
|
|
|
|
|
element.insert(QLatin1String("id"), QVariant(QmlDebug::RenderThread));
|
|
|
|
|
result << element;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2014-03-07 17:35:56 +01:00
|
|
|
|
|
|
|
|
return result;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QVariantMap QmlProfilerAnimationsModel::details(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
Q_D(const QmlProfilerAnimationsModel);
|
2014-07-07 14:02:29 +02:00
|
|
|
QVariantMap result;
|
|
|
|
|
|
|
|
|
|
result.insert(QStringLiteral("displayName"), displayName());
|
2014-10-27 18:42:39 +01:00
|
|
|
result.insert(tr("Duration"), QmlProfilerBaseModel::formatTime(duration(index)));
|
2014-07-08 17:18:51 +02:00
|
|
|
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 ?
|
2014-07-07 14:02:29 +02:00
|
|
|
"GUI Thread" : "Render Thread"));
|
2013-08-08 13:28:08 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|