2013-08-08 13:28:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** 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
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2013-08-08 13:28:08 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
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 <QUrl>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStack>
|
|
|
|
|
#include <QElapsedTimer>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
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
|
|
|
QmlProfilerStatisticsModelPrivate(QmlProfilerStatisticsModel *qq) : q(qq) {}
|
|
|
|
|
~QmlProfilerStatisticsModelPrivate() {}
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QHash<int, QmlProfilerStatisticsModel::QmlEventStats> data;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
QmlProfilerModelManager *modelManager;
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlProfilerStatisticsModel *q;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
int modelId;
|
|
|
|
|
|
2014-06-03 16:57:32 +02:00
|
|
|
QList<QmlDebug::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;
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlProfilerStatisticsModel::QmlProfilerStatisticsModel(QmlProfilerModelManager *modelManager,
|
|
|
|
|
QObject *parent) :
|
|
|
|
|
QObject(parent), d(new QmlProfilerStatisticsModelPrivate(this))
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
d->modelManager = modelManager;
|
2015-10-30 12:35:17 +01:00
|
|
|
connect(modelManager->qmlModel(), &QmlProfilerDataModel::changed,
|
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();
|
|
|
|
|
|
2014-02-12 17:50:55 +01:00
|
|
|
// We're iterating twice in loadData.
|
|
|
|
|
modelManager->setProxyCountWeight(d->modelId, 2);
|
|
|
|
|
|
2014-02-07 17:57:40 +01:00
|
|
|
d->acceptedTypes << QmlDebug::Compiling << QmlDebug::Creating << QmlDebug::Binding << QmlDebug::HandlingSignal << QmlDebug::Javascript;
|
2014-09-09 18:22:58 +02:00
|
|
|
|
|
|
|
|
modelManager->announceFeatures(d->modelId, QmlDebug::Constants::QML_JS_RANGE_FEATURES);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsModel::setEventTypeAccepted(QmlDebug::RangeType type, bool accepted)
|
2014-03-06 16:12:02 +01:00
|
|
|
{
|
|
|
|
|
if (accepted && !d->acceptedTypes.contains(type))
|
|
|
|
|
d->acceptedTypes << type;
|
|
|
|
|
else if (!accepted && d->acceptedTypes.contains(type))
|
|
|
|
|
d->acceptedTypes.removeOne(type);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
bool QmlProfilerStatisticsModel::eventTypeAccepted(QmlDebug::RangeType type) const
|
2014-03-06 16:12:02 +01:00
|
|
|
{
|
|
|
|
|
return d->acceptedTypes.contains(type);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &QmlProfilerStatisticsModel::getTypes() const
|
2014-06-13 16:34:30 +02:00
|
|
|
{
|
|
|
|
|
return d->modelManager->qmlModel()->getEventTypes();
|
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->modelManager->modelProxyCountUpdated(d->modelId, 0, 1);
|
|
|
|
|
d->data.clear();
|
|
|
|
|
d->eventsInBindingLoop.clear();
|
2014-09-26 18:25:39 +02:00
|
|
|
d->notes.clear();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsModel::limitToRange(qint64 rangeStart, qint64 rangeEnd)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2015-09-09 14:48:01 +02:00
|
|
|
if (!d->modelManager->isEmpty())
|
|
|
|
|
loadData(rangeStart, rangeEnd);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsModel::dataChanged()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2015-09-10 13:51:54 +02:00
|
|
|
if (d->modelManager->state() == QmlProfilerModelManager::ProcessingData)
|
2013-12-03 14:57:50 +01:00
|
|
|
loadData();
|
2015-09-10 13:51:54 +02:00
|
|
|
else 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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
const QSet<int> &QmlProfilerStatisticsModel::eventsInBindingLoop() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
return d->eventsInBindingLoop;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsModel::loadData(qint64 rangeStart, qint64 rangeEnd)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
clear();
|
|
|
|
|
|
|
|
|
|
qint64 qmlTime = 0;
|
|
|
|
|
qint64 lastEndTime = 0;
|
2014-06-13 16:34:30 +02:00
|
|
|
QHash <int, QVector<qint64> > durations;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
const bool checkRanges = (rangeStart != -1) && (rangeEnd != -1);
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventData> &eventList
|
2014-02-18 17:32:20 +01:00
|
|
|
= d->modelManager->qmlModel()->getEvents();
|
2014-06-13 16:34:30 +02:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &typesList
|
|
|
|
|
= d->modelManager->qmlModel()->getEventTypes();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// used by binding loop detection
|
2014-06-13 16:34:30 +02:00
|
|
|
QStack<const QmlProfilerDataModel::QmlEventData*> callStack;
|
|
|
|
|
callStack.push(0); // artificial root
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
for (int i = 0; i < eventList.size(); ++i) {
|
2014-02-18 17:32:20 +01:00
|
|
|
const QmlProfilerDataModel::QmlEventData *event = &eventList[i];
|
2015-11-13 15:31:32 +01:00
|
|
|
const QmlProfilerDataModel::QmlEventTypeData *type = &typesList[event->typeIndex()];
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
if (!d->acceptedTypes.contains(type->rangeType))
|
2013-08-08 13:28:08 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (checkRanges) {
|
2015-11-13 15:31:32 +01:00
|
|
|
if ((event->startTime() + event->duration() < rangeStart)
|
|
|
|
|
|| (event->startTime() > rangeEnd))
|
2013-08-08 13:28:08 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
// update stats
|
2015-11-13 15:31:32 +01:00
|
|
|
QmlEventStats *stats = &d->data[event->typeIndex()];
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2015-11-13 15:31:32 +01:00
|
|
|
stats->duration += event->duration();
|
2015-12-03 12:33:00 +01:00
|
|
|
stats->durationSelf += event->duration();
|
2015-11-13 15:31:32 +01:00
|
|
|
if (event->duration() < stats->minTime)
|
|
|
|
|
stats->minTime = event->duration();
|
|
|
|
|
if (event->duration() > stats->maxTime)
|
|
|
|
|
stats->maxTime = event->duration();
|
2014-06-13 16:34:30 +02:00
|
|
|
stats->calls++;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
// for median computing
|
2015-11-13 15:31:32 +01:00
|
|
|
durations[event->typeIndex()].append(event->duration());
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// qml time computation
|
2015-11-13 15:31:32 +01:00
|
|
|
if (event->startTime() > lastEndTime) { // assume parent event if starts before last end
|
|
|
|
|
qmlTime += event->duration();
|
|
|
|
|
lastEndTime = event->startTime() + event->duration();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// binding loop detection
|
|
|
|
|
//
|
2014-06-13 16:34:30 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventData *potentialParent = callStack.top();
|
2015-11-13 15:31:32 +01:00
|
|
|
while (potentialParent && !(potentialParent->startTime() + potentialParent->duration() >
|
|
|
|
|
event->startTime())) {
|
2013-08-08 13:28:08 +02:00
|
|
|
callStack.pop();
|
2014-06-13 16:34:30 +02:00
|
|
|
potentialParent = callStack.top();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check whether event is already in stack
|
|
|
|
|
for (int ii = 1; ii < callStack.size(); ++ii) {
|
2015-11-13 15:31:32 +01:00
|
|
|
if (callStack.at(ii)->typeIndex() == event->typeIndex()) {
|
|
|
|
|
d->eventsInBindingLoop.insert(event->typeIndex());
|
2014-06-13 16:34:30 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-03 12:33:00 +01:00
|
|
|
if (callStack.count() > 1)
|
|
|
|
|
d->data[callStack.top()->typeIndex()].durationSelf -= event->duration();
|
2014-06-13 16:34:30 +02:00
|
|
|
callStack.push(event);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, i, eventList.count()*2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// post-process: calc mean time, median time, percentoftime
|
2014-02-12 17:50:55 +01:00
|
|
|
int i = d->data.size();
|
|
|
|
|
int total = i * 2;
|
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;
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
QVector<qint64> eventDurations = 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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stats->percentOfTime = stats->duration * 100.0 / qmlTime;
|
2015-12-03 12:33:00 +01:00
|
|
|
stats->percentSelf = stats->durationSelf * 100.0 / qmlTime;
|
2014-02-12 17:50:55 +01:00
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, i++, total);
|
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
|
|
|
|
|
= rootEvent.medianTime = 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);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, 1, 1);
|
|
|
|
|
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,
|
|
|
|
|
QObject *parent) : QObject(parent)
|
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);
|
|
|
|
|
m_statisticsModel = statisticsModel;
|
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.
|
2015-12-04 15:41:20 +01:00
|
|
|
connect(m_statisticsModel, &QmlProfilerStatisticsModel::dataAvailable,
|
|
|
|
|
this, &QmlProfilerStatisticsRelativesModel::dataChanged);
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &
|
|
|
|
|
QmlProfilerStatisticsRelativesModel::getTypes() const
|
2014-06-13 16:34:30 +02:00
|
|
|
{
|
|
|
|
|
return m_modelManager->qmlModel()->getEventTypes();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
int QmlProfilerStatisticsRelativesModel::count() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
return m_data.count();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsRelativesModel::clear()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
m_data.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsRelativesModel::dataChanged()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
loadData();
|
|
|
|
|
|
|
|
|
|
emit dataAvailable();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlProfilerStatisticsParentsModel::QmlProfilerStatisticsParentsModel(
|
|
|
|
|
QmlProfilerModelManager *modelManager, QmlProfilerStatisticsModel *statisticsModel,
|
|
|
|
|
QObject *parent) :
|
|
|
|
|
QmlProfilerStatisticsRelativesModel(modelManager, statisticsModel, parent)
|
2013-08-08 13:28:08 +02:00
|
|
|
{}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsParentsModel::loadData()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
clear();
|
2014-02-18 17:32:20 +01:00
|
|
|
QmlProfilerDataModel *simpleModel = m_modelManager->qmlModel();
|
2013-08-08 13:28:08 +02:00
|
|
|
if (simpleModel->isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// for level computation
|
|
|
|
|
QHash<int, qint64> endtimesPerLevel;
|
|
|
|
|
int level = QmlDebug::Constants::QML_MIN_LEVEL;
|
|
|
|
|
endtimesPerLevel[0] = 0;
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
const QSet<int> &eventsInBindingLoop = m_statisticsModel->eventsInBindingLoop();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// compute parent-child relationship and call count
|
2014-06-13 16:34:30 +02:00
|
|
|
QHash<int, int> lastParent;
|
2014-02-18 17:32:20 +01:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventData> eventList = simpleModel->getEvents();
|
2014-06-13 16:34:30 +02:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> typesList = simpleModel->getEventTypes();
|
2014-02-18 17:32:20 +01:00
|
|
|
foreach (const QmlProfilerDataModel::QmlEventData &event, eventList) {
|
2013-08-08 13:28:08 +02:00
|
|
|
// whitelist
|
2015-12-04 15:41:20 +01:00
|
|
|
if (!m_statisticsModel->eventTypeAccepted(typesList[event.typeIndex()].rangeType))
|
2013-08-08 13:28:08 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// level computation
|
2015-11-13 15:31:32 +01:00
|
|
|
if (endtimesPerLevel[level] > event.startTime()) {
|
2013-08-08 13:28:08 +02:00
|
|
|
level++;
|
|
|
|
|
} else {
|
2015-11-13 15:31:32 +01:00
|
|
|
while (level > QmlDebug::Constants::QML_MIN_LEVEL &&
|
|
|
|
|
endtimesPerLevel[level-1] <= event.startTime())
|
2013-08-08 13:28:08 +02:00
|
|
|
level--;
|
|
|
|
|
}
|
2015-11-13 15:31:32 +01:00
|
|
|
endtimesPerLevel[level] = event.startTime() + event.duration();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
int parentTypeIndex = -1;
|
2013-08-08 13:28:08 +02:00
|
|
|
if (level > QmlDebug::Constants::QML_MIN_LEVEL && lastParent.contains(level-1))
|
2014-06-13 16:34:30 +02:00
|
|
|
parentTypeIndex = lastParent[level-1];
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlStatisticsRelativesMap &relativesMap = m_data[event.typeIndex()];
|
|
|
|
|
QmlStatisticsRelativesMap::Iterator it = relativesMap.find(parentTypeIndex);
|
2014-06-13 16:34:30 +02:00
|
|
|
if (it != relativesMap.end()) {
|
|
|
|
|
it.value().calls++;
|
2015-11-13 15:31:32 +01:00
|
|
|
it.value().duration += event.duration();
|
2013-08-08 13:28:08 +02:00
|
|
|
} else {
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlStatisticsRelativesData parent = {
|
2015-11-13 15:31:32 +01:00
|
|
|
event.duration(),
|
2014-06-13 16:34:30 +02:00
|
|
|
1,
|
|
|
|
|
eventsInBindingLoop.contains(parentTypeIndex)
|
|
|
|
|
};
|
|
|
|
|
relativesMap.insert(parentTypeIndex, parent);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
// now lastparent is the new type
|
2015-11-13 15:31:32 +01:00
|
|
|
lastParent[level] = event.typeIndex();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlProfilerStatisticsChildrenModel::QmlProfilerStatisticsChildrenModel(
|
|
|
|
|
QmlProfilerModelManager *modelManager, QmlProfilerStatisticsModel *statisticsModel,
|
|
|
|
|
QObject *parent) :
|
|
|
|
|
QmlProfilerStatisticsRelativesModel(modelManager, statisticsModel, parent)
|
2013-08-08 13:28:08 +02:00
|
|
|
{}
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
void QmlProfilerStatisticsChildrenModel::loadData()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
clear();
|
2014-02-18 17:32:20 +01:00
|
|
|
QmlProfilerDataModel *simpleModel = m_modelManager->qmlModel();
|
2013-08-08 13:28:08 +02:00
|
|
|
if (simpleModel->isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// for level computation
|
|
|
|
|
QHash<int, qint64> endtimesPerLevel;
|
|
|
|
|
int level = QmlDebug::Constants::QML_MIN_LEVEL;
|
|
|
|
|
endtimesPerLevel[0] = 0;
|
|
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
const QSet<int> &eventsInBindingLoop = m_statisticsModel->eventsInBindingLoop();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// compute parent-child relationship and call count
|
2014-06-13 16:34:30 +02:00
|
|
|
QHash<int, int> lastParent;
|
|
|
|
|
const QVector<QmlProfilerDataModel::QmlEventData> &eventList = simpleModel->getEvents();
|
|
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &typesList = simpleModel->getEventTypes();
|
2014-02-18 17:32:20 +01:00
|
|
|
foreach (const QmlProfilerDataModel::QmlEventData &event, eventList) {
|
2013-08-08 13:28:08 +02:00
|
|
|
// whitelist
|
2015-12-04 15:41:20 +01:00
|
|
|
if (!m_statisticsModel->eventTypeAccepted(typesList[event.typeIndex()].rangeType))
|
2013-08-08 13:28:08 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// level computation
|
2015-11-13 15:31:32 +01:00
|
|
|
if (endtimesPerLevel[level] > event.startTime()) {
|
2013-08-08 13:28:08 +02:00
|
|
|
level++;
|
|
|
|
|
} else {
|
2015-11-13 15:31:32 +01:00
|
|
|
while (level > QmlDebug::Constants::QML_MIN_LEVEL &&
|
|
|
|
|
endtimesPerLevel[level-1] <= event.startTime())
|
2013-08-08 13:28:08 +02:00
|
|
|
level--;
|
|
|
|
|
}
|
2015-11-13 15:31:32 +01:00
|
|
|
endtimesPerLevel[level] = event.startTime() + event.duration();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
int parentId = -1;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
if (level > QmlDebug::Constants::QML_MIN_LEVEL && lastParent.contains(level-1))
|
2014-06-13 16:34:30 +02:00
|
|
|
parentId = lastParent[level-1];
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlStatisticsRelativesMap &relativesMap = m_data[parentId];
|
|
|
|
|
QmlStatisticsRelativesMap::Iterator it = relativesMap.find(event.typeIndex());
|
2014-06-13 16:34:30 +02:00
|
|
|
if (it != relativesMap.end()) {
|
|
|
|
|
it.value().calls++;
|
2015-11-13 15:31:32 +01:00
|
|
|
it.value().duration += event.duration();
|
2013-08-08 13:28:08 +02:00
|
|
|
} else {
|
2015-12-04 15:41:20 +01:00
|
|
|
QmlStatisticsRelativesData child = {
|
2015-11-13 15:31:32 +01:00
|
|
|
event.duration(),
|
2014-06-13 16:34:30 +02:00
|
|
|
1,
|
|
|
|
|
eventsInBindingLoop.contains(parentId)
|
|
|
|
|
};
|
2015-11-13 15:31:32 +01:00
|
|
|
relativesMap.insert(event.typeIndex(), child);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
// now lastparent is the new type
|
2015-11-13 15:31:32 +01:00
|
|
|
lastParent[level] = event.typeIndex();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|