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
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qmlprofilerpainteventsmodelproxy.h"
|
|
|
|
|
#include "qmlprofilermodelmanager.h"
|
2014-02-18 17:32:20 +01:00
|
|
|
#include "qmlprofilerdatamodel.h"
|
2013-12-04 16:48:00 +01:00
|
|
|
#include "sortedtimelinemodel.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-02-14 16:20:13 +01:00
|
|
|
class PaintEventsModelProxy::PaintEventsModelProxyPrivate :
|
|
|
|
|
public SortedTimelineModel<QmlPaintEventData,
|
2014-06-12 16:01:04 +02:00
|
|
|
AbstractTimelineModel::AbstractTimelineModelPrivate>
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
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:
|
|
|
|
|
Q_DECLARE_PUBLIC(PaintEventsModelProxy)
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PaintEventsModelProxy::PaintEventsModelProxy(QObject *parent)
|
2014-06-12 16:01:04 +02:00
|
|
|
: AbstractTimelineModel(new PaintEventsModelProxyPrivate,
|
2014-07-03 10:53:13 +02:00
|
|
|
QLatin1String("PaintEventsModelProxy"), tr("Animations"),
|
2014-06-03 16:57:32 +02:00
|
|
|
QmlDebug::Event, QmlDebug::MaximumRangeType, parent)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-02-25 18:12:11 +01:00
|
|
|
Q_D(PaintEventsModelProxy);
|
2014-03-07 17:35:56 +01:00
|
|
|
d->maxGuiThreadAnimations = d->maxRenderThreadAnimations = 0;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PaintEventsModelProxy::clear()
|
|
|
|
|
{
|
2014-02-14 16:20:13 +01:00
|
|
|
Q_D(PaintEventsModelProxy);
|
2014-04-09 16:25:10 +02:00
|
|
|
d->clear();
|
2014-03-07 17:35:56 +01:00
|
|
|
d->maxGuiThreadAnimations = d->maxRenderThreadAnimations = 0;
|
2013-08-08 13:28:08 +02:00
|
|
|
d->expanded = false;
|
2014-02-14 16:20:13 +01:00
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, 0, 1);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
bool PaintEventsModelProxy::eventAccepted(const QmlProfilerDataModel::QmlEventTypeData &event) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-06-12 16:01:04 +02:00
|
|
|
return AbstractTimelineModel::eventAccepted(event) &&
|
2014-06-03 16:57:32 +02:00
|
|
|
event.detailType== QmlDebug::AnimationFrame;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaintEventsModelProxy::loadData()
|
|
|
|
|
{
|
2014-02-14 16:20:13 +01:00
|
|
|
Q_D(PaintEventsModelProxy);
|
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-03 10:53:13 +02:00
|
|
|
if (!eventAccepted(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-01-13 11:18:10 +01:00
|
|
|
d->insert(realStartTime, realEndTime - realStartTime, lastEvent);
|
|
|
|
|
|
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-02-14 16:20:13 +01:00
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, d->count(), referenceList.count());
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2013-12-04 16:48:00 +01:00
|
|
|
d->computeNesting();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
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-06-06 17:36:11 +02:00
|
|
|
int PaintEventsModelProxy::rowCount() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-03-07 17:35:56 +01:00
|
|
|
Q_D(const PaintEventsModelProxy);
|
2013-08-08 13:28:08 +02:00
|
|
|
if (isEmpty())
|
2014-07-03 10:53:13 +02:00
|
|
|
return 1;
|
2013-08-08 13:28:08 +02:00
|
|
|
else
|
2014-03-07 17:35:56 +01:00
|
|
|
return (d->maxGuiThreadAnimations == 0 || d->maxRenderThreadAnimations == 0) ? 2 : 3;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-02 11:06:56 +02:00
|
|
|
int PaintEventsModelProxy::PaintEventsModelProxyPrivate::rowFromThreadId(
|
|
|
|
|
QmlDebug::AnimationThread threadId) const
|
|
|
|
|
{
|
|
|
|
|
return (threadId == QmlDebug::GuiThread || maxGuiThreadAnimations == 0) ? 1 : 2;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int PaintEventsModelProxy::getEventRow(int index) const
|
|
|
|
|
{
|
2014-03-07 17:35:56 +01:00
|
|
|
Q_D(const PaintEventsModelProxy);
|
2014-07-02 11:06:56 +02:00
|
|
|
return d->rowFromThreadId(d->range(index).threadId);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-23 12:38:53 +02:00
|
|
|
int PaintEventsModelProxy::rowMaxValue(int rowNumber) const
|
|
|
|
|
{
|
|
|
|
|
Q_D(const PaintEventsModelProxy);
|
|
|
|
|
switch (rowNumber) {
|
|
|
|
|
case 1:
|
|
|
|
|
return d->maxGuiThreadAnimations > 0 ? d->maxGuiThreadAnimations :
|
|
|
|
|
d->maxRenderThreadAnimations;
|
|
|
|
|
case 2:
|
|
|
|
|
return d->maxRenderThreadAnimations;
|
|
|
|
|
default:
|
|
|
|
|
return AbstractTimelineModel::rowMaxValue(rowNumber);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int PaintEventsModelProxy::getEventId(int index) const
|
|
|
|
|
{
|
2014-03-07 17:35:56 +01:00
|
|
|
Q_D(const PaintEventsModelProxy);
|
|
|
|
|
return d->range(index).threadId;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QColor PaintEventsModelProxy::getColor(int index) const
|
|
|
|
|
{
|
2014-02-14 16:20:13 +01:00
|
|
|
Q_D(const PaintEventsModelProxy);
|
2013-12-04 16:48:00 +01:00
|
|
|
double fpsFraction = d->range(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-02-26 17:42:04 +01:00
|
|
|
return getFractionColor(fpsFraction);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float PaintEventsModelProxy::getHeight(int index) const
|
|
|
|
|
{
|
2014-02-14 16:20:13 +01:00
|
|
|
Q_D(const PaintEventsModelProxy);
|
2014-03-07 17:35:56 +01:00
|
|
|
const PaintEventsModelProxyPrivate::Range &range = d->range(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.
|
|
|
|
|
int scaleThreshold = 2 * DefaultRowHeight - rowHeight(d->rowFromThreadId(range.threadId));
|
|
|
|
|
float boost = scaleThreshold > 0 ? (0.15 * scaleThreshold / DefaultRowHeight) : 0;
|
|
|
|
|
|
|
|
|
|
return boost + (1.0 - boost) * (float)range.animationcount /
|
|
|
|
|
(float)(range.threadId == QmlDebug::GuiThread ? d->maxGuiThreadAnimations :
|
|
|
|
|
d->maxRenderThreadAnimations);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-06 17:36:11 +02:00
|
|
|
const QVariantList PaintEventsModelProxy::getLabels() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-03-07 17:35:56 +01:00
|
|
|
Q_D(const PaintEventsModelProxy);
|
2013-08-08 13:28:08 +02:00
|
|
|
QVariantList result;
|
|
|
|
|
|
2014-03-07 17:35:56 +01:00
|
|
|
if (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-03-07 17:35:56 +01:00
|
|
|
if (d->maxRenderThreadAnimations > 0) {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QVariantList PaintEventsModelProxy::getEventDetails(int index) const
|
|
|
|
|
{
|
2014-02-14 16:20:13 +01:00
|
|
|
Q_D(const PaintEventsModelProxy);
|
2013-08-08 13:28:08 +02:00
|
|
|
QVariantList result;
|
|
|
|
|
|
|
|
|
|
static const char trContext[] = "RangeDetails";
|
|
|
|
|
{
|
|
|
|
|
QVariantMap valuePair;
|
2014-06-06 17:36:11 +02:00
|
|
|
valuePair.insert(QLatin1String("title"), QVariant(title()));
|
2013-08-08 13:28:08 +02:00
|
|
|
result << valuePair;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// duration
|
|
|
|
|
{
|
|
|
|
|
QVariantMap valuePair;
|
2014-02-14 17:01:24 +01:00
|
|
|
valuePair.insert(QCoreApplication::translate(trContext, "Duration:"),
|
2014-02-18 17:32:20 +01:00
|
|
|
QVariant(QmlProfilerBaseModel::formatTime(d->range(index).duration)));
|
2013-08-08 13:28:08 +02:00
|
|
|
result << valuePair;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// duration
|
|
|
|
|
{
|
|
|
|
|
QVariantMap valuePair;
|
2013-12-04 16:48:00 +01:00
|
|
|
valuePair.insert(QCoreApplication::translate(trContext, "Framerate:"), QVariant(QString::fromLatin1("%1 FPS").arg(d->range(index).framerate)));
|
2013-08-08 13:28:08 +02:00
|
|
|
result << valuePair;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// duration
|
|
|
|
|
{
|
|
|
|
|
QVariantMap valuePair;
|
2013-12-04 16:48:00 +01:00
|
|
|
valuePair.insert(QCoreApplication::translate(trContext, "Animations:"), QVariant(QString::fromLatin1("%1").arg(d->range(index).animationcount)));
|
2013-08-08 13:28:08 +02:00
|
|
|
result << valuePair;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-07 17:35:56 +01:00
|
|
|
{
|
|
|
|
|
QVariantMap valuePair;
|
|
|
|
|
valuePair.insert(QCoreApplication::translate(trContext, "Context:"),
|
|
|
|
|
QCoreApplication::translate(trContext,
|
|
|
|
|
d->range(index).threadId == QmlDebug::GuiThread ?
|
|
|
|
|
"GUI Thread" : "Render Thread"));
|
|
|
|
|
result << valuePair;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|