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 "qmlprofilermodelmanager.h"
|
2014-02-18 17:32:20 +01:00
|
|
|
#include "qmlprofilerdatamodel.h"
|
2013-08-08 13:28:08 +02:00
|
|
|
#include "qv8profilerdatamodel.h"
|
|
|
|
#include "qmlprofilertracefile.h"
|
|
|
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
QmlProfilerDataState::QmlProfilerDataState(QmlProfilerModelManager *modelManager, QObject *parent)
|
|
|
|
: QObject(parent), m_state(Empty), m_modelManager(modelManager)
|
|
|
|
{
|
|
|
|
connect(this, SIGNAL(error(QString)), m_modelManager, SIGNAL(error(QString)));
|
|
|
|
connect(this, SIGNAL(stateChanged()), m_modelManager, SIGNAL(stateChanged()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerDataState::setState(QmlProfilerDataState::State state)
|
|
|
|
{
|
|
|
|
// It's not an error, we are continuously calling "AcquiringData" for example
|
|
|
|
if (m_state == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (state) {
|
2013-12-09 12:11:48 +01:00
|
|
|
case ClearingData:
|
2014-02-13 12:53:21 +01:00
|
|
|
QTC_ASSERT(m_state == Done || m_state == Empty || m_state == AcquiringData, /**/);
|
2013-12-09 12:11:48 +01:00
|
|
|
break;
|
2013-08-08 13:28:08 +02:00
|
|
|
case Empty:
|
|
|
|
// if it's not empty, complain but go on
|
|
|
|
QTC_ASSERT(m_modelManager->isEmpty(), /**/);
|
|
|
|
break;
|
|
|
|
case AcquiringData:
|
|
|
|
// we're not supposed to receive new data while processing older data
|
|
|
|
QTC_ASSERT(m_state != ProcessingData, return);
|
|
|
|
break;
|
|
|
|
case ProcessingData:
|
|
|
|
QTC_ASSERT(m_state == AcquiringData, return);
|
|
|
|
break;
|
|
|
|
case Done:
|
|
|
|
QTC_ASSERT(m_state == ProcessingData || m_state == Empty, return);
|
|
|
|
break;
|
|
|
|
default:
|
2013-10-09 17:11:00 +02:00
|
|
|
emit error(tr("Trying to set unknown state in events list."));
|
2013-08-08 13:28:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_state = state;
|
|
|
|
emit stateChanged();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
2014-06-03 15:35:54 +02:00
|
|
|
QmlProfilerTraceTime::QmlProfilerTraceTime(QObject *parent) :
|
|
|
|
QObject(parent), m_startTime(-1), m_endTime(-1)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerTraceTime::~QmlProfilerTraceTime()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QmlProfilerTraceTime::startTime() const
|
|
|
|
{
|
|
|
|
return m_startTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QmlProfilerTraceTime::endTime() const
|
|
|
|
{
|
|
|
|
return m_endTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QmlProfilerTraceTime::duration() const
|
|
|
|
{
|
|
|
|
return endTime() - startTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTraceTime::clear()
|
|
|
|
{
|
2014-03-28 16:06:07 +01:00
|
|
|
setStartTime(-1);
|
|
|
|
setEndTime(-1);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTraceTime::setStartTime(qint64 time)
|
|
|
|
{
|
2014-03-28 16:06:07 +01:00
|
|
|
if (time != m_startTime) {
|
|
|
|
m_startTime = time;
|
|
|
|
emit startTimeChanged(time);
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTraceTime::setEndTime(qint64 time)
|
|
|
|
{
|
2014-03-28 16:06:07 +01:00
|
|
|
if (time != m_endTime) {
|
|
|
|
m_endTime = time;
|
|
|
|
emit endTimeChanged(time);
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2014-03-12 17:20:52 +01:00
|
|
|
void QmlProfilerTraceTime::decreaseStartTime(qint64 time)
|
|
|
|
{
|
|
|
|
if (m_startTime > time)
|
|
|
|
setStartTime(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTraceTime::increaseEndTime(qint64 time)
|
|
|
|
{
|
|
|
|
if (m_endTime < time)
|
|
|
|
setEndTime(time);
|
|
|
|
}
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class QmlProfilerModelManager::QmlProfilerModelManagerPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QmlProfilerModelManagerPrivate(QmlProfilerModelManager *qq) : q(qq) {}
|
|
|
|
~QmlProfilerModelManagerPrivate() {}
|
|
|
|
QmlProfilerModelManager *q;
|
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
QmlProfilerDataModel *model;
|
2013-08-08 13:28:08 +02:00
|
|
|
QV8ProfilerDataModel *v8Model;
|
|
|
|
QmlProfilerDataState *dataState;
|
|
|
|
QmlProfilerTraceTime *traceTime;
|
|
|
|
|
|
|
|
QVector <double> partialCounts;
|
2014-02-12 17:50:55 +01:00
|
|
|
QVector <int> partialCountWeights;
|
|
|
|
int totalWeight;
|
2013-08-08 13:28:08 +02:00
|
|
|
double progress;
|
2014-02-12 18:13:10 +01:00
|
|
|
double previousProgress;
|
2013-08-08 13:28:08 +02:00
|
|
|
qint64 estimatedTime;
|
|
|
|
|
|
|
|
// file to load
|
|
|
|
QString fileName;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
QmlProfilerModelManager::QmlProfilerModelManager(Utils::FileInProjectFinder *finder, QObject *parent) :
|
|
|
|
QObject(parent), d(new QmlProfilerModelManagerPrivate(this))
|
|
|
|
{
|
2014-02-12 17:50:55 +01:00
|
|
|
d->totalWeight = 0;
|
2014-02-18 17:32:20 +01:00
|
|
|
d->model = new QmlProfilerDataModel(finder, this);
|
2014-02-18 12:47:23 +01:00
|
|
|
d->v8Model = new QV8ProfilerDataModel(finder, this);
|
2013-08-08 13:28:08 +02:00
|
|
|
d->dataState = new QmlProfilerDataState(this, this);
|
|
|
|
d->traceTime = new QmlProfilerTraceTime(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerModelManager::~QmlProfilerModelManager()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerTraceTime *QmlProfilerModelManager::traceTime() const
|
|
|
|
{
|
|
|
|
return d->traceTime;
|
|
|
|
}
|
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
QmlProfilerDataModel *QmlProfilerModelManager::qmlModel() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
return d->model;
|
|
|
|
}
|
|
|
|
|
|
|
|
QV8ProfilerDataModel *QmlProfilerModelManager::v8Model() const
|
|
|
|
{
|
|
|
|
return d->v8Model;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProfilerModelManager::isEmpty() const
|
|
|
|
{
|
|
|
|
return d->model->isEmpty() && d->v8Model->isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
int QmlProfilerModelManager::count() const
|
|
|
|
{
|
|
|
|
return d->model->count();
|
|
|
|
}
|
|
|
|
|
|
|
|
double QmlProfilerModelManager::progress() const
|
|
|
|
{
|
|
|
|
return d->progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
int QmlProfilerModelManager::registerModelProxy()
|
|
|
|
{
|
|
|
|
d->partialCounts << 0;
|
2014-02-12 17:50:55 +01:00
|
|
|
d->partialCountWeights << 1;
|
|
|
|
d->totalWeight++;
|
2013-08-08 13:28:08 +02:00
|
|
|
return d->partialCounts.count()-1;
|
|
|
|
}
|
|
|
|
|
2014-02-12 17:50:55 +01:00
|
|
|
void QmlProfilerModelManager::setProxyCountWeight(int proxyId, int weight)
|
|
|
|
{
|
|
|
|
d->totalWeight += weight - d->partialCountWeights[proxyId];
|
|
|
|
d->partialCountWeights[proxyId] = weight;
|
|
|
|
}
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void QmlProfilerModelManager::modelProxyCountUpdated(int proxyId, qint64 count, qint64 max)
|
|
|
|
{
|
2014-02-12 17:50:55 +01:00
|
|
|
d->progress -= d->partialCounts[proxyId] * d->partialCountWeights[proxyId] /
|
|
|
|
d->totalWeight;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
if (max <= 0)
|
|
|
|
d->partialCounts[proxyId] = 1;
|
|
|
|
else
|
|
|
|
d->partialCounts[proxyId] = (double)count / (double) max;
|
|
|
|
|
2014-02-12 17:50:55 +01:00
|
|
|
d->progress += d->partialCounts[proxyId] * d->partialCountWeights[proxyId] /
|
|
|
|
d->totalWeight;
|
2014-02-12 18:13:10 +01:00
|
|
|
|
|
|
|
if (d->progress - d->previousProgress > 0.01) {
|
|
|
|
d->previousProgress = d->progress;
|
|
|
|
emit progressChanged();
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QmlProfilerModelManager::estimatedProfilingTime() const
|
|
|
|
{
|
|
|
|
return d->estimatedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::newTimeEstimation(qint64 estimation)
|
|
|
|
{
|
|
|
|
d->estimatedTime = estimation;
|
|
|
|
}
|
|
|
|
|
2014-06-03 16:57:32 +02:00
|
|
|
void QmlProfilerModelManager::addQmlEvent(QmlDebug::Message message,
|
|
|
|
QmlDebug::RangeType rangeType,
|
|
|
|
int detailType,
|
2013-08-08 13:28:08 +02:00
|
|
|
qint64 startTime,
|
|
|
|
qint64 length,
|
2014-06-13 16:33:30 +02:00
|
|
|
const QString &data,
|
2013-08-08 13:28:08 +02:00
|
|
|
const QmlDebug::QmlEventLocation &location,
|
|
|
|
qint64 ndata1,
|
|
|
|
qint64 ndata2,
|
|
|
|
qint64 ndata3,
|
|
|
|
qint64 ndata4,
|
|
|
|
qint64 ndata5)
|
|
|
|
{
|
|
|
|
// If trace start time was not explicitly set, use the first event
|
|
|
|
if (d->traceTime->startTime() == -1)
|
|
|
|
d->traceTime->setStartTime(startTime);
|
|
|
|
|
|
|
|
QTC_ASSERT(state() == QmlProfilerDataState::AcquiringData, /**/);
|
2014-06-03 16:57:32 +02:00
|
|
|
d->model->addQmlEvent(message, rangeType, detailType, startTime, length, data, location,
|
|
|
|
ndata1, ndata2, ndata3, ndata4, ndata5);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::addV8Event(int depth, const QString &function, const QString &filename,
|
|
|
|
int lineNumber, double totalTime, double selfTime)
|
|
|
|
{
|
|
|
|
d->v8Model->addV8Event(depth, function, filename, lineNumber,totalTime, selfTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::complete()
|
|
|
|
{
|
2014-02-12 17:35:08 +01:00
|
|
|
switch (state()) {
|
|
|
|
case QmlProfilerDataState::ProcessingData:
|
|
|
|
setState(QmlProfilerDataState::Done);
|
|
|
|
emit dataAvailable();
|
|
|
|
break;
|
|
|
|
case QmlProfilerDataState::AcquiringData:
|
2013-08-08 13:28:08 +02:00
|
|
|
// If trace end time was not explicitly set, use the last event
|
|
|
|
if (d->traceTime->endTime() == 0)
|
|
|
|
d->traceTime->setEndTime(d->model->lastTimeMark());
|
|
|
|
setState(QmlProfilerDataState::ProcessingData);
|
|
|
|
d->model->complete();
|
|
|
|
d->v8Model->complete();
|
2014-02-12 17:35:08 +01:00
|
|
|
break;
|
|
|
|
case QmlProfilerDataState::Empty:
|
2013-08-08 13:28:08 +02:00
|
|
|
setState(QmlProfilerDataState::Done);
|
2014-02-12 17:35:08 +01:00
|
|
|
break;
|
|
|
|
case QmlProfilerDataState::Done:
|
|
|
|
break;
|
|
|
|
default:
|
2013-10-09 17:11:00 +02:00
|
|
|
emit error(tr("Unexpected complete signal in data model."));
|
2014-02-12 17:35:08 +01:00
|
|
|
break;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 17:35:08 +01:00
|
|
|
void QmlProfilerModelManager::modelProcessingDone()
|
|
|
|
{
|
|
|
|
Q_ASSERT(state() == QmlProfilerDataState::ProcessingData);
|
|
|
|
if (d->model->processingDone() && d->v8Model->processingDone())
|
|
|
|
complete();
|
|
|
|
}
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void QmlProfilerModelManager::save(const QString &filename)
|
|
|
|
{
|
|
|
|
QFile file(filename);
|
|
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
|
|
|
emit error(tr("Could not open %1 for writing.").arg(filename));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerFileWriter writer;
|
|
|
|
|
|
|
|
writer.setTraceTime(traceTime()->startTime(), traceTime()->endTime(), traceTime()->duration());
|
|
|
|
writer.setV8DataModel(d->v8Model);
|
2014-06-13 16:34:30 +02:00
|
|
|
writer.setQmlEvents(d->model->getEventTypes(), d->model->getEvents());
|
2013-08-08 13:28:08 +02:00
|
|
|
writer.save(&file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::load(const QString &filename)
|
|
|
|
{
|
|
|
|
d->fileName = filename;
|
|
|
|
load();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::setFilename(const QString &filename)
|
|
|
|
{
|
|
|
|
d->fileName = filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::load()
|
|
|
|
{
|
|
|
|
QString filename = d->fileName;
|
|
|
|
|
|
|
|
QFile file(filename);
|
|
|
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
emit error(tr("Could not open %1 for reading.").arg(filename));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// erase current
|
|
|
|
clear();
|
|
|
|
|
|
|
|
setState(QmlProfilerDataState::AcquiringData);
|
|
|
|
|
|
|
|
QmlProfilerFileReader reader;
|
|
|
|
connect(&reader, SIGNAL(error(QString)), this, SIGNAL(error(QString)));
|
|
|
|
connect(&reader, SIGNAL(traceStartTime(qint64)), traceTime(), SLOT(setStartTime(qint64)));
|
|
|
|
connect(&reader, SIGNAL(traceEndTime(qint64)), traceTime(), SLOT(setEndTime(qint64)));
|
|
|
|
reader.setV8DataModel(d->v8Model);
|
2014-08-12 13:39:22 +02:00
|
|
|
reader.setQmlDataModel(d->model);
|
2013-08-08 13:28:08 +02:00
|
|
|
reader.load(&file);
|
|
|
|
|
|
|
|
complete();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::setState(QmlProfilerDataState::State state)
|
|
|
|
{
|
|
|
|
d->dataState->setState(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerDataState::State QmlProfilerModelManager::state() const
|
|
|
|
{
|
|
|
|
return d->dataState->state();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::clear()
|
|
|
|
{
|
2013-12-09 12:11:48 +01:00
|
|
|
setState(QmlProfilerDataState::ClearingData);
|
2013-08-08 13:28:08 +02:00
|
|
|
for (int i = 0; i < d->partialCounts.count(); i++)
|
|
|
|
d->partialCounts[i] = 0;
|
|
|
|
d->progress = 0;
|
2014-02-12 18:13:10 +01:00
|
|
|
d->previousProgress = 0;
|
2013-08-08 13:28:08 +02:00
|
|
|
d->model->clear();
|
|
|
|
d->v8Model->clear();
|
|
|
|
d->traceTime->clear();
|
|
|
|
|
|
|
|
setState(QmlProfilerDataState::Empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::prepareForWriting()
|
|
|
|
{
|
|
|
|
setState(QmlProfilerDataState::AcquiringData);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace QmlProfiler
|