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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
#include "qmlprofilerdatamodel.h"
|
2014-02-18 18:25:57 +01:00
|
|
|
#include "qmlprofilerbasemodel_p.h"
|
2014-02-12 17:35:08 +01:00
|
|
|
#include "qmlprofilermodelmanager.h"
|
2013-08-08 13:28:08 +02:00
|
|
|
#include <qmldebug/qmlprofilereventtypes.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <QUrl>
|
|
|
|
|
#include <QDebug>
|
2014-03-26 17:23:12 +01:00
|
|
|
#include <algorithm>
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
|
|
2014-02-18 18:25:57 +01:00
|
|
|
class QmlProfilerDataModel::QmlProfilerDataModelPrivate :
|
|
|
|
|
public QmlProfilerBaseModel::QmlProfilerBaseModelPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QmlProfilerDataModelPrivate(QmlProfilerDataModel *qq) : QmlProfilerBaseModelPrivate(qq) {}
|
2014-06-13 16:34:30 +02:00
|
|
|
QVector<QmlEventTypeData> eventTypes;
|
2014-02-18 18:25:57 +01:00
|
|
|
QVector<QmlEventData> eventList;
|
2014-06-13 16:34:30 +02:00
|
|
|
QHash<QmlEventTypeData, int> eventTypeIds;
|
2014-02-18 18:25:57 +01:00
|
|
|
private:
|
|
|
|
|
Q_DECLARE_PUBLIC(QmlProfilerDataModel)
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
QString getInitialDetails(const QmlProfilerDataModel::QmlEventTypeData &event);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
QmlDebug::QmlEventLocation getLocation(const QmlProfilerDataModel::QmlEventTypeData &event)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
QmlDebug::QmlEventLocation eventLocation = event.location;
|
2014-06-03 16:57:32 +02:00
|
|
|
if ((event.rangeType == QmlDebug::Creating || event.rangeType == QmlDebug::Compiling)
|
2013-08-08 13:28:08 +02:00
|
|
|
&& eventLocation.filename.isEmpty()) {
|
|
|
|
|
eventLocation.filename = getInitialDetails(event);
|
|
|
|
|
eventLocation.line = 1;
|
|
|
|
|
eventLocation.column = 1;
|
|
|
|
|
}
|
|
|
|
|
return eventLocation;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
QString getDisplayName(const QmlProfilerDataModel::QmlEventTypeData &event)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
const QmlDebug::QmlEventLocation eventLocation = getLocation(event);
|
|
|
|
|
QString displayName;
|
|
|
|
|
|
|
|
|
|
// generate hash
|
|
|
|
|
if (eventLocation.filename.isEmpty()) {
|
2014-02-18 17:32:20 +01:00
|
|
|
displayName = QmlProfilerDataModel::tr("<bytecode>");
|
2013-08-08 13:28:08 +02:00
|
|
|
} else {
|
|
|
|
|
const QString filePath = QUrl(eventLocation.filename).path();
|
|
|
|
|
displayName = filePath.mid(filePath.lastIndexOf(QLatin1Char('/')) + 1) + QLatin1Char(':') +
|
|
|
|
|
QString::number(eventLocation.line);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return displayName;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
QString getInitialDetails(const QmlProfilerDataModel::QmlEventTypeData &event)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
QString details;
|
|
|
|
|
// generate details string
|
2014-06-13 19:16:35 +02:00
|
|
|
if (!event.data.isEmpty()) {
|
2014-06-13 16:33:30 +02:00
|
|
|
details = event.data;
|
|
|
|
|
details.replace(QLatin1Char('\n'),QLatin1Char(' ')).simplified();
|
2014-02-19 11:22:25 +01:00
|
|
|
if (details.isEmpty()) {
|
2014-06-13 19:16:35 +02:00
|
|
|
if (event.rangeType == QmlDebug::Javascript)
|
|
|
|
|
details = QmlProfilerDataModel::tr("anonymous function");
|
2014-02-19 11:22:25 +01:00
|
|
|
} else {
|
|
|
|
|
QRegExp rewrite(QLatin1String("\\(function \\$(\\w+)\\(\\) \\{ (return |)(.+) \\}\\)"));
|
|
|
|
|
bool match = rewrite.exactMatch(details);
|
|
|
|
|
if (match)
|
|
|
|
|
details = rewrite.cap(1) + QLatin1String(": ") + rewrite.cap(3);
|
2014-02-21 12:11:27 +01:00
|
|
|
if (details.startsWith(QLatin1String("file://")) ||
|
|
|
|
|
details.startsWith(QLatin1String("qrc:/")))
|
2014-02-19 11:22:25 +01:00
|
|
|
details = details.mid(details.lastIndexOf(QLatin1Char('/')) + 1);
|
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return details;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
QmlProfilerDataModel::QmlProfilerDataModel(Utils::FileInProjectFinder *fileFinder,
|
|
|
|
|
QmlProfilerModelManager *parent)
|
2014-02-18 18:25:57 +01:00
|
|
|
: QmlProfilerBaseModel(fileFinder, parent, new QmlProfilerDataModelPrivate(this))
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-02-18 18:25:57 +01:00
|
|
|
Q_D(QmlProfilerDataModel);
|
2014-02-12 17:50:55 +01:00
|
|
|
// The document loading is very expensive.
|
2014-02-18 18:25:57 +01:00
|
|
|
d->modelManager->setProxyCountWeight(d->modelId, 4);
|
2014-02-18 17:32:20 +01:00
|
|
|
}
|
2014-02-12 17:50:55 +01:00
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventData> &QmlProfilerDataModel::getEvents() const
|
|
|
|
|
{
|
2014-02-18 18:25:57 +01:00
|
|
|
Q_D(const QmlProfilerDataModel);
|
|
|
|
|
return d->eventList;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &QmlProfilerDataModel::getEventTypes() const
|
|
|
|
|
{
|
|
|
|
|
Q_D(const QmlProfilerDataModel);
|
|
|
|
|
return d->eventTypes;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
int QmlProfilerDataModel::count() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-02-18 18:25:57 +01:00
|
|
|
Q_D(const QmlProfilerDataModel);
|
|
|
|
|
return d->eventList.count();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
void QmlProfilerDataModel::clear()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-02-18 18:25:57 +01:00
|
|
|
Q_D(QmlProfilerDataModel);
|
|
|
|
|
d->eventList.clear();
|
2014-06-13 16:34:30 +02:00
|
|
|
d->eventTypes.clear();
|
|
|
|
|
d->eventTypeIds.clear();
|
2013-12-09 12:52:51 +01:00
|
|
|
// This call emits changed(). Don't emit it again here.
|
2014-02-18 17:32:20 +01:00
|
|
|
QmlProfilerBaseModel::clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QmlProfilerDataModel::isEmpty() const
|
|
|
|
|
{
|
2014-02-18 18:25:57 +01:00
|
|
|
Q_D(const QmlProfilerDataModel);
|
|
|
|
|
return d->eventList.isEmpty();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-03-26 17:23:12 +01:00
|
|
|
inline static bool operator<(const QmlProfilerDataModel::QmlEventData &t1,
|
|
|
|
|
const QmlProfilerDataModel::QmlEventData &t2)
|
|
|
|
|
{
|
|
|
|
|
return t1.startTime < t2.startTime;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
inline static uint qHash(const QmlProfilerDataModel::QmlEventTypeData &type)
|
|
|
|
|
{
|
|
|
|
|
return qHash(type.location.filename) ^
|
|
|
|
|
((type.location.line & 0xfff) | // 12 bits of line number
|
|
|
|
|
((type.message << 12) & 0xf000) | // 4 bits of message
|
|
|
|
|
((type.location.column << 16) & 0xff0000) | // 8 bits of column
|
|
|
|
|
((type.rangeType << 24) & 0xf000000) | // 4 bits of rangeType
|
|
|
|
|
((type.detailType << 28) & 0xf0000000)); // 4 bits of detailType
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline static bool operator==(const QmlProfilerDataModel::QmlEventTypeData &type1,
|
|
|
|
|
const QmlProfilerDataModel::QmlEventTypeData &type2)
|
|
|
|
|
{
|
|
|
|
|
return type1.message == type2.message && type1.rangeType == type2.rangeType &&
|
|
|
|
|
type1.detailType == type2.detailType && type1.location.line == type2.location.line &&
|
|
|
|
|
type1.location.column == type2.location.column &&
|
|
|
|
|
// compare filename last as it's expensive.
|
|
|
|
|
type1.location.filename == type2.location.filename;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
void QmlProfilerDataModel::complete()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-02-18 18:25:57 +01:00
|
|
|
Q_D(QmlProfilerDataModel);
|
2013-08-08 13:28:08 +02:00
|
|
|
// post-processing
|
|
|
|
|
|
2014-03-26 17:23:12 +01:00
|
|
|
// sort events by start time, using above operator<
|
|
|
|
|
std::sort(d->eventList.begin(), d->eventList.end());
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// rewrite strings
|
2014-06-13 16:34:30 +02:00
|
|
|
int n = d->eventTypes.count();
|
2013-08-08 13:28:08 +02:00
|
|
|
for (int i = 0; i < n; i++) {
|
2014-06-13 16:34:30 +02:00
|
|
|
QmlEventTypeData *event = &d->eventTypes[i];
|
2013-08-08 13:28:08 +02:00
|
|
|
event->location = getLocation(*event);
|
|
|
|
|
event->displayName = getDisplayName(*event);
|
2014-06-13 16:33:30 +02:00
|
|
|
event->data = getInitialDetails(*event);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// request further details from files
|
|
|
|
|
//
|
|
|
|
|
|
2014-06-03 16:57:32 +02:00
|
|
|
if (event->rangeType != QmlDebug::Binding && event->rangeType != QmlDebug::HandlingSignal)
|
2013-08-08 13:28:08 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// This skips anonymous bindings in Qt4.8 (we don't have valid location data for them)
|
|
|
|
|
if (event->location.filename.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Skip non-anonymous bindings from Qt4.8 (we already have correct details for them)
|
|
|
|
|
if (event->location.column == -1)
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-02-18 18:25:57 +01:00
|
|
|
d->detailsRewriter->requestDetailsForLocation(i, event->location);
|
|
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, i + n, n * 2);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
// Allow changed() event only after documents have been reloaded to avoid
|
2014-02-12 17:35:08 +01:00
|
|
|
// unnecessary updates of child models.
|
2014-02-18 17:32:20 +01:00
|
|
|
QmlProfilerBaseModel::complete();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-03 16:57:32 +02:00
|
|
|
void QmlProfilerDataModel::addQmlEvent(QmlDebug::Message message, QmlDebug::RangeType rangeType,
|
|
|
|
|
int detailType, qint64 startTime,
|
2014-06-13 16:33:30 +02:00
|
|
|
qint64 duration, const QString &data,
|
2014-02-18 17:32:20 +01:00
|
|
|
const QmlDebug::QmlEventLocation &location,
|
|
|
|
|
qint64 ndata1, qint64 ndata2, qint64 ndata3,
|
|
|
|
|
qint64 ndata4, qint64 ndata5)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-02-18 18:25:57 +01:00
|
|
|
Q_D(QmlProfilerDataModel);
|
2014-02-18 17:32:20 +01:00
|
|
|
QString displayName;
|
2014-06-03 16:57:32 +02:00
|
|
|
if (message == QmlDebug::Event && detailType == QmlDebug::AnimationFrame) {
|
2014-02-18 17:32:20 +01:00
|
|
|
displayName = tr("Animations");
|
|
|
|
|
} else {
|
|
|
|
|
displayName = QString::fromLatin1("%1:%2").arg(
|
|
|
|
|
location.filename,
|
|
|
|
|
QString::number(location.line));
|
|
|
|
|
}
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
QmlEventTypeData typeData = {displayName, location, message, rangeType, detailType, data};
|
|
|
|
|
QmlEventData eventData = {-1, startTime, duration, ndata1, ndata2, ndata3, ndata4, ndata5};
|
|
|
|
|
|
|
|
|
|
QHash<QmlEventTypeData, int>::Iterator it = d->eventTypeIds.find(typeData);
|
|
|
|
|
if (it != d->eventTypeIds.end()) {
|
|
|
|
|
eventData.typeIndex = it.value();
|
|
|
|
|
} else {
|
|
|
|
|
eventData.typeIndex = d->eventTypes.size();
|
|
|
|
|
d->eventTypeIds[typeData] = eventData.typeIndex;
|
|
|
|
|
d->eventTypes.append(typeData);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 18:25:57 +01:00
|
|
|
d->eventList.append(eventData);
|
2014-02-18 17:32:20 +01:00
|
|
|
|
2014-02-18 18:25:57 +01:00
|
|
|
d->modelManager->modelProxyCountUpdated(d->modelId, startTime,
|
|
|
|
|
d->modelManager->estimatedProfilingTime() * 2);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-18 17:32:20 +01:00
|
|
|
qint64 QmlProfilerDataModel::lastTimeMark() const
|
|
|
|
|
{
|
2014-02-18 18:25:57 +01:00
|
|
|
Q_D(const QmlProfilerDataModel);
|
|
|
|
|
if (d->eventList.isEmpty())
|
2014-02-18 17:32:20 +01:00
|
|
|
return 0;
|
|
|
|
|
|
2014-02-18 18:25:57 +01:00
|
|
|
return d->eventList.last().startTime + d->eventList.last().duration;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2014-02-18 17:32:20 +01:00
|
|
|
|
|
|
|
|
void QmlProfilerDataModel::detailsChanged(int requestId, const QString &newString)
|
|
|
|
|
{
|
2014-02-18 18:25:57 +01:00
|
|
|
Q_D(QmlProfilerDataModel);
|
2014-06-13 16:34:30 +02:00
|
|
|
QTC_ASSERT(requestId < d->eventTypes.count(), return);
|
2014-02-18 17:32:20 +01:00
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
QmlEventTypeData *event = &d->eventTypes[requestId];
|
2014-06-13 16:33:30 +02:00
|
|
|
event->data = newString;
|
2014-02-18 17:32:20 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|