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
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "qmlprofilermodelmanager.h"
|
2015-02-10 20:29:54 +01:00
|
|
|
#include "qmlprofilerconstants.h"
|
2013-08-08 13:28:08 +02:00
|
|
|
#include "qmlprofilertracefile.h"
|
2014-10-27 17:41:22 +01:00
|
|
|
#include "qmlprofilernotesmodel.h"
|
2016-12-29 15:02:06 +01:00
|
|
|
#include "qmlprofilerdetailsrewriter.h"
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2015-02-10 20:29:54 +01:00
|
|
|
#include <coreplugin/progressmanager/progressmanager.h>
|
|
|
|
#include <utils/runextensions.h>
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2016-12-29 15:02:06 +01:00
|
|
|
#include <utils/temporaryfile.h>
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QFile>
|
2014-11-03 14:19:26 +01:00
|
|
|
#include <QMessageBox>
|
2017-03-09 23:02:32 +01:00
|
|
|
#include <QRegExp>
|
2016-12-29 15:02:06 +01:00
|
|
|
#include <QStack>
|
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 {
|
|
|
|
namespace Internal {
|
|
|
|
|
2015-11-13 17:55:58 +01:00
|
|
|
static const char *ProfileFeatureNames[] = {
|
2014-09-09 18:22:58 +02:00
|
|
|
QT_TRANSLATE_NOOP("MainView", "JavaScript"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Memory Usage"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Pixmap Cache"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Scene Graph"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Animations"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Painting"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Compiling"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Creating"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Binding"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Handling Signal"),
|
2015-11-13 17:55:58 +01:00
|
|
|
QT_TRANSLATE_NOOP("MainView", "Input Events"),
|
|
|
|
QT_TRANSLATE_NOOP("MainView", "Debug Messages")
|
2014-09-09 18:22:58 +02:00
|
|
|
};
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
Q_STATIC_ASSERT(sizeof(ProfileFeatureNames) == sizeof(char *) * MaximumProfileFeature);
|
2015-11-13 17:55:58 +01:00
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
2014-06-03 15:35:54 +02:00
|
|
|
QmlProfilerTraceTime::QmlProfilerTraceTime(QObject *parent) :
|
2016-04-28 16:13:16 +02:00
|
|
|
QObject(parent), m_startTime(-1), m_endTime(-1),
|
|
|
|
m_restrictedStartTime(-1), m_restrictedEndTime(-1)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QmlProfilerTraceTime::startTime() const
|
|
|
|
{
|
2016-04-28 16:13:16 +02:00
|
|
|
return m_restrictedStartTime != -1 ? m_restrictedStartTime : m_startTime;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QmlProfilerTraceTime::endTime() const
|
|
|
|
{
|
2016-04-28 16:13:16 +02:00
|
|
|
return m_restrictedEndTime != -1 ? m_restrictedEndTime : m_endTime;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
qint64 QmlProfilerTraceTime::duration() const
|
|
|
|
{
|
|
|
|
return endTime() - startTime();
|
|
|
|
}
|
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
bool QmlProfilerTraceTime::isRestrictedToRange() const
|
|
|
|
{
|
|
|
|
return m_restrictedStartTime != -1 || m_restrictedEndTime != -1;
|
|
|
|
}
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void QmlProfilerTraceTime::clear()
|
|
|
|
{
|
2016-04-28 16:13:16 +02:00
|
|
|
restrictToRange(-1, -1);
|
2017-09-08 17:35:28 +02:00
|
|
|
m_startTime = -1;
|
|
|
|
m_endTime = -1;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 17:35:28 +02:00
|
|
|
void QmlProfilerTraceTime::update(qint64 time)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2017-09-08 17:35:28 +02:00
|
|
|
QTC_ASSERT(time >= 0, return);
|
|
|
|
if (m_startTime > time || m_startTime == -1)
|
|
|
|
m_startTime = time;
|
|
|
|
if (m_endTime < time || m_endTime == -1)
|
|
|
|
m_endTime = time;
|
|
|
|
QTC_ASSERT(m_endTime >= m_startTime, m_startTime = m_endTime);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2014-03-12 17:20:52 +01:00
|
|
|
void QmlProfilerTraceTime::decreaseStartTime(qint64 time)
|
|
|
|
{
|
2017-09-08 17:35:28 +02:00
|
|
|
QTC_ASSERT(time >= 0, return);
|
2015-11-13 17:54:08 +01:00
|
|
|
if (m_startTime > time || m_startTime == -1) {
|
2014-10-14 16:44:45 +02:00
|
|
|
m_startTime = time;
|
2015-11-13 17:54:08 +01:00
|
|
|
if (m_endTime == -1)
|
|
|
|
m_endTime = m_startTime;
|
|
|
|
else
|
|
|
|
QTC_ASSERT(m_endTime >= m_startTime, m_endTime = m_startTime);
|
2014-10-14 16:44:45 +02:00
|
|
|
}
|
2014-03-12 17:20:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerTraceTime::increaseEndTime(qint64 time)
|
|
|
|
{
|
2017-09-08 17:35:28 +02:00
|
|
|
QTC_ASSERT(time >= 0, return);
|
2015-11-13 17:54:08 +01:00
|
|
|
if (m_endTime < time || m_endTime == -1) {
|
2014-10-14 16:44:45 +02:00
|
|
|
m_endTime = time;
|
2015-11-13 17:54:08 +01:00
|
|
|
if (m_startTime == -1)
|
|
|
|
m_startTime = m_endTime;
|
|
|
|
else
|
|
|
|
QTC_ASSERT(m_endTime >= m_startTime, m_startTime = m_endTime);
|
2014-10-14 16:44:45 +02:00
|
|
|
}
|
2014-03-12 17:20:52 +01:00
|
|
|
}
|
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
void QmlProfilerTraceTime::restrictToRange(qint64 startTime, qint64 endTime)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(endTime == -1 || startTime <= endTime, endTime = startTime);
|
|
|
|
m_restrictedStartTime = startTime;
|
|
|
|
m_restrictedEndTime = endTime;
|
|
|
|
}
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class QmlProfilerModelManager::QmlProfilerModelManagerPrivate
|
|
|
|
{
|
|
|
|
public:
|
2016-12-29 15:02:06 +01:00
|
|
|
QmlProfilerModelManagerPrivate() : file("qmlprofiler-data") {}
|
|
|
|
|
2017-02-28 12:35:29 +01:00
|
|
|
QmlProfilerNotesModel *notesModel = nullptr;
|
|
|
|
QmlProfilerTextMarkModel *textMarkModel = nullptr;
|
2014-09-26 15:49:49 +02:00
|
|
|
|
2017-02-28 12:35:29 +01:00
|
|
|
QmlProfilerModelManager::State state = Empty;
|
|
|
|
QmlProfilerTraceTime *traceTime = nullptr;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2017-02-28 12:35:29 +01:00
|
|
|
int numRegisteredModels = 0;
|
|
|
|
int numFinishedFinalizers = 0;
|
2016-05-11 14:43:26 +02:00
|
|
|
|
2017-02-28 12:35:29 +01:00
|
|
|
uint numLoadedEvents = 0;
|
|
|
|
quint64 availableFeatures = 0;
|
|
|
|
quint64 visibleFeatures = 0;
|
|
|
|
quint64 recordedFeatures = 0;
|
|
|
|
bool aggregateTraces = false;
|
2016-04-28 16:19:17 +02:00
|
|
|
|
|
|
|
QHash<ProfileFeature, QVector<EventLoader> > eventLoaders;
|
|
|
|
QVector<Finalizer> finalizers;
|
2016-12-28 16:39:57 +01:00
|
|
|
|
2016-12-29 15:02:06 +01:00
|
|
|
QVector<QmlEventType> eventTypes;
|
2017-02-28 12:35:29 +01:00
|
|
|
QmlProfilerDetailsRewriter *detailsRewriter = nullptr;
|
2016-12-29 15:02:06 +01:00
|
|
|
|
|
|
|
Utils::TemporaryFile file;
|
|
|
|
QDataStream eventStream;
|
|
|
|
|
2016-12-28 16:39:57 +01:00
|
|
|
void dispatch(const QmlEvent &event, const QmlEventType &type);
|
2016-12-29 15:02:06 +01:00
|
|
|
void rewriteType(int typeIndex);
|
|
|
|
int resolveStackTop();
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-12-28 16:45:43 +01:00
|
|
|
QmlProfilerModelManager::QmlProfilerModelManager(QObject *parent) :
|
2016-04-28 16:02:54 +02:00
|
|
|
QObject(parent), d(new QmlProfilerModelManagerPrivate)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
d->traceTime = new QmlProfilerTraceTime(this);
|
2014-10-27 17:41:22 +01:00
|
|
|
d->notesModel = new QmlProfilerNotesModel(this);
|
2016-12-19 18:47:06 +01:00
|
|
|
d->textMarkModel = new QmlProfilerTextMarkModel(this);
|
2016-12-29 15:02:06 +01:00
|
|
|
|
|
|
|
d->detailsRewriter = new QmlProfilerDetailsRewriter(this);
|
|
|
|
connect(d->detailsRewriter, &QmlProfilerDetailsRewriter::rewriteDetailsString,
|
|
|
|
this, &QmlProfilerModelManager::detailsChanged);
|
|
|
|
connect(d->detailsRewriter, &QmlProfilerDetailsRewriter::eventDetailsChanged,
|
2016-04-28 16:13:16 +02:00
|
|
|
this, &QmlProfilerModelManager::processingDone);
|
2016-12-29 15:02:06 +01:00
|
|
|
|
|
|
|
if (d->file.open())
|
|
|
|
d->eventStream.setDevice(&d->file);
|
|
|
|
else
|
|
|
|
emit error(tr("Cannot open temporary trace file to store events."));
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerModelManager::~QmlProfilerModelManager()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerTraceTime *QmlProfilerModelManager::traceTime() const
|
|
|
|
{
|
|
|
|
return d->traceTime;
|
|
|
|
}
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QmlProfilerNotesModel *QmlProfilerModelManager::notesModel() const
|
2014-09-26 15:49:49 +02:00
|
|
|
{
|
|
|
|
return d->notesModel;
|
|
|
|
}
|
|
|
|
|
2016-12-19 18:47:06 +01:00
|
|
|
QmlProfilerTextMarkModel *QmlProfilerModelManager::textMarkModel() const
|
|
|
|
{
|
|
|
|
return d->textMarkModel;
|
|
|
|
}
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
bool QmlProfilerModelManager::isEmpty() const
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
return d->file.pos() == 0;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 14:43:26 +02:00
|
|
|
uint QmlProfilerModelManager::numLoadedEvents() const
|
|
|
|
{
|
|
|
|
return d->numLoadedEvents;
|
|
|
|
}
|
|
|
|
|
2016-12-28 16:39:57 +01:00
|
|
|
uint QmlProfilerModelManager::numLoadedEventTypes() const
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
return d->eventTypes.count();
|
2016-12-28 16:39:57 +01:00
|
|
|
}
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
int QmlProfilerModelManager::registerModelProxy()
|
|
|
|
{
|
2016-05-11 13:58:20 +02:00
|
|
|
return d->numRegisteredModels++;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 14:43:26 +02:00
|
|
|
int QmlProfilerModelManager::numFinishedFinalizers() const
|
|
|
|
{
|
|
|
|
return d->numFinishedFinalizers;
|
|
|
|
}
|
|
|
|
|
|
|
|
int QmlProfilerModelManager::numRegisteredFinalizers() const
|
|
|
|
{
|
|
|
|
return d->finalizers.count();
|
|
|
|
}
|
|
|
|
|
2016-12-28 16:39:57 +01:00
|
|
|
void QmlProfilerModelManager::addEvents(const QVector<QmlEvent> &events)
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
for (const QmlEvent &event : events) {
|
|
|
|
d->eventStream << event;
|
2017-09-08 17:35:28 +02:00
|
|
|
d->traceTime->update(event.timestamp());
|
2016-12-29 15:02:06 +01:00
|
|
|
d->dispatch(event, d->eventTypes[event.typeIndex()]);
|
|
|
|
}
|
2016-12-28 16:39:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::addEvent(const QmlEvent &event)
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
d->eventStream << event;
|
2017-09-08 17:35:28 +02:00
|
|
|
d->traceTime->update(event.timestamp());
|
2017-05-29 13:14:16 +02:00
|
|
|
QTC_ASSERT(event.typeIndex() < d->eventTypes.size(),
|
|
|
|
d->eventTypes.resize(event.typeIndex() + 1));
|
2016-12-29 15:02:06 +01:00
|
|
|
d->dispatch(event, d->eventTypes.at(event.typeIndex()));
|
2016-12-28 16:39:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::addEventTypes(const QVector<QmlEventType> &types)
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
const int firstTypeId = d->eventTypes.length();;
|
|
|
|
d->eventTypes.append(types);
|
|
|
|
for (int typeId = firstTypeId, end = d->eventTypes.length(); typeId < end; ++typeId) {
|
|
|
|
d->rewriteType(typeId);
|
|
|
|
const QmlEventLocation &location = d->eventTypes[typeId].location();
|
2016-12-19 18:47:06 +01:00
|
|
|
if (location.isValid()) {
|
2016-12-29 15:02:06 +01:00
|
|
|
d->textMarkModel->addTextMarkId(typeId, QmlEventLocation(
|
|
|
|
findLocalFile(location.filename()), location.line(),
|
2016-12-19 18:47:06 +01:00
|
|
|
location.column()));
|
|
|
|
}
|
|
|
|
}
|
2016-12-28 16:39:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::addEventType(const QmlEventType &type)
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
const int typeId = d->eventTypes.count();
|
|
|
|
d->eventTypes.append(type);
|
|
|
|
d->rewriteType(typeId);
|
2016-12-19 18:47:06 +01:00
|
|
|
const QmlEventLocation &location = type.location();
|
|
|
|
if (location.isValid()) {
|
|
|
|
d->textMarkModel->addTextMarkId(
|
2016-12-29 15:02:06 +01:00
|
|
|
typeId, QmlEventLocation(findLocalFile(location.filename()),
|
2016-12-19 18:47:06 +01:00
|
|
|
location.line(), location.column()));
|
|
|
|
}
|
2016-12-28 16:39:57 +01:00
|
|
|
}
|
|
|
|
|
2016-12-29 14:26:29 +01:00
|
|
|
const QVector<QmlEventType> &QmlProfilerModelManager::eventTypes() const
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
return d->eventTypes;
|
2016-12-29 14:26:29 +01:00
|
|
|
}
|
|
|
|
|
2016-12-29 15:02:06 +01:00
|
|
|
static bool isStateful(const QmlEventType &type)
|
|
|
|
{
|
|
|
|
// Events of these types carry state that has to be taken into account when adding later events:
|
|
|
|
// PixmapCacheEvent: Total size of the cache and size of pixmap currently being loaded
|
|
|
|
// MemoryAllocation: Total size of the JS heap and the amount of it currently in use
|
|
|
|
const Message message = type.message();
|
|
|
|
return message == PixmapCacheEvent || message == MemoryAllocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProfilerModelManager::replayEvents(qint64 rangeStart, qint64 rangeEnd,
|
2016-12-29 14:26:29 +01:00
|
|
|
EventLoader loader) const
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
QStack<QmlEvent> stack;
|
|
|
|
QmlEvent event;
|
|
|
|
QFile file(d->file.fileName());
|
|
|
|
if (!file.open(QIODevice::ReadOnly))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QDataStream stream(&file);
|
|
|
|
bool crossedRangeStart = false;
|
|
|
|
while (!stream.atEnd()) {
|
|
|
|
stream >> event;
|
|
|
|
if (stream.status() == QDataStream::ReadPastEnd)
|
|
|
|
break;
|
|
|
|
|
|
|
|
const QmlEventType &type = d->eventTypes[event.typeIndex()];
|
|
|
|
if (rangeStart != -1 && rangeEnd != -1) {
|
|
|
|
// Double-check if rangeStart has been crossed. Some versions of Qt send dirty data.
|
|
|
|
if (event.timestamp() < rangeStart && !crossedRangeStart) {
|
|
|
|
if (type.rangeType() != MaximumRangeType) {
|
|
|
|
if (event.rangeStage() == RangeStart)
|
|
|
|
stack.push(event);
|
|
|
|
else if (event.rangeStage() == RangeEnd)
|
|
|
|
stack.pop();
|
|
|
|
continue;
|
|
|
|
} else if (isStateful(type)) {
|
|
|
|
event.setTimestamp(rangeStart);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!crossedRangeStart) {
|
|
|
|
foreach (QmlEvent stashed, stack) {
|
|
|
|
stashed.setTimestamp(rangeStart);
|
|
|
|
loader(stashed, d->eventTypes[stashed.typeIndex()]);
|
|
|
|
}
|
|
|
|
stack.clear();
|
|
|
|
crossedRangeStart = true;
|
|
|
|
}
|
|
|
|
if (event.timestamp() > rangeEnd) {
|
|
|
|
if (type.rangeType() != MaximumRangeType) {
|
|
|
|
if (event.rangeStage() == RangeEnd) {
|
|
|
|
if (stack.isEmpty()) {
|
|
|
|
QmlEvent endEvent(event);
|
|
|
|
endEvent.setTimestamp(rangeEnd);
|
|
|
|
loader(endEvent, d->eventTypes[event.typeIndex()]);
|
|
|
|
} else {
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
} else if (event.rangeStage() == RangeStart) {
|
|
|
|
stack.push(event);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} else if (isStateful(type)) {
|
|
|
|
event.setTimestamp(rangeEnd);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loader(event, type);
|
|
|
|
}
|
|
|
|
return true;
|
2016-12-29 14:26:29 +01:00
|
|
|
}
|
|
|
|
|
2016-12-28 16:39:57 +01:00
|
|
|
void QmlProfilerModelManager::QmlProfilerModelManagerPrivate::dispatch(const QmlEvent &event,
|
|
|
|
const QmlEventType &type)
|
2016-04-28 16:19:17 +02:00
|
|
|
{
|
2017-02-21 13:05:22 +01:00
|
|
|
for (const EventLoader &loader : eventLoaders.value(type.feature()))
|
2016-04-28 16:19:17 +02:00
|
|
|
loader(event, type);
|
2016-12-28 16:39:57 +01:00
|
|
|
++numLoadedEvents;
|
2016-04-28 16:19:17 +02:00
|
|
|
}
|
|
|
|
|
2016-12-29 15:02:06 +01:00
|
|
|
static QString getDisplayName(const QmlEventType &event)
|
|
|
|
{
|
|
|
|
if (event.location().filename().isEmpty()) {
|
|
|
|
return QmlProfilerModelManager::tr("<bytecode>");
|
|
|
|
} else {
|
|
|
|
const QString filePath = QUrl(event.location().filename()).path();
|
|
|
|
return filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1) + QLatin1Char(':') +
|
|
|
|
QString::number(event.location().line());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static QString getInitialDetails(const QmlEventType &event)
|
|
|
|
{
|
|
|
|
QString details = event.data();
|
|
|
|
// generate details string
|
|
|
|
if (!details.isEmpty()) {
|
|
|
|
details = details.replace(QLatin1Char('\n'),QLatin1Char(' ')).simplified();
|
|
|
|
if (details.isEmpty()) {
|
|
|
|
if (event.rangeType() == Javascript)
|
|
|
|
details = QmlProfilerModelManager::tr("anonymous function");
|
|
|
|
} else {
|
|
|
|
QRegExp rewrite(QLatin1String("\\(function \\$(\\w+)\\(\\) \\{ (return |)(.+) \\}\\)"));
|
|
|
|
bool match = rewrite.exactMatch(details);
|
|
|
|
if (match)
|
|
|
|
details = rewrite.cap(1) + QLatin1String(": ") + rewrite.cap(3);
|
|
|
|
if (details.startsWith(QLatin1String("file://")) ||
|
|
|
|
details.startsWith(QLatin1String("qrc:/")))
|
|
|
|
details = details.mid(details.lastIndexOf(QLatin1Char('/')) + 1);
|
|
|
|
}
|
|
|
|
} else if (event.rangeType() == Painting) {
|
|
|
|
// QtQuick1 animations always run in GUI thread.
|
|
|
|
details = QmlProfilerModelManager::tr("GUI Thread");
|
|
|
|
}
|
|
|
|
|
|
|
|
return details;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::QmlProfilerModelManagerPrivate::rewriteType(int typeIndex)
|
|
|
|
{
|
|
|
|
QmlEventType &type = eventTypes[typeIndex];
|
|
|
|
type.setDisplayName(getDisplayName(type));
|
|
|
|
type.setData(getInitialDetails(type));
|
|
|
|
|
|
|
|
const QmlEventLocation &location = type.location();
|
|
|
|
// There is no point in looking for invalid locations
|
|
|
|
if (!location.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Only bindings and signal handlers need rewriting
|
|
|
|
if (type.rangeType() == Binding || type.rangeType() == HandlingSignal)
|
|
|
|
detailsRewriter->requestDetailsForLocation(typeIndex, location);
|
|
|
|
}
|
|
|
|
|
2016-04-28 16:19:17 +02:00
|
|
|
void QmlProfilerModelManager::announceFeatures(quint64 features, EventLoader eventLoader,
|
|
|
|
Finalizer finalizer)
|
2014-09-09 18:22:58 +02:00
|
|
|
{
|
2015-06-30 15:55:33 +02:00
|
|
|
if ((features & d->availableFeatures) != features) {
|
|
|
|
d->availableFeatures |= features;
|
|
|
|
emit availableFeaturesChanged(d->availableFeatures);
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
2015-06-30 15:55:33 +02:00
|
|
|
if ((features & d->visibleFeatures) != features) {
|
|
|
|
d->visibleFeatures |= features;
|
|
|
|
emit visibleFeaturesChanged(d->visibleFeatures);
|
|
|
|
}
|
2016-04-28 16:19:17 +02:00
|
|
|
|
|
|
|
for (int feature = 0; feature != MaximumProfileFeature; ++feature) {
|
2016-05-26 09:27:15 +02:00
|
|
|
if (features & (1ULL << feature))
|
2016-04-28 16:19:17 +02:00
|
|
|
d->eventLoaders[static_cast<ProfileFeature>(feature)].append(eventLoader);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->finalizers.append(finalizer);
|
2015-06-30 15:55:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
quint64 QmlProfilerModelManager::availableFeatures() const
|
|
|
|
{
|
|
|
|
return d->availableFeatures;
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
|
|
|
|
2015-06-30 15:55:33 +02:00
|
|
|
quint64 QmlProfilerModelManager::visibleFeatures() const
|
2014-09-09 18:22:58 +02:00
|
|
|
{
|
2015-06-30 15:55:33 +02:00
|
|
|
return d->visibleFeatures;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::setVisibleFeatures(quint64 features)
|
|
|
|
{
|
|
|
|
if (d->visibleFeatures != features) {
|
|
|
|
d->visibleFeatures = features;
|
|
|
|
emit visibleFeaturesChanged(d->visibleFeatures);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
quint64 QmlProfilerModelManager::recordedFeatures() const
|
|
|
|
{
|
|
|
|
return d->recordedFeatures;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::setRecordedFeatures(quint64 features)
|
|
|
|
{
|
|
|
|
if (d->recordedFeatures != features) {
|
|
|
|
d->recordedFeatures = features;
|
|
|
|
emit recordedFeaturesChanged(d->recordedFeatures);
|
|
|
|
}
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-04 17:29:05 +02:00
|
|
|
bool QmlProfilerModelManager::aggregateTraces() const
|
|
|
|
{
|
|
|
|
return d->aggregateTraces;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::setAggregateTraces(bool aggregateTraces)
|
|
|
|
{
|
|
|
|
d->aggregateTraces = aggregateTraces;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-02 12:18:57 +02:00
|
|
|
const char *QmlProfilerModelManager::featureName(ProfileFeature feature)
|
2014-09-09 18:22:58 +02:00
|
|
|
{
|
|
|
|
return ProfileFeatureNames[feature];
|
|
|
|
}
|
|
|
|
|
2015-09-10 17:11:21 +02:00
|
|
|
void QmlProfilerModelManager::acquiringDone()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2015-09-10 17:11:21 +02:00
|
|
|
QTC_ASSERT(state() == AcquiringData, /**/);
|
|
|
|
setState(ProcessingData);
|
2016-12-29 15:02:06 +01:00
|
|
|
d->file.flush();
|
|
|
|
d->detailsRewriter->reloadDocuments();
|
2015-09-10 17:11:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::processingDone()
|
|
|
|
{
|
|
|
|
QTC_ASSERT(state() == ProcessingData, /**/);
|
2015-09-25 10:35:42 +02:00
|
|
|
// Load notes after the timeline models have been initialized ...
|
|
|
|
// which happens on stateChanged(Done).
|
2016-04-28 16:13:16 +02:00
|
|
|
|
2016-05-11 14:43:26 +02:00
|
|
|
foreach (const Finalizer &finalizer, d->finalizers) {
|
2016-04-28 16:13:16 +02:00
|
|
|
finalizer();
|
2016-05-11 14:43:26 +02:00
|
|
|
++d->numFinishedFinalizers;
|
|
|
|
}
|
2016-04-28 16:13:16 +02:00
|
|
|
|
|
|
|
setState(Done);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2016-12-29 14:26:29 +01:00
|
|
|
void QmlProfilerModelManager::populateFileFinder(const ProjectExplorer::RunConfiguration *runConfiguration)
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
d->detailsRewriter->populateFileFinder(runConfiguration);
|
2016-12-29 14:26:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString QmlProfilerModelManager::findLocalFile(const QString &remoteFile)
|
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
return d->detailsRewriter->getLocalFile(remoteFile);
|
2016-12-29 14:26:29 +01:00
|
|
|
}
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
void QmlProfilerModelManager::save(const QString &filename)
|
|
|
|
{
|
2015-02-10 20:29:54 +01:00
|
|
|
QFile *file = new QFile(filename);
|
|
|
|
if (!file->open(QIODevice::WriteOnly)) {
|
2013-08-08 13:28:08 +02:00
|
|
|
emit error(tr("Could not open %1 for writing.").arg(filename));
|
2015-02-10 20:29:54 +01:00
|
|
|
delete file;
|
|
|
|
emit saveFinished();
|
2013-08-08 13:28:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-06 11:34:15 +02:00
|
|
|
d->notesModel->saveData();
|
2015-02-10 20:29:54 +01:00
|
|
|
|
2016-02-08 16:51:48 +01:00
|
|
|
QmlProfilerFileWriter *writer = new QmlProfilerFileWriter(this);
|
|
|
|
writer->setTraceTime(traceTime()->startTime(), traceTime()->endTime(),
|
|
|
|
traceTime()->duration());
|
2016-12-29 14:26:29 +01:00
|
|
|
writer->setData(this);
|
2016-04-26 12:26:46 +02:00
|
|
|
writer->setNotes(d->notesModel->notes());
|
2016-02-08 16:51:48 +01:00
|
|
|
|
|
|
|
connect(writer, &QObject::destroyed, this, &QmlProfilerModelManager::saveFinished,
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
|
2017-02-20 18:55:45 +01:00
|
|
|
connect(writer, &QmlProfilerFileWriter::error, this, [this, file](const QString &message) {
|
|
|
|
file->close();
|
|
|
|
file->remove();
|
|
|
|
delete file;
|
|
|
|
emit error(message);
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
|
2017-09-07 17:05:47 +02:00
|
|
|
connect(writer, &QmlProfilerFileWriter::success, this, [file]() {
|
2017-02-20 18:55:45 +01:00
|
|
|
file->close();
|
|
|
|
delete file;
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
|
2017-09-07 17:05:47 +02:00
|
|
|
connect(writer, &QmlProfilerFileWriter::canceled, this, [file]() {
|
2017-02-20 18:55:45 +01:00
|
|
|
file->close();
|
|
|
|
file->remove();
|
|
|
|
delete file;
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
|
2016-02-08 16:26:19 +01:00
|
|
|
QFuture<void> result = Utils::runAsync([file, writer] (QFutureInterface<void> &future) {
|
2016-02-08 16:51:48 +01:00
|
|
|
writer->setFuture(&future);
|
2016-05-10 13:27:48 +02:00
|
|
|
if (file->fileName().endsWith(QLatin1String(Constants::QtdFileExtension)))
|
|
|
|
writer->saveQtd(file);
|
|
|
|
else
|
|
|
|
writer->saveQzt(file);
|
2016-10-26 10:47:21 +02:00
|
|
|
writer->deleteLater();
|
2015-02-10 20:29:54 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
Core::ProgressManager::addTask(result, tr("Saving Trace Data"), Constants::TASK_SAVE,
|
|
|
|
Core::ProgressManager::ShowInApplicationIcon);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::load(const QString &filename)
|
|
|
|
{
|
2016-05-10 13:27:48 +02:00
|
|
|
bool isQtd = filename.endsWith(QLatin1String(Constants::QtdFileExtension));
|
2015-09-10 11:49:17 +02:00
|
|
|
QFile *file = new QFile(filename, this);
|
2016-05-10 13:27:48 +02:00
|
|
|
if (!file->open(isQtd ? (QIODevice::ReadOnly | QIODevice::Text) : QIODevice::ReadOnly)) {
|
2015-09-10 11:49:17 +02:00
|
|
|
emit error(tr("Could not open %1 for reading.").arg(filename));
|
2015-02-17 14:25:24 +01:00
|
|
|
delete file;
|
|
|
|
emit loadFinished();
|
2013-08-08 13:28:08 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear();
|
2015-09-10 13:51:54 +02:00
|
|
|
setState(AcquiringData);
|
2016-02-08 16:51:48 +01:00
|
|
|
QmlProfilerFileReader *reader = new QmlProfilerFileReader(this);
|
|
|
|
|
2017-02-20 18:55:45 +01:00
|
|
|
connect(reader, &QObject::destroyed, this, &QmlProfilerModelManager::loadFinished,
|
|
|
|
Qt::QueuedConnection);
|
2016-02-08 16:51:48 +01:00
|
|
|
|
2016-05-10 13:27:48 +02:00
|
|
|
connect(reader, &QmlProfilerFileReader::typesLoaded,
|
2016-12-28 16:39:57 +01:00
|
|
|
this, &QmlProfilerModelManager::addEventTypes);
|
2016-05-10 13:27:48 +02:00
|
|
|
|
|
|
|
connect(reader, &QmlProfilerFileReader::notesLoaded,
|
|
|
|
d->notesModel, &QmlProfilerNotesModel::setNotes);
|
|
|
|
|
2016-11-08 17:26:39 +01:00
|
|
|
connect(reader, &QmlProfilerFileReader::qmlEventsLoaded,
|
2016-12-28 16:39:57 +01:00
|
|
|
this, &QmlProfilerModelManager::addEvents);
|
2016-05-10 13:27:48 +02:00
|
|
|
|
2016-02-08 16:51:48 +01:00
|
|
|
connect(reader, &QmlProfilerFileReader::success, this, [this, reader]() {
|
2017-09-08 17:35:28 +02:00
|
|
|
if (reader->traceStart() >= 0)
|
|
|
|
d->traceTime->decreaseStartTime(reader->traceStart());
|
|
|
|
if (reader->traceEnd() >= 0)
|
|
|
|
d->traceTime->increaseEndTime(reader->traceEnd());
|
2016-02-08 16:51:48 +01:00
|
|
|
setRecordedFeatures(reader->loadedFeatures());
|
|
|
|
delete reader;
|
|
|
|
acquiringDone();
|
|
|
|
}, Qt::QueuedConnection);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2017-02-20 18:55:45 +01:00
|
|
|
connect(reader, &QmlProfilerFileReader::error, this, [this, reader](const QString &message) {
|
|
|
|
clear();
|
|
|
|
delete reader;
|
|
|
|
emit error(message);
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
|
|
|
|
connect(reader, &QmlProfilerFileReader::canceled, this, [this, reader]() {
|
|
|
|
clear();
|
|
|
|
delete reader;
|
|
|
|
}, Qt::QueuedConnection);
|
|
|
|
|
2016-05-10 13:27:48 +02:00
|
|
|
QFuture<void> result = Utils::runAsync([isQtd, file, reader] (QFutureInterface<void> &future) {
|
2016-02-08 16:51:48 +01:00
|
|
|
reader->setFuture(&future);
|
2016-05-10 13:27:48 +02:00
|
|
|
if (isQtd)
|
|
|
|
reader->loadQtd(file);
|
|
|
|
else
|
|
|
|
reader->loadQzt(file);
|
2015-02-17 14:25:24 +01:00
|
|
|
file->close();
|
|
|
|
file->deleteLater();
|
|
|
|
});
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2015-02-17 14:25:24 +01:00
|
|
|
Core::ProgressManager::addTask(result, tr("Loading Trace Data"), Constants::TASK_LOAD);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2015-09-10 13:51:54 +02:00
|
|
|
void QmlProfilerModelManager::setState(QmlProfilerModelManager::State state)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2015-09-10 13:51:54 +02:00
|
|
|
// It's not an error, we are continuously calling "AcquiringData" for example
|
|
|
|
if (d->state == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case ClearingData:
|
|
|
|
QTC_ASSERT(d->state == Done || d->state == Empty || d->state == AcquiringData, /**/);
|
|
|
|
break;
|
|
|
|
case Empty:
|
|
|
|
// if it's not empty, complain but go on
|
|
|
|
QTC_ASSERT(isEmpty(), /**/);
|
|
|
|
break;
|
|
|
|
case AcquiringData:
|
|
|
|
// we're not supposed to receive new data while processing older data
|
|
|
|
QTC_ASSERT(d->state != ProcessingData, return);
|
|
|
|
break;
|
|
|
|
case ProcessingData:
|
|
|
|
QTC_ASSERT(d->state == AcquiringData, return);
|
|
|
|
break;
|
|
|
|
case Done:
|
|
|
|
QTC_ASSERT(d->state == ProcessingData || d->state == Empty, return);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
emit error(tr("Trying to set unknown state in events list."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->state = state;
|
|
|
|
emit stateChanged();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2016-12-29 15:02:06 +01:00
|
|
|
void QmlProfilerModelManager::detailsChanged(int typeId, const QString &newString)
|
|
|
|
{
|
|
|
|
QTC_ASSERT(typeId < d->eventTypes.count(), return);
|
|
|
|
d->eventTypes[typeId].setData(newString);
|
|
|
|
}
|
|
|
|
|
2015-09-10 13:51:54 +02:00
|
|
|
QmlProfilerModelManager::State QmlProfilerModelManager::state() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2015-09-10 13:51:54 +02:00
|
|
|
return d->state;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerModelManager::clear()
|
|
|
|
{
|
2015-09-10 13:51:54 +02:00
|
|
|
setState(ClearingData);
|
2016-05-11 14:43:26 +02:00
|
|
|
d->numLoadedEvents = 0;
|
|
|
|
d->numFinishedFinalizers = 0;
|
2016-12-29 15:02:06 +01:00
|
|
|
d->file.remove();
|
|
|
|
d->eventStream.unsetDevice();
|
|
|
|
if (d->file.open())
|
|
|
|
d->eventStream.setDevice(&d->file);
|
|
|
|
else
|
|
|
|
emit error(tr("Cannot open temporary trace file to store events."));
|
|
|
|
d->eventTypes.clear();
|
2017-08-14 14:39:17 +02:00
|
|
|
d->detailsRewriter->clear();
|
2013-08-08 13:28:08 +02:00
|
|
|
d->traceTime->clear();
|
2014-11-03 14:19:26 +01:00
|
|
|
d->notesModel->clear();
|
2015-06-30 15:55:33 +02:00
|
|
|
setVisibleFeatures(0);
|
|
|
|
setRecordedFeatures(0);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2015-09-10 13:51:54 +02:00
|
|
|
setState(Empty);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2016-04-28 16:13:16 +02:00
|
|
|
void QmlProfilerModelManager::restrictToRange(qint64 startTime, qint64 endTime)
|
|
|
|
{
|
2016-07-06 11:34:15 +02:00
|
|
|
d->notesModel->saveData();
|
2016-07-06 11:34:49 +02:00
|
|
|
const QVector<QmlNote> notes = d->notesModel->notes();
|
|
|
|
d->notesModel->clear();
|
|
|
|
|
2016-06-02 10:20:52 +02:00
|
|
|
setState(ClearingData);
|
2016-04-28 16:13:16 +02:00
|
|
|
setVisibleFeatures(0);
|
|
|
|
|
|
|
|
startAcquiring();
|
2016-12-29 15:02:06 +01:00
|
|
|
if (!replayEvents(startTime, endTime,
|
|
|
|
std::bind(&QmlProfilerModelManagerPrivate::dispatch, d, std::placeholders::_1,
|
|
|
|
std::placeholders::_2))) {
|
2017-02-20 19:19:50 +01:00
|
|
|
emit error(tr("Could not re-read events from temporary trace file. "
|
|
|
|
"The trace data is lost."));
|
|
|
|
clear();
|
|
|
|
} else {
|
|
|
|
d->notesModel->setNotes(notes);
|
|
|
|
d->traceTime->restrictToRange(startTime, endTime);
|
|
|
|
acquiringDone();
|
|
|
|
}
|
2016-04-28 16:13:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProfilerModelManager::isRestrictedToRange() const
|
|
|
|
{
|
|
|
|
return d->traceTime->isRestrictedToRange();
|
|
|
|
}
|
|
|
|
|
2016-04-28 16:02:54 +02:00
|
|
|
void QmlProfilerModelManager::startAcquiring()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2015-09-10 13:51:54 +02:00
|
|
|
setState(AcquiringData);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace QmlProfiler
|