2013-08-08 13:28:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2013-08-08 13:28:08 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
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"
|
2016-04-28 16:02:54 +02:00
|
|
|
|
2014-03-07 17:35:56 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-28 16:02:54 +02:00
|
|
|
#include <QCoreApplication>
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <QVector>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QUrl>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStack>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-10-28 17:37:11 +01:00
|
|
|
QmlProfilerAnimationsModel::QmlProfilerAnimationsModel(QmlProfilerModelManager *manager,
|
2014-10-28 19:01:43 +01:00
|
|
|
QObject *parent) :
|
2016-05-02 12:18:57 +02:00
|
|
|
QmlProfilerTimelineModel(manager, Event, MaximumRangeType, ProfileAnimations, parent)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2016-05-24 09:28:58 +02:00
|
|
|
m_minNextStartTimes[0] = m_minNextStartTimes[1] = 0;
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
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
|
|
|
{
|
2016-04-26 13:23:35 +02:00
|
|
|
m_minNextStartTimes[0] = m_minNextStartTimes[1] = 0;
|
2014-10-28 10:57:32 +01:00
|
|
|
m_maxGuiThreadAnimations = m_maxRenderThreadAnimations = 0;
|
|
|
|
|
m_data.clear();
|
2014-10-28 19:01:43 +01:00
|
|
|
QmlProfilerTimelineModel::clear();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 11:50:59 +02:00
|
|
|
bool QmlProfilerAnimationsModel::accepted(const QmlEventType &event) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2016-06-06 19:51:55 +02:00
|
|
|
return QmlProfilerTimelineModel::accepted(event) && event.detailType() == AnimationFrame;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
void QmlProfilerAnimationsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2016-04-26 13:23:35 +02:00
|
|
|
Q_UNUSED(type);
|
|
|
|
|
AnimationThread lastThread = (AnimationThread)event.number<qint32>(2);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
// initial estimation of the event duration: 1/framerate
|
|
|
|
|
qint64 estimatedDuration = event.number<qint32>(0) > 0 ? 1e9 / event.number<qint32>(0) : 1;
|
2014-03-07 17:35:56 +01:00
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
// the profiler registers the animation events at the end of them
|
|
|
|
|
qint64 realEndTime = event.timestamp();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
// ranges should not overlap. If they do, our estimate wasn't accurate enough
|
|
|
|
|
qint64 realStartTime = qMax(event.timestamp() - estimatedDuration,
|
|
|
|
|
m_minNextStartTimes[lastThread]);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-26 13:23:35 +02: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
|
|
|
|
2016-04-26 13:23:35 +02: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.
|
|
|
|
|
QmlPaintEventData lastEvent;
|
|
|
|
|
lastEvent.typeId = event.typeIndex();
|
|
|
|
|
lastEvent.framerate = event.number<qint32>(0);
|
|
|
|
|
lastEvent.animationcount = event.number<qint32>(1);
|
|
|
|
|
QTC_ASSERT(lastEvent.animationcount > 0, return);
|
2014-03-07 17:35:56 +01:00
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
m_data.insert(insert(realStartTime, realEndTime - realStartTime, lastThread), lastEvent);
|
2014-01-13 11:18:10 +01:00
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
if (lastThread == GuiThread)
|
|
|
|
|
m_maxGuiThreadAnimations = qMax(lastEvent.animationcount, m_maxGuiThreadAnimations);
|
|
|
|
|
else
|
|
|
|
|
m_maxRenderThreadAnimations = qMax(lastEvent.animationcount,
|
|
|
|
|
m_maxRenderThreadAnimations);
|
2014-03-07 17:35:56 +01:00
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
m_minNextStartTimes[lastThread] = event.timestamp() + 1;
|
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-26 13:23:35 +02:00
|
|
|
void QmlProfilerAnimationsModel::finalize()
|
|
|
|
|
{
|
2014-07-08 17:18:51 +02:00
|
|
|
computeNesting();
|
2014-10-28 10:57:32 +01:00
|
|
|
setExpandedRowCount((m_maxGuiThreadAnimations == 0 || m_maxRenderThreadAnimations == 0) ? 2 : 3);
|
|
|
|
|
setCollapsedRowCount(expandedRowCount());
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 14:26:57 +01:00
|
|
|
int QmlProfilerAnimationsModel::rowFromThreadId(int threadId) const
|
2014-07-02 11:06:56 +02:00
|
|
|
{
|
2016-05-02 12:18:57 +02:00
|
|
|
return (threadId == GuiThread || m_maxGuiThreadAnimations == 0) ? 1 : 2;
|
2014-07-02 11:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerAnimationsModel::rowMaxValue(int rowNumber) const
|
2014-06-23 12:38:53 +02:00
|
|
|
{
|
|
|
|
|
switch (rowNumber) {
|
|
|
|
|
case 1:
|
2014-10-28 10:57:32 +01:00
|
|
|
return m_maxGuiThreadAnimations > 0 ? m_maxGuiThreadAnimations : m_maxRenderThreadAnimations;
|
2014-06-23 12:38:53 +02:00
|
|
|
case 2:
|
2014-10-28 10:57:32 +01:00
|
|
|
return m_maxRenderThreadAnimations;
|
2014-06-23 12:38:53 +02:00
|
|
|
default:
|
2014-10-28 19:01:43 +01:00
|
|
|
return QmlProfilerTimelineModel::rowMaxValue(rowNumber);
|
2014-06-23 12:38:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 14:26:57 +01:00
|
|
|
int QmlProfilerAnimationsModel::typeId(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-28 14:26:57 +01:00
|
|
|
return m_data[index].typeId;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-18 17:37:25 +01:00
|
|
|
int QmlProfilerAnimationsModel::expandedRow(int index) const
|
|
|
|
|
{
|
|
|
|
|
return rowFromThreadId(selectionId(index));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int QmlProfilerAnimationsModel::collapsedRow(int index) const
|
|
|
|
|
{
|
|
|
|
|
return rowFromThreadId(selectionId(index));
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QColor QmlProfilerAnimationsModel::color(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-28 10:57:32 +01:00
|
|
|
double fpsFraction = m_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
|
|
|
{
|
2016-05-02 12:18:57 +02:00
|
|
|
return (float)m_data[index].animationcount / (float)(selectionId(index) == GuiThread ?
|
2014-11-27 13:40:04 +01:00
|
|
|
m_maxGuiThreadAnimations :
|
|
|
|
|
m_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
|
|
|
{
|
|
|
|
|
QVariantList result;
|
|
|
|
|
|
2014-10-29 10:41:27 +01:00
|
|
|
if (m_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")));
|
2016-05-02 12:18:57 +02:00
|
|
|
element.insert(QLatin1String("id"), QVariant(GuiThread));
|
2013-08-08 13:28:08 +02:00
|
|
|
result << element;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 10:41:27 +01:00
|
|
|
if (m_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")));
|
2016-05-02 12:18:57 +02:00
|
|
|
element.insert(QLatin1String("id"), QVariant(RenderThread));
|
2014-03-07 17:35:56 +01:00
|
|
|
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-07-07 14:02:29 +02:00
|
|
|
QVariantMap result;
|
|
|
|
|
|
|
|
|
|
result.insert(QStringLiteral("displayName"), displayName());
|
2015-09-10 16:03:21 +02:00
|
|
|
result.insert(tr("Duration"), QmlProfilerDataModel::formatTime(duration(index)));
|
2014-10-28 10:57:32 +01:00
|
|
|
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));
|
2016-05-02 12:18:57 +02:00
|
|
|
result.insert(tr("Context"), tr(selectionId(index) == GuiThread ? "GUI Thread" :
|
|
|
|
|
"Render Thread"));
|
2013-08-08 13:28:08 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:02:54 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProfiler
|