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
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
#include "qmlprofilerstatisticsmodel.h"
|
2013-08-08 13:28:08 +02:00
|
|
|
#include "qmlprofilermodelmanager.h"
|
2014-02-18 17:32:20 +01:00
|
|
|
#include "qmlprofilerdatamodel.h"
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStack>
|
2016-04-28 16:02:54 +02:00
|
|
|
#include <QSet>
|
2016-04-26 16:38:56 +02:00
|
|
|
#include <QPointer>
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
namespace QmlProfiler {
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
class QmlProfilerStatisticsModel::QmlProfilerStatisticsModelPrivate
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2015-12-04 15:41:20 +01:00
|
|
|
QHash<int, QmlProfilerStatisticsModel::QmlEventStats> data;
|
2016-04-28 16:13:16 +02:00
|
|
|
QHash<int, QmlProfilerStatisticsModel::QmlEventStats> workingSet;
|
|
|
|
|
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
QPointer<QmlProfilerStatisticsRelativesModel> childrenModel;
|
|
|
|
|
QPointer<QmlProfilerStatisticsRelativesModel> parentsModel;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
QmlProfilerModelManager *modelManager;
|
|
|
|
|
|
|
|
|
|
int modelId;
|
|
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
QList<RangeType> acceptedTypes;
|
2014-06-13 16:34:30 +02:00
|
|
|
QSet<int> eventsInBindingLoop;
|
2014-09-26 18:25:39 +02:00
|
|
|
QHash<int, QString> notes;
|
2016-04-26 16:38:56 +02:00
|
|
|
|
|
|
|
|
QStack<QmlEvent> callStack;
|
|
|
|
|
qint64 qmlTime = 0;
|
|
|
|
|
qint64 lastEndTime = 0;
|
|
|
|
|
QHash <int, QVector<qint64> > durations;
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlProfilerStatisticsModel::QmlProfilerStatisticsModel(QmlProfilerModelManager *modelManager,
|
|
|
|
|
QObject *parent) :
|
2016-04-27 09:50:24 +02:00
|
|
|
QObject(parent), d(new QmlProfilerStatisticsModelPrivate)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
d->modelManager = modelManager;
|
2016-04-26 16:38:56 +02:00
|
|
|
d->callStack.push(QmlEvent());
|
|
|
|
|
connect(modelManager, &QmlProfilerModelManager::stateChanged,
|
2015-12-04 15:41:20 +01:00
|
|
|
this, &QmlProfilerStatisticsModel::dataChanged);
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(modelManager->notesModel(), &Timeline::TimelineNotesModel::changed,
|
2015-12-04 15:41:20 +01:00
|
|
|
this, &QmlProfilerStatisticsModel::notesChanged);
|
2013-08-08 13:28:08 +02:00
|
|
|
d->modelId = modelManager->registerModelProxy();
|
|
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
d->acceptedTypes << Compiling << Creating << Binding << HandlingSignal << Javascript;
|
2014-09-09 18:22:58 +02:00
|
|
|
|
2016-04-28 16:19:17 +02:00
|
|
|
modelManager->announceFeatures(Constants::QML_JS_RANGE_FEATURES,
|
|
|
|
|
[this](const QmlEvent &event, const QmlEventType &type) {
|
|
|
|
|
loadEvent(event, type);
|
|
|
|
|
}, [this]() {
|
|
|
|
|
finalize();
|
|
|
|
|
});
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlProfilerStatisticsModel::~QmlProfilerStatisticsModel()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
void QmlProfilerStatisticsModel::restrictToFeatures(qint64 features)
|
2014-03-06 16:12:02 +01:00
|
|
|
{
|
2016-04-28 16:13:16 +02:00
|
|
|
bool didChange = false;
|
|
|
|
|
for (int i = 0; i < MaximumRangeType; ++i) {
|
|
|
|
|
RangeType type = static_cast<RangeType>(i);
|
|
|
|
|
quint64 featureFlag = 1ULL << featureFromRangeType(type);
|
|
|
|
|
if (Constants::QML_JS_RANGE_FEATURES & featureFlag) {
|
|
|
|
|
bool accepted = features & featureFlag;
|
|
|
|
|
if (accepted && !d->acceptedTypes.contains(type)) {
|
|
|
|
|
d->acceptedTypes << type;
|
|
|
|
|
didChange = true;
|
|
|
|
|
} else if (!accepted && d->acceptedTypes.contains(type)) {
|
|
|
|
|
d->acceptedTypes.removeOne(type);
|
|
|
|
|
didChange = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!didChange || d->modelManager->state() != QmlProfilerModelManager::Done)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
clear();
|
|
|
|
|
d->modelManager->qmlModel()->replayEvents(d->modelManager->traceTime()->startTime(),
|
|
|
|
|
d->modelManager->traceTime()->endTime(),
|
|
|
|
|
std::bind(&QmlProfilerStatisticsModel::loadEvent,
|
|
|
|
|
this, std::placeholders::_1,
|
|
|
|
|
std::placeholders::_2));
|
|
|
|
|
finalize();
|
|
|
|
|
notesChanged(-1); // Reload notes
|
2014-03-06 16:12:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
const QHash<int, QmlProfilerStatisticsModel::QmlEventStats> &QmlProfilerStatisticsModel::getData() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-06-13 16:34:30 +02:00
|
|
|
return d->data;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 11:50:59 +02:00
|
|
|
const QVector<QmlEventType> &QmlProfilerStatisticsModel::getTypes() const
|
2014-06-13 16:34:30 +02:00
|
|
|
{
|
2016-04-26 11:50:59 +02:00
|
|
|
return d->modelManager->qmlModel()->eventTypes();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
const QHash<int, QString> &QmlProfilerStatisticsModel::getNotes() const
|
2014-09-26 18:25:39 +02:00
|
|
|
{
|
|
|
|
|
return d->notes;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsModel::clear()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
d->data.clear();
|
|
|
|
|
d->eventsInBindingLoop.clear();
|
2014-09-26 18:25:39 +02:00
|
|
|
d->notes.clear();
|
2016-04-26 16:38:56 +02:00
|
|
|
d->callStack.clear();
|
|
|
|
|
d->callStack.push(QmlEvent());
|
|
|
|
|
d->qmlTime = 0;
|
|
|
|
|
d->lastEndTime = 0;
|
|
|
|
|
d->durations.clear();
|
|
|
|
|
if (!d->childrenModel.isNull())
|
|
|
|
|
d->childrenModel->clear();
|
|
|
|
|
if (!d->parentsModel.isNull())
|
|
|
|
|
d->parentsModel->clear();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
void QmlProfilerStatisticsModel::setRelativesModel(QmlProfilerStatisticsRelativesModel *relative,
|
|
|
|
|
QmlProfilerStatisticsRelation relation)
|
|
|
|
|
{
|
|
|
|
|
if (relation == QmlProfilerStatisticsParents)
|
|
|
|
|
d->parentsModel = relative;
|
|
|
|
|
else
|
|
|
|
|
d->childrenModel = relative;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
QmlProfilerModelManager *QmlProfilerStatisticsModel::modelManager() const
|
|
|
|
|
{
|
|
|
|
|
return d->modelManager;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsModel::dataChanged()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2016-04-28 16:13:16 +02:00
|
|
|
if (d->modelManager->state() == QmlProfilerModelManager::ClearingData)
|
2013-12-16 10:46:43 +01:00
|
|
|
clear();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsModel::notesChanged(int typeIndex)
|
2014-09-26 18:25:39 +02:00
|
|
|
{
|
2014-10-27 17:41:22 +01:00
|
|
|
const QmlProfilerNotesModel *notesModel = d->modelManager->notesModel();
|
2014-09-26 18:25:39 +02:00
|
|
|
if (typeIndex == -1) {
|
|
|
|
|
d->notes.clear();
|
|
|
|
|
for (int noteId = 0; noteId < notesModel->count(); ++noteId) {
|
|
|
|
|
int noteType = notesModel->typeId(noteId);
|
|
|
|
|
if (noteType != -1) {
|
|
|
|
|
QString ¬e = d->notes[noteType];
|
|
|
|
|
if (note.isEmpty()) {
|
|
|
|
|
note = notesModel->text(noteId);
|
|
|
|
|
} else {
|
|
|
|
|
note.append(QStringLiteral("\n")).append(notesModel->text(noteId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
d->notes.remove(typeIndex);
|
2015-04-01 11:19:32 +02:00
|
|
|
const QVariantList changedNotes = notesModel->byTypeId(typeIndex);
|
2014-09-26 18:25:39 +02:00
|
|
|
if (!changedNotes.isEmpty()) {
|
|
|
|
|
QStringList newNotes;
|
|
|
|
|
for (QVariantList::ConstIterator it = changedNotes.begin(); it != changedNotes.end();
|
|
|
|
|
++it) {
|
|
|
|
|
newNotes << notesModel->text(it->toInt());
|
|
|
|
|
}
|
|
|
|
|
d->notes[typeIndex] = newNotes.join(QStringLiteral("\n"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit notesAvailable(typeIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
void QmlProfilerStatisticsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
|
|
|
|
|
{
|
2016-06-06 19:51:55 +02:00
|
|
|
if (!d->acceptedTypes.contains(type.rangeType()))
|
2016-04-26 16:38:56 +02:00
|
|
|
return;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
switch (event.rangeStage()) {
|
|
|
|
|
case RangeStart:
|
|
|
|
|
// binding loop detection: check whether event is already in stack
|
|
|
|
|
for (int ii = 1; ii < d->callStack.size(); ++ii) {
|
|
|
|
|
if (d->callStack.at(ii).typeIndex() == event.typeIndex()
|
2016-06-06 19:51:55 +02:00
|
|
|
&& type.rangeType() != Javascript) {
|
2016-04-28 16:13:16 +02:00
|
|
|
d->eventsInBindingLoop.insert(event.typeIndex());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
d->callStack.push(event);
|
|
|
|
|
break;
|
|
|
|
|
case RangeEnd: {
|
|
|
|
|
// update stats
|
|
|
|
|
QmlEventStats *stats = &d->data[event.typeIndex()];
|
|
|
|
|
qint64 duration = event.timestamp() - d->callStack.top().timestamp();
|
|
|
|
|
stats->duration += duration;
|
|
|
|
|
stats->durationSelf += duration;
|
|
|
|
|
if (duration < stats->minTime)
|
|
|
|
|
stats->minTime = duration;
|
|
|
|
|
if (duration > stats->maxTime)
|
|
|
|
|
stats->maxTime = duration;
|
|
|
|
|
stats->calls++;
|
|
|
|
|
// for median computing
|
|
|
|
|
d->durations[event.typeIndex()].append(duration);
|
|
|
|
|
// qml time computation
|
|
|
|
|
if (event.timestamp() > d->lastEndTime) { // assume parent event if starts before last end
|
|
|
|
|
d->qmlTime += duration;
|
|
|
|
|
d->lastEndTime = event.timestamp();
|
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
d->callStack.pop();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
if (d->callStack.count() > 1)
|
|
|
|
|
d->data[d->callStack.top().typeIndex()].durationSelf -= duration;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
break;
|
2016-04-26 16:38:56 +02:00
|
|
|
}
|
2016-04-28 16:13:16 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2016-04-26 16:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!d->childrenModel.isNull())
|
|
|
|
|
d->childrenModel->loadEvent(event);
|
|
|
|
|
if (!d->parentsModel.isNull())
|
|
|
|
|
d->parentsModel->loadEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void QmlProfilerStatisticsModel::finalize()
|
|
|
|
|
{
|
2013-08-08 13:28:08 +02:00
|
|
|
// post-process: calc mean time, median time, percentoftime
|
2014-06-13 16:34:30 +02:00
|
|
|
for (QHash<int, QmlEventStats>::iterator it = d->data.begin(); it != d->data.end(); ++it) {
|
|
|
|
|
QmlEventStats* stats = &it.value();
|
2013-08-08 13:28:08 +02:00
|
|
|
if (stats->calls > 0)
|
|
|
|
|
stats->timePerCall = stats->duration / (double)stats->calls;
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
QVector<qint64> eventDurations = d->durations[it.key()];
|
2013-08-08 13:28:08 +02:00
|
|
|
if (!eventDurations.isEmpty()) {
|
2014-06-16 18:25:52 +04:00
|
|
|
Utils::sort(eventDurations);
|
2013-08-08 13:28:08 +02:00
|
|
|
stats->medianTime = eventDurations.at(eventDurations.count()/2);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
stats->percentOfTime = stats->duration * 100.0 / d->qmlTime;
|
|
|
|
|
stats->percentSelf = stats->durationSelf * 100.0 / d->qmlTime;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// set binding loop flag
|
2014-06-13 16:34:30 +02:00
|
|
|
foreach (int typeIndex, d->eventsInBindingLoop)
|
|
|
|
|
d->data[typeIndex].isBindingLoop = true;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// insert root event
|
2014-06-13 16:34:30 +02:00
|
|
|
QmlEventStats rootEvent;
|
|
|
|
|
rootEvent.duration = rootEvent.minTime = rootEvent.maxTime = rootEvent.timePerCall
|
2016-04-26 16:38:56 +02:00
|
|
|
= rootEvent.medianTime = d->qmlTime + 1;
|
2015-12-03 12:33:00 +01:00
|
|
|
rootEvent.durationSelf = 1;
|
2014-06-13 16:34:30 +02:00
|
|
|
rootEvent.calls = 1;
|
|
|
|
|
rootEvent.percentOfTime = 100.0;
|
2015-12-03 12:33:00 +01:00
|
|
|
rootEvent.percentSelf = 1.0 / rootEvent.duration;
|
2014-06-13 16:34:30 +02:00
|
|
|
|
|
|
|
|
d->data.insert(-1, rootEvent);
|
2016-04-28 16:13:16 +02:00
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
if (!d->childrenModel.isNull())
|
|
|
|
|
d->childrenModel->finalize(d->eventsInBindingLoop);
|
|
|
|
|
if (!d->parentsModel.isNull())
|
|
|
|
|
d->parentsModel->finalize(d->eventsInBindingLoop);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
emit dataAvailable();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
int QmlProfilerStatisticsModel::count() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
return d->data.count();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlProfilerStatisticsRelativesModel::QmlProfilerStatisticsRelativesModel(
|
|
|
|
|
QmlProfilerModelManager *modelManager, QmlProfilerStatisticsModel *statisticsModel,
|
2016-04-26 16:38:56 +02:00
|
|
|
QmlProfilerStatisticsRelation relation, QObject *parent) :
|
|
|
|
|
QObject(parent), m_relation(relation)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2016-04-28 16:13:16 +02:00
|
|
|
m_startTimesPerLevel[0] = 0;
|
2016-04-26 16:38:56 +02:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
QTC_CHECK(modelManager);
|
|
|
|
|
m_modelManager = modelManager;
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QTC_CHECK(statisticsModel);
|
2016-04-26 16:38:56 +02:00
|
|
|
statisticsModel->setRelativesModel(this, relation);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-03-06 16:12:02 +01:00
|
|
|
// Load the child models whenever the parent model is done to get the filtering for JS/QML
|
|
|
|
|
// right.
|
2016-04-26 16:38:56 +02:00
|
|
|
connect(statisticsModel, &QmlProfilerStatisticsModel::dataAvailable,
|
|
|
|
|
this, &QmlProfilerStatisticsRelativesModel::dataAvailable);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
const QmlProfilerStatisticsRelativesModel::QmlStatisticsRelativesMap &
|
|
|
|
|
QmlProfilerStatisticsRelativesModel::getData(int typeId) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2015-12-04 15:41:20 +01:00
|
|
|
QHash <int, QmlStatisticsRelativesMap>::ConstIterator it = m_data.find(typeId);
|
2014-06-13 16:34:30 +02:00
|
|
|
if (it != m_data.end()) {
|
|
|
|
|
return it.value();
|
|
|
|
|
} else {
|
2015-12-04 15:41:20 +01:00
|
|
|
static const QmlStatisticsRelativesMap emptyMap;
|
2014-06-13 16:34:30 +02:00
|
|
|
return emptyMap;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 11:50:59 +02:00
|
|
|
const QVector<QmlEventType> &QmlProfilerStatisticsRelativesModel::getTypes() const
|
2014-06-13 16:34:30 +02:00
|
|
|
{
|
2016-04-26 11:50:59 +02:00
|
|
|
return m_modelManager->qmlModel()->eventTypes();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
void QmlProfilerStatisticsRelativesModel::loadEvent(const QmlEvent &event)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2016-04-26 16:38:56 +02:00
|
|
|
// level computation
|
2016-04-28 16:13:16 +02:00
|
|
|
switch (event.rangeStage()) {
|
|
|
|
|
case RangeStart:
|
|
|
|
|
// now lastparent is the new type
|
|
|
|
|
++m_level;
|
|
|
|
|
m_typesPerLevel[m_level] = event.typeIndex();
|
|
|
|
|
m_startTimesPerLevel[m_level] = event.timestamp();
|
|
|
|
|
break;
|
|
|
|
|
case RangeEnd: {
|
|
|
|
|
int parentTypeIndex = -1;
|
|
|
|
|
if (m_level > Constants::QML_MIN_LEVEL && m_typesPerLevel.contains(m_level-1))
|
|
|
|
|
parentTypeIndex = m_typesPerLevel[m_level-1];
|
|
|
|
|
|
|
|
|
|
int relativeTypeIndex = (m_relation == QmlProfilerStatisticsParents) ? parentTypeIndex :
|
|
|
|
|
event.typeIndex();
|
|
|
|
|
int selfTypeIndex = (m_relation == QmlProfilerStatisticsParents) ? event.typeIndex() :
|
|
|
|
|
parentTypeIndex;
|
|
|
|
|
|
|
|
|
|
QmlStatisticsRelativesMap &relativesMap = m_data[selfTypeIndex];
|
|
|
|
|
QmlStatisticsRelativesMap::Iterator it = relativesMap.find(relativeTypeIndex);
|
|
|
|
|
if (it != relativesMap.end()) {
|
|
|
|
|
it.value().calls++;
|
|
|
|
|
it.value().duration += event.timestamp() - m_startTimesPerLevel[m_level];
|
|
|
|
|
} else {
|
|
|
|
|
QmlStatisticsRelativesData relative = {
|
|
|
|
|
event.timestamp() - m_startTimesPerLevel[m_level],
|
|
|
|
|
1,
|
|
|
|
|
false
|
|
|
|
|
};
|
|
|
|
|
relativesMap.insert(relativeTypeIndex, relative);
|
|
|
|
|
}
|
|
|
|
|
--m_level;
|
|
|
|
|
break;
|
2016-04-26 16:38:56 +02:00
|
|
|
}
|
2016-04-28 16:13:16 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2016-04-26 16:38:56 +02:00
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
void QmlProfilerStatisticsRelativesModel::finalize(const QSet<int> &eventsInBindingLoop)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2016-04-26 16:38:56 +02:00
|
|
|
for (auto map = m_data.begin(), mapEnd = m_data.end(); map != mapEnd; ++map) {
|
|
|
|
|
auto itemEnd = map->end();
|
|
|
|
|
foreach (int typeIndex, eventsInBindingLoop) {
|
|
|
|
|
auto item = map->find(typeIndex);
|
|
|
|
|
if (item != itemEnd)
|
|
|
|
|
item->isBindingLoop = true;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-24 15:50:31 +02:00
|
|
|
QmlProfilerStatisticsRelation QmlProfilerStatisticsRelativesModel::relation() const
|
|
|
|
|
{
|
|
|
|
|
return m_relation;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
int QmlProfilerStatisticsRelativesModel::count() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2016-04-26 16:38:56 +02:00
|
|
|
return m_data.count();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-26 16:38:56 +02:00
|
|
|
void QmlProfilerStatisticsRelativesModel::clear()
|
|
|
|
|
{
|
|
|
|
|
m_data.clear();
|
2016-04-28 16:13:16 +02:00
|
|
|
m_startTimesPerLevel.clear();
|
2016-04-26 16:38:56 +02:00
|
|
|
m_level = Constants::QML_MIN_LEVEL;
|
2016-04-28 16:13:16 +02:00
|
|
|
m_startTimesPerLevel[0] = 0;
|
|
|
|
|
m_typesPerLevel.clear();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2016-04-26 16:38:56 +02:00
|
|
|
|
|
|
|
|
} // namespace QmlProfiler
|