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"
|
|
|
|
|
#include "qmlprofilersimplemodel.h"
|
2013-12-04 16:48:00 +01:00
|
|
|
#include "sortedtimelinemodel.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 {
|
|
|
|
|
|
|
|
|
|
struct CategorySpan {
|
|
|
|
|
bool expanded;
|
|
|
|
|
int expandedRows;
|
|
|
|
|
int contractedRows;
|
|
|
|
|
};
|
|
|
|
|
|
2013-12-04 16:48:00 +01:00
|
|
|
class PaintEventsModelProxy::PaintEventsModelProxyPrivate : public SortedTimelineModel<QmlPaintEventData>
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
PaintEventsModelProxyPrivate(PaintEventsModelProxy *qq) : q(qq) {}
|
|
|
|
|
~PaintEventsModelProxyPrivate() {}
|
|
|
|
|
|
|
|
|
|
void computeAnimationCountLimit();
|
|
|
|
|
|
|
|
|
|
int minAnimationCount;
|
|
|
|
|
int maxAnimationCount;
|
|
|
|
|
bool expanded;
|
2014-01-10 16:43:43 +01:00
|
|
|
bool seenForeignPaintEvent;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
PaintEventsModelProxy *q;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
PaintEventsModelProxy::PaintEventsModelProxy(QObject *parent)
|
2014-02-14 13:28:04 +01:00
|
|
|
: AbstractTimelineModel(QLatin1String("PaintEventsModelProxy"), parent),
|
|
|
|
|
d(new PaintEventsModelProxyPrivate(this))
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PaintEventsModelProxy::~PaintEventsModelProxy()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaintEventsModelProxy::clear()
|
|
|
|
|
{
|
2013-12-04 16:48:00 +01:00
|
|
|
d->SortedTimelineModel::clear();
|
2013-08-08 13:28:08 +02:00
|
|
|
d->minAnimationCount = 1;
|
|
|
|
|
d->maxAnimationCount = 1;
|
|
|
|
|
d->expanded = false;
|
2014-01-10 16:43:43 +01:00
|
|
|
d->seenForeignPaintEvent = false;
|
2013-08-08 13:28:08 +02:00
|
|
|
m_modelManager->modelProxyCountUpdated(m_modelId, 0, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PaintEventsModelProxy::eventAccepted(const QmlProfilerSimpleModel::QmlEventData &event) const
|
|
|
|
|
{
|
|
|
|
|
return (event.eventType == QmlDebug::Painting && event.bindingType == QmlDebug::AnimationFrame);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaintEventsModelProxy::loadData()
|
|
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
QmlProfilerSimpleModel *simpleModel = m_modelManager->simpleModel();
|
|
|
|
|
if (simpleModel->isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// collect events
|
|
|
|
|
const QVector<QmlProfilerSimpleModel::QmlEventData> referenceList = simpleModel->getEvents();
|
2013-12-04 16:48:00 +01:00
|
|
|
|
|
|
|
|
QmlPaintEventData lastEvent;
|
2014-01-13 11:18:10 +01:00
|
|
|
qint64 minNextStartTime = 0;
|
2013-12-04 16:48:00 +01:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
foreach (const QmlProfilerSimpleModel::QmlEventData &event, referenceList) {
|
2014-01-10 16:43:43 +01:00
|
|
|
if (!eventAccepted(event)) {
|
|
|
|
|
if (event.eventType == QmlDebug::Painting)
|
|
|
|
|
d->seenForeignPaintEvent = true;
|
2013-08-08 13:28:08 +02:00
|
|
|
continue;
|
2014-01-10 16:43:43 +01:00
|
|
|
}
|
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
|
|
|
|
|
qint64 realStartTime = qMax(event.startTime - estimatedDuration, minNextStartTime);
|
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-01-13 11:18:10 +01:00
|
|
|
d->insert(realStartTime, realEndTime - realStartTime, lastEvent);
|
|
|
|
|
|
|
|
|
|
minNextStartTime = event.startTime + 1;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2013-12-04 16:48:00 +01:00
|
|
|
m_modelManager->modelProxyCountUpdated(m_modelId, d->count(), referenceList.count());
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2013-12-04 16:48:00 +01:00
|
|
|
d->computeAnimationCountLimit();
|
|
|
|
|
d->computeNesting();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
m_modelManager->modelProxyCountUpdated(m_modelId, 1, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////// QML interface
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::count() const
|
|
|
|
|
{
|
2013-12-04 16:48:00 +01:00
|
|
|
return d->count();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 PaintEventsModelProxy::lastTimeMark() const
|
|
|
|
|
{
|
2013-12-04 16:48:00 +01:00
|
|
|
return d->lastEndTime();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PaintEventsModelProxy::expanded(int ) const
|
|
|
|
|
{
|
|
|
|
|
return d->expanded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaintEventsModelProxy::setExpanded(int category, bool expanded)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(category);
|
|
|
|
|
d->expanded = expanded;
|
|
|
|
|
emit expandedChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::categoryDepth(int categoryIndex) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(categoryIndex);
|
|
|
|
|
if (isEmpty())
|
2014-01-10 16:43:43 +01:00
|
|
|
return d->seenForeignPaintEvent ? 0 : 1;
|
2013-08-08 13:28:08 +02:00
|
|
|
else
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::categoryCount() const
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString PaintEventsModelProxy::categoryLabel(int categoryIndex) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(categoryIndex);
|
|
|
|
|
return tr("Painting");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::findFirstIndex(qint64 startTime) const
|
|
|
|
|
{
|
2013-12-04 16:48:00 +01:00
|
|
|
return d->findFirstIndex(startTime);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::findFirstIndexNoParents(qint64 startTime) const
|
|
|
|
|
{
|
2013-12-04 16:48:00 +01:00
|
|
|
return d->findFirstIndexNoParents(startTime);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::findLastIndex(qint64 endTime) const
|
|
|
|
|
{
|
2013-12-04 16:48:00 +01:00
|
|
|
return d->findLastIndex(endTime);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::getEventType(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
return (int)QmlDebug::Painting;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::getEventCategory(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
// there is only one category, all events belong to it
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::getEventRow(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 PaintEventsModelProxy::getDuration(int index) const
|
|
|
|
|
{
|
2013-12-04 16:48:00 +01:00
|
|
|
return d->range(index).duration;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 PaintEventsModelProxy::getStartTime(int index) const
|
|
|
|
|
{
|
2013-12-04 16:48:00 +01:00
|
|
|
return d->range(index).start;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
qint64 PaintEventsModelProxy::getEndTime(int index) const
|
|
|
|
|
{
|
2013-12-04 16:48:00 +01:00
|
|
|
return d->range(index).start + d->range(index).duration;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::getEventId(int index) const
|
|
|
|
|
{
|
|
|
|
|
// there is only one event Id for all painting events
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QColor PaintEventsModelProxy::getColor(int index) const
|
|
|
|
|
{
|
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;
|
|
|
|
|
return QColor::fromHsl((fpsFraction*96)+10, 76, 166);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float PaintEventsModelProxy::getHeight(int index) const
|
|
|
|
|
{
|
|
|
|
|
float scale = d->maxAnimationCount - d->minAnimationCount;
|
|
|
|
|
float fraction = 1.0f;
|
|
|
|
|
if (scale > 1)
|
2013-12-04 16:48:00 +01:00
|
|
|
fraction = (float)(d->range(index).animationcount -
|
2013-08-08 13:28:08 +02:00
|
|
|
d->minAnimationCount) / scale;
|
|
|
|
|
|
|
|
|
|
return fraction * 0.85f + 0.15f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QVariantList PaintEventsModelProxy::getLabelsForCategory(int category) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(category);
|
|
|
|
|
QVariantList result;
|
|
|
|
|
|
|
|
|
|
if (!isEmpty()) {
|
|
|
|
|
QVariantMap element;
|
|
|
|
|
element.insert(QLatin1String("displayName"), QVariant(QLatin1String("Animations")));
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(QLatin1String("Animations")));
|
|
|
|
|
element.insert(QLatin1String("id"), QVariant(0));
|
|
|
|
|
result << element;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PaintEventsModelProxy::PaintEventsModelProxyPrivate::computeAnimationCountLimit()
|
|
|
|
|
{
|
|
|
|
|
minAnimationCount = 1;
|
|
|
|
|
maxAnimationCount = 1;
|
2013-12-04 16:48:00 +01:00
|
|
|
if (count() == 0)
|
2013-08-08 13:28:08 +02:00
|
|
|
return;
|
|
|
|
|
|
2013-12-04 16:48:00 +01:00
|
|
|
for (int i=0; i < count(); i++) {
|
|
|
|
|
if (range(i).animationcount < minAnimationCount)
|
|
|
|
|
minAnimationCount = range(i).animationcount;
|
|
|
|
|
else if (range(i).animationcount > maxAnimationCount)
|
|
|
|
|
maxAnimationCount = range(i).animationcount;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QVariantList PaintEventsModelProxy::getEventDetails(int index) const
|
|
|
|
|
{
|
|
|
|
|
QVariantList result;
|
|
|
|
|
// int eventId = getEventId(index);
|
|
|
|
|
|
|
|
|
|
static const char trContext[] = "RangeDetails";
|
|
|
|
|
{
|
|
|
|
|
QVariantMap valuePair;
|
|
|
|
|
valuePair.insert(QLatin1String("title"), QVariant(categoryLabel(0)));
|
|
|
|
|
result << valuePair;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// duration
|
|
|
|
|
{
|
|
|
|
|
QVariantMap valuePair;
|
2014-02-14 17:01:24 +01:00
|
|
|
valuePair.insert(QCoreApplication::translate(trContext, "Duration:"),
|
|
|
|
|
QVariant(QmlProfilerSimpleModel::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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QVariantMap PaintEventsModelProxy::getEventLocation(int /*index*/) const
|
|
|
|
|
{
|
|
|
|
|
QVariantMap map;
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::getEventIdForHash(const QString &/*eventHash*/) const
|
|
|
|
|
{
|
|
|
|
|
// paint events do not have an eventHash
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int PaintEventsModelProxy::getEventIdForLocation(const QString &/*filename*/, int /*line*/, int /*column*/) const
|
|
|
|
|
{
|
|
|
|
|
// paint events do not have a defined location
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|