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>
|
2018-05-03 09:50:11 +02:00
|
|
|
#include <tracing/tracestashfile.h>
|
2015-02-10 20:29:54 +01:00
|
|
|
#include <utils/runextensions.h>
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
#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 {
|
|
|
|
|
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
|
|
|
|
2018-05-04 17:19:08 +02:00
|
|
|
class QmlProfilerEventTypeStorage : public Timeline::TraceEventTypeStorage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const Timeline::TraceEventType &get(int typeId) const override;
|
|
|
|
void set(int typeId, Timeline::TraceEventType &&type) override;
|
|
|
|
int append(Timeline::TraceEventType &&type) override;
|
|
|
|
int size() const override;
|
|
|
|
void clear() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<QmlEventType> m_types;
|
|
|
|
};
|
|
|
|
|
2018-05-07 13:26:05 +02:00
|
|
|
class QmlProfilerEventStorage : public Timeline::TraceEventStorage
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2018-05-07 13:26:05 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(QmlProfilerEventStorage)
|
2013-08-08 13:28:08 +02:00
|
|
|
public:
|
2018-05-07 13:26:05 +02:00
|
|
|
using ErrorHandler = std::function<void(const QString &)>;
|
|
|
|
|
|
|
|
QmlProfilerEventStorage(const ErrorHandler &errorHandler);
|
|
|
|
|
|
|
|
int append(Timeline::TraceEvent &&event) override;
|
|
|
|
int size() const override;
|
|
|
|
void clear() override;
|
|
|
|
bool replay(const std::function<bool(Timeline::TraceEvent &&)> &receiver) const override;
|
|
|
|
void finalize() override;
|
|
|
|
|
|
|
|
ErrorHandler errorHandler() const;
|
|
|
|
void setErrorHandler(const ErrorHandler &errorHandler);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Timeline::TraceStashFile<QmlEvent> m_file;
|
|
|
|
std::function<void(const QString &)> m_errorHandler;
|
|
|
|
int m_size = 0;
|
|
|
|
};
|
2016-12-29 15:02:06 +01:00
|
|
|
|
2018-05-07 13:26:05 +02:00
|
|
|
class QmlProfilerModelManager::QmlProfilerModelManagerPrivate
|
|
|
|
{
|
|
|
|
public:
|
2018-04-05 09:47:33 +02:00
|
|
|
Internal::QmlProfilerTextMarkModel *textMarkModel = nullptr;
|
|
|
|
Internal::QmlProfilerDetailsRewriter *detailsRewriter = nullptr;
|
2016-12-29 15:02:06 +01:00
|
|
|
|
2018-05-07 15:56:13 +02:00
|
|
|
bool isRestrictedToRange = false;
|
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
void addEventType(const QmlEventType &eventType);
|
|
|
|
void handleError(const QString &message);
|
2018-03-28 08:57:46 +02:00
|
|
|
|
2016-12-29 15:02:06 +01:00
|
|
|
int resolveStackTop();
|
2013-08-08 13:28:08 +02:00
|
|
|
};
|
|
|
|
|
2016-12-28 16:45:43 +01:00
|
|
|
QmlProfilerModelManager::QmlProfilerModelManager(QObject *parent) :
|
2018-05-07 13:26:05 +02:00
|
|
|
Timeline::TimelineTraceManager(
|
|
|
|
std::make_unique<QmlProfilerEventStorage>(
|
|
|
|
std::bind(&Timeline::TimelineTraceManager::error, this, std::placeholders::_1)),
|
|
|
|
std::make_unique<QmlProfilerEventTypeStorage>(), parent),
|
2018-05-04 17:19:08 +02:00
|
|
|
d(new QmlProfilerModelManagerPrivate)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2018-04-05 09:47:33 +02:00
|
|
|
setNotesModel(new QmlProfilerNotesModel(this));
|
|
|
|
d->textMarkModel = new Internal::QmlProfilerTextMarkModel(this);
|
2016-12-29 15:02:06 +01:00
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
d->detailsRewriter = new Internal::QmlProfilerDetailsRewriter(this);
|
|
|
|
connect(d->detailsRewriter, &Internal::QmlProfilerDetailsRewriter::rewriteDetailsString,
|
2018-05-30 13:32:29 +02:00
|
|
|
this, &QmlProfilerModelManager::setTypeDetails);
|
2018-04-05 09:47:33 +02:00
|
|
|
connect(d->detailsRewriter, &Internal::QmlProfilerDetailsRewriter::eventDetailsChanged,
|
2018-03-27 15:58:43 +02:00
|
|
|
this, &QmlProfilerModelManager::typeDetailsFinished);
|
2016-12-29 15:02:06 +01:00
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
quint64 allFeatures = 0;
|
|
|
|
for (quint8 i = 0; i <= MaximumProfileFeature; ++i)
|
|
|
|
allFeatures |= (1ull << i);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerModelManager::~QmlProfilerModelManager()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
Internal::QmlProfilerTextMarkModel *QmlProfilerModelManager::textMarkModel() const
|
2016-12-19 18:47:06 +01:00
|
|
|
{
|
|
|
|
return d->textMarkModel;
|
|
|
|
}
|
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
void QmlProfilerModelManager::registerFeatures(quint64 features, QmlEventLoader eventLoader,
|
|
|
|
Initializer initializer, Finalizer finalizer,
|
|
|
|
Clearer clearer)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2018-04-05 09:47:33 +02:00
|
|
|
const TraceEventLoader traceEventLoader = eventLoader ? [eventLoader](
|
|
|
|
const Timeline::TraceEvent &event, const Timeline::TraceEventType &type) {
|
|
|
|
return eventLoader(static_cast<const QmlEvent &>(event),
|
|
|
|
static_cast<const QmlEventType &>(type));
|
|
|
|
} : TraceEventLoader();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
Timeline::TimelineTraceManager::registerFeatures(features, traceEventLoader, initializer,
|
|
|
|
finalizer, clearer);
|
2016-05-11 14:43:26 +02:00
|
|
|
}
|
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
const QmlEventType &QmlProfilerModelManager::eventType(int typeId) const
|
2016-12-28 16:39:57 +01:00
|
|
|
{
|
2018-05-04 17:19:08 +02:00
|
|
|
return static_cast<const QmlEventType &>(TimelineTraceManager::eventType(typeId));
|
2016-12-28 16:39:57 +01:00
|
|
|
}
|
|
|
|
|
2018-05-07 17:08:12 +02:00
|
|
|
void QmlProfilerModelManager::replayEvents(TraceEventLoader loader, Initializer initializer,
|
2018-04-05 09:47:33 +02:00
|
|
|
Finalizer finalizer, ErrorHandler errorHandler,
|
|
|
|
QFutureInterface<void> &future) const
|
2016-12-29 14:26:29 +01:00
|
|
|
{
|
2018-05-07 17:08:12 +02:00
|
|
|
replayQmlEvents(static_cast<QmlEventLoader>(loader), initializer, finalizer, errorHandler,
|
|
|
|
future);
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-07 17:08:12 +02:00
|
|
|
void QmlProfilerModelManager::replayQmlEvents(QmlEventLoader loader,
|
|
|
|
Initializer initializer, Finalizer finalizer,
|
|
|
|
ErrorHandler errorHandler,
|
2018-04-19 13:10:49 +02:00
|
|
|
QFutureInterface<void> &future) const
|
2016-12-29 14:26:29 +01:00
|
|
|
{
|
2018-04-05 09:47:33 +02:00
|
|
|
if (initializer)
|
|
|
|
initializer();
|
2016-12-29 15:02:06 +01:00
|
|
|
|
2018-05-07 13:26:05 +02:00
|
|
|
const auto result = eventStorage()->replay([&](Timeline::TraceEvent &&event) {
|
2018-04-05 09:47:33 +02:00
|
|
|
if (future.isCanceled())
|
|
|
|
return false;
|
2016-12-29 15:02:06 +01:00
|
|
|
|
2018-05-07 13:26:05 +02:00
|
|
|
loader(static_cast<QmlEvent &&>(event), eventType(event.typeIndex()));
|
2018-04-05 09:47:33 +02:00
|
|
|
return true;
|
|
|
|
});
|
2016-12-29 14:26:29 +01:00
|
|
|
|
2018-05-07 13:26:05 +02:00
|
|
|
if (!result && errorHandler) {
|
|
|
|
errorHandler(future.isCanceled() ? QString()
|
|
|
|
: tr("Failed to replay QML events from stash file."));
|
|
|
|
} else if (result && finalizer) {
|
|
|
|
finalizer();
|
2018-03-27 17:39:17 +02:00
|
|
|
}
|
2016-04-28 16:19:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-29 18:04:07 +02:00
|
|
|
void QmlProfilerModelManager::initialize()
|
|
|
|
{
|
|
|
|
d->textMarkModel->hideTextMarks();
|
|
|
|
TimelineTraceManager::initialize();
|
|
|
|
}
|
|
|
|
|
2018-05-28 16:21:03 +02:00
|
|
|
void QmlProfilerModelManager::clearEventStorage()
|
|
|
|
{
|
|
|
|
TimelineTraceManager::clearEventStorage();
|
|
|
|
emit traceChanged();
|
|
|
|
}
|
|
|
|
|
2018-05-29 18:04:07 +02:00
|
|
|
void QmlProfilerModelManager::clearTypeStorage()
|
|
|
|
{
|
|
|
|
d->textMarkModel->clear();
|
|
|
|
TimelineTraceManager::clearTypeStorage();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return details;
|
|
|
|
}
|
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
void QmlProfilerModelManager::QmlProfilerModelManagerPrivate::handleError(const QString &message)
|
|
|
|
{
|
|
|
|
// What to do here?
|
|
|
|
qWarning() << message;
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2018-03-27 15:58:43 +02:00
|
|
|
void QmlProfilerModelManager::finalize()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2016-12-29 15:02:06 +01:00
|
|
|
d->detailsRewriter->reloadDocuments();
|
2015-09-10 17:11:21 +02:00
|
|
|
|
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
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
TimelineTraceManager::finalize();
|
2018-05-29 18:04:07 +02:00
|
|
|
d->textMarkModel->showTextMarks();
|
2018-05-28 16:21:03 +02:00
|
|
|
emit traceChanged();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2017-09-27 14:56:00 +02:00
|
|
|
void QmlProfilerModelManager::populateFileFinder(const ProjectExplorer::Target *target)
|
2016-12-29 14:26:29 +01:00
|
|
|
{
|
2017-09-27 14:56:00 +02:00
|
|
|
d->detailsRewriter->populateFileFinder(target);
|
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
|
|
|
}
|
|
|
|
|
2018-05-30 13:32:29 +02:00
|
|
|
void QmlProfilerModelManager::setTypeDetails(int typeId, const QString &details)
|
2016-12-29 15:02:06 +01:00
|
|
|
{
|
2018-05-04 17:19:08 +02:00
|
|
|
QTC_ASSERT(typeId < numEventTypes(), return);
|
|
|
|
QmlEventType type = eventType(typeId);
|
2018-05-30 13:32:29 +02:00
|
|
|
type.setData(details);
|
|
|
|
// Don't rewrite the details again, but directly push the type into the type storage.
|
|
|
|
Timeline::TimelineTraceManager::setEventType(typeId, std::move(type));
|
2018-03-27 15:58:43 +02:00
|
|
|
emit typeDetailsChanged(typeId);
|
2016-12-29 15:02:06 +01:00
|
|
|
}
|
|
|
|
|
2018-05-07 17:08:12 +02:00
|
|
|
void QmlProfilerModelManager::restrictByFilter(QmlProfilerModelManager::QmlEventFilter filter)
|
|
|
|
{
|
|
|
|
return Timeline::TimelineTraceManager::restrictByFilter([filter](TraceEventLoader loader) {
|
|
|
|
const auto filteredQmlLoader = filter([loader](const QmlEvent &event,
|
|
|
|
const QmlEventType &type) {
|
|
|
|
loader(event, type);
|
|
|
|
});
|
|
|
|
|
|
|
|
return [filteredQmlLoader](const Timeline::TraceEvent &event,
|
|
|
|
const Timeline::TraceEventType &type) {
|
|
|
|
filteredQmlLoader(static_cast<const QmlEvent &>(event),
|
|
|
|
static_cast<const QmlEventType &>(type));
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-04 17:19:08 +02:00
|
|
|
int QmlProfilerModelManager::appendEventType(QmlEventType &&type)
|
2018-01-03 13:40:48 +01:00
|
|
|
{
|
2018-05-04 17:19:08 +02:00
|
|
|
type.setDisplayName(getDisplayName(type));
|
|
|
|
type.setData(getInitialDetails(type));
|
|
|
|
|
|
|
|
const QmlEventLocation &location = type.location();
|
|
|
|
if (location.isValid()) {
|
|
|
|
const RangeType rangeType = type.rangeType();
|
|
|
|
const QmlEventLocation localLocation(d->detailsRewriter->getLocalFile(location.filename()),
|
|
|
|
location.line(), location.column());
|
|
|
|
|
|
|
|
// location and type are invalid after this
|
|
|
|
const int typeIndex = TimelineTraceManager::appendEventType(std::move(type));
|
|
|
|
|
|
|
|
// Only bindings and signal handlers need rewriting
|
|
|
|
if (rangeType == Binding || rangeType == HandlingSignal)
|
|
|
|
d->detailsRewriter->requestDetailsForLocation(typeIndex, location);
|
|
|
|
d->textMarkModel->addTextMarkId(typeIndex, localLocation);
|
|
|
|
return typeIndex;
|
|
|
|
} else {
|
|
|
|
// There is no point in looking for invalid locations; just add the type
|
|
|
|
return TimelineTraceManager::appendEventType(std::move(type));
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2018-05-04 17:19:08 +02:00
|
|
|
void QmlProfilerModelManager::setEventType(int typeIndex, QmlEventType &&type)
|
2016-04-28 16:13:16 +02:00
|
|
|
{
|
2018-05-04 17:19:08 +02:00
|
|
|
type.setDisplayName(getDisplayName(type));
|
|
|
|
type.setData(getInitialDetails(type));
|
|
|
|
|
|
|
|
const QmlEventLocation &location = type.location();
|
|
|
|
if (location.isValid()) {
|
|
|
|
// Only bindings and signal handlers need rewriting
|
|
|
|
if (type.rangeType() == Binding || type.rangeType() == HandlingSignal)
|
|
|
|
d->detailsRewriter->requestDetailsForLocation(typeIndex, location);
|
|
|
|
d->textMarkModel->addTextMarkId(typeIndex, QmlEventLocation(
|
|
|
|
d->detailsRewriter->getLocalFile(location.filename()),
|
|
|
|
location.line(), location.column()));
|
|
|
|
}
|
|
|
|
|
|
|
|
TimelineTraceManager::setEventType(typeIndex, std::move(type));
|
2016-04-28 16:13:16 +02:00
|
|
|
}
|
|
|
|
|
2018-05-04 17:19:08 +02:00
|
|
|
|
2018-05-07 13:26:05 +02:00
|
|
|
void QmlProfilerModelManager::appendEvent(QmlEvent &&event)
|
2016-04-28 16:13:16 +02:00
|
|
|
{
|
2018-05-07 13:26:05 +02:00
|
|
|
TimelineTraceManager::appendEvent(std::move(event));
|
2016-04-28 16:13:16 +02:00
|
|
|
}
|
|
|
|
|
2018-05-07 15:56:13 +02:00
|
|
|
void QmlProfilerModelManager::restrictToRange(qint64 start, qint64 end)
|
|
|
|
{
|
|
|
|
d->isRestrictedToRange = (start != -1 || end != -1);
|
2018-05-07 17:08:12 +02:00
|
|
|
restrictByFilter(rangeFilter(start, end));
|
2018-05-07 15:56:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProfilerModelManager::isRestrictedToRange() const
|
|
|
|
{
|
|
|
|
return d->isRestrictedToRange;
|
|
|
|
}
|
|
|
|
|
2018-05-07 17:08:12 +02:00
|
|
|
QmlProfilerModelManager::QmlEventFilter
|
|
|
|
QmlProfilerModelManager::rangeFilter(qint64 rangeStart, qint64 rangeEnd) const
|
|
|
|
{
|
|
|
|
return [rangeStart, rangeEnd, this] (QmlEventLoader loader) {
|
|
|
|
QStack<QmlEvent> stack;
|
|
|
|
bool crossedRangeStart = false;
|
|
|
|
|
|
|
|
return [=](const QmlEvent &event, const QmlEventType &type) mutable {
|
|
|
|
|
|
|
|
// No restrictions: load all events
|
|
|
|
if (rangeStart == -1 || rangeEnd == -1) {
|
|
|
|
loader(event, type);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Double-check if rangeStart has been crossed. Some versions of Qt send dirty data.
|
|
|
|
qint64 adjustedTimestamp = event.timestamp();
|
|
|
|
if (event.timestamp() < rangeStart && !crossedRangeStart) {
|
|
|
|
if (type.rangeType() != MaximumRangeType) {
|
|
|
|
if (event.rangeStage() == RangeStart)
|
|
|
|
stack.push(event);
|
|
|
|
else if (event.rangeStage() == RangeEnd)
|
|
|
|
stack.pop();
|
|
|
|
return true;
|
|
|
|
} else if (isStateful(type)) {
|
|
|
|
adjustedTimestamp = rangeStart;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!crossedRangeStart) {
|
|
|
|
for (auto stashed : stack) {
|
|
|
|
stashed.setTimestamp(rangeStart);
|
|
|
|
loader(stashed, eventType(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, type);
|
|
|
|
} else {
|
|
|
|
stack.pop();
|
|
|
|
}
|
|
|
|
} else if (event.rangeStage() == RangeStart) {
|
|
|
|
stack.push(event);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (isStateful(type)) {
|
|
|
|
adjustedTimestamp = rangeEnd;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (adjustedTimestamp != event.timestamp()) {
|
|
|
|
QmlEvent adjusted(event);
|
|
|
|
adjusted.setTimestamp(adjustedTimestamp);
|
|
|
|
loader(adjusted, type);
|
|
|
|
} else {
|
|
|
|
loader(event, type);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
Timeline::TimelineTraceFile *QmlProfilerModelManager::createTraceFile()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2018-04-05 09:47:33 +02:00
|
|
|
return new Internal::QmlProfilerTraceFile(this);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
2018-05-04 17:19:08 +02:00
|
|
|
const Timeline::TraceEventType &QmlProfilerEventTypeStorage::get(int typeId) const
|
|
|
|
{
|
|
|
|
Q_ASSERT(typeId >= 0);
|
|
|
|
return m_types.at(static_cast<size_t>(typeId));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerEventTypeStorage::set(int typeId, Timeline::TraceEventType &&type)
|
|
|
|
{
|
|
|
|
Q_ASSERT(typeId >= 0);
|
|
|
|
const size_t index = static_cast<size_t>(typeId);
|
|
|
|
if (m_types.size() <= index)
|
|
|
|
m_types.resize(index + 1);
|
|
|
|
m_types[index] = std::move(static_cast<QmlEventType &&>(type));
|
|
|
|
}
|
|
|
|
|
|
|
|
int QmlProfilerEventTypeStorage::append(Timeline::TraceEventType &&type)
|
|
|
|
{
|
|
|
|
const size_t index = m_types.size();
|
|
|
|
m_types.push_back(std::move(static_cast<QmlEventType &&>(type)));
|
|
|
|
QTC_ASSERT(index <= std::numeric_limits<int>::max(), return std::numeric_limits<int>::max());
|
|
|
|
return static_cast<int>(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
int QmlProfilerEventTypeStorage::size() const
|
|
|
|
{
|
|
|
|
const size_t size = m_types.size();
|
|
|
|
QTC_ASSERT(size <= std::numeric_limits<int>::max(), return std::numeric_limits<int>::max());
|
|
|
|
return static_cast<int>(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerEventTypeStorage::clear()
|
|
|
|
{
|
|
|
|
m_types.clear();
|
|
|
|
}
|
|
|
|
|
2018-05-07 13:26:05 +02:00
|
|
|
QmlProfilerEventStorage::QmlProfilerEventStorage(
|
|
|
|
const std::function<void (const QString &)> &errorHandler)
|
|
|
|
: m_file("qmlprofiler-data"), m_errorHandler(errorHandler)
|
|
|
|
{
|
|
|
|
if (!m_file.open())
|
|
|
|
errorHandler(tr("Cannot open temporary trace file to store events."));
|
|
|
|
}
|
|
|
|
|
|
|
|
int QmlProfilerEventStorage::append(Timeline::TraceEvent &&event)
|
|
|
|
{
|
|
|
|
m_file.append(std::move(static_cast<QmlEvent &&>(event)));
|
|
|
|
return m_size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int QmlProfilerEventStorage::size() const
|
|
|
|
{
|
|
|
|
return m_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerEventStorage::clear()
|
|
|
|
{
|
|
|
|
m_size = 0;
|
|
|
|
m_file.clear();
|
|
|
|
if (!m_file.open())
|
|
|
|
m_errorHandler(tr("Failed to reset temporary trace file"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerEventStorage::finalize()
|
|
|
|
{
|
|
|
|
if (!m_file.flush())
|
|
|
|
m_errorHandler(tr("Failed to flush temporary trace file"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QmlProfilerEventStorage::ErrorHandler QmlProfilerEventStorage::errorHandler() const
|
|
|
|
{
|
|
|
|
return m_errorHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QmlProfilerEventStorage::setErrorHandler(
|
|
|
|
const QmlProfilerEventStorage::ErrorHandler &errorHandler)
|
|
|
|
{
|
|
|
|
m_errorHandler = errorHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QmlProfilerEventStorage::replay(
|
|
|
|
const std::function<bool (Timeline::TraceEvent &&)> &receiver) const
|
|
|
|
{
|
|
|
|
switch (m_file.replay(receiver)) {
|
|
|
|
case Timeline::TraceStashFile<QmlEvent>::ReplaySuccess:
|
|
|
|
return true;
|
|
|
|
case Timeline::TraceStashFile<QmlEvent>::ReplayOpenFailed:
|
|
|
|
m_errorHandler(tr("Could not re-open temporary trace file"));
|
|
|
|
break;
|
|
|
|
case Timeline::TraceStashFile<QmlEvent>::ReplayLoadFailed:
|
|
|
|
// Happens if the loader rejects an event. Not an actual error
|
|
|
|
break;
|
|
|
|
case Timeline::TraceStashFile<QmlEvent>::ReplayReadPastEnd:
|
|
|
|
m_errorHandler(tr("Read past end in temporary trace file"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
} // namespace QmlProfiler
|