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
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** 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
|
|
|
**
|
|
|
|
|
** 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-10-27 17:41:22 +01:00
|
|
|
#include "qmlprofilerrangemodel.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
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QVector>
|
|
|
|
|
#include <QHash>
|
|
|
|
|
#include <QUrl>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStack>
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
|
2014-10-28 17:37:11 +01:00
|
|
|
QmlProfilerRangeModel::QmlProfilerRangeModel(QmlProfilerModelManager *manager,
|
2014-10-28 19:01:43 +01:00
|
|
|
QmlDebug::RangeType range, QObject *parent) :
|
|
|
|
|
QmlProfilerTimelineModel(manager, categoryLabel(range), QmlDebug::MaximumMessage, range, parent)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-28 10:57:32 +01:00
|
|
|
m_expandedRowTypes << -1;
|
2014-10-28 17:37:11 +01:00
|
|
|
announceFeatures(1ULL << QmlDebug::featureFromRangeType(rangeType()));
|
2014-09-09 18:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerRangeModel::clear()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-28 10:57:32 +01:00
|
|
|
m_expandedRowTypes.clear();
|
|
|
|
|
m_expandedRowTypes << -1;
|
|
|
|
|
m_data.clear();
|
2014-10-28 19:01:43 +01:00
|
|
|
QmlProfilerTimelineModel::clear();
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
void QmlProfilerRangeModel::loadData()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
clear();
|
2014-10-28 10:57:32 +01:00
|
|
|
QmlProfilerDataModel *simpleModel = modelManager()->qmlModel();
|
2013-08-08 13:28:08 +02:00
|
|
|
if (simpleModel->isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// collect events
|
2014-06-13 16:34:30 +02:00
|
|
|
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) {
|
2014-06-13 16:34:30 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventTypeData &type = typesList[event.typeIndex];
|
2014-07-08 14:43:15 +02:00
|
|
|
if (!accepted(type))
|
2013-08-08 13:28:08 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// store starttime-based instance
|
2014-10-28 10:57:32 +01:00
|
|
|
m_data.insert(insert(event.startTime, event.duration, event.typeIndex),
|
|
|
|
|
QmlRangeEventStartInstance());
|
|
|
|
|
updateProgress(count(), eventList.count() * 6);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
updateProgress(2, 6);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2013-12-04 16:05:02 +01:00
|
|
|
// compute range nesting
|
2014-07-08 17:18:51 +02:00
|
|
|
computeNesting();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// compute nestingLevel - nonexpanded
|
2014-10-28 10:57:32 +01:00
|
|
|
computeNestingContracted();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
updateProgress(3, 6);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// compute nestingLevel - expanded
|
2014-10-28 10:57:32 +01:00
|
|
|
computeExpandedLevels();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
updateProgress(4, 6);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
findBindingLoops();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
updateProgress(5, 6);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
updateProgress(1, 1);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
void QmlProfilerRangeModel::computeNestingContracted()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
2014-10-28 10:57:32 +01:00
|
|
|
int eventCount = count();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-12 15:34:38 +02:00
|
|
|
int nestingLevels = QmlDebug::Constants::QML_MIN_LEVEL;
|
2014-10-28 10:57:32 +01:00
|
|
|
int collapsedRowCount = nestingLevels + 1;
|
2014-06-12 15:34:38 +02:00
|
|
|
QVector<qint64> nestingEndTimes;
|
|
|
|
|
nestingEndTimes.fill(0, nestingLevels + 1);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < eventCount; i++) {
|
2014-10-28 10:57:32 +01:00
|
|
|
qint64 st = startTime(i);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
// per type
|
2014-06-12 15:34:38 +02:00
|
|
|
if (nestingEndTimes[nestingLevels] > st) {
|
2014-06-24 12:45:27 +02:00
|
|
|
if (++nestingLevels == nestingEndTimes.size())
|
2014-06-12 15:34:38 +02:00
|
|
|
nestingEndTimes << 0;
|
2014-09-11 10:57:34 +02:00
|
|
|
if (nestingLevels == collapsedRowCount)
|
|
|
|
|
++collapsedRowCount;
|
2013-08-08 13:28:08 +02:00
|
|
|
} else {
|
2014-06-12 15:34:38 +02:00
|
|
|
while (nestingLevels > QmlDebug::Constants::QML_MIN_LEVEL &&
|
|
|
|
|
nestingEndTimes[nestingLevels-1] <= st)
|
|
|
|
|
nestingLevels--;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2014-10-28 10:57:32 +01:00
|
|
|
nestingEndTimes[nestingLevels] = st + duration(i);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
m_data[i].displayRowCollapsed = nestingLevels;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2014-10-28 10:57:32 +01:00
|
|
|
setCollapsedRowCount(collapsedRowCount);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
void QmlProfilerRangeModel::computeExpandedLevels()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
QHash<int, int> eventRow;
|
2014-10-28 10:57:32 +01:00
|
|
|
int eventCount = count();
|
2013-08-08 13:28:08 +02:00
|
|
|
for (int i = 0; i < eventCount; i++) {
|
2014-10-28 10:57:32 +01:00
|
|
|
int eventTypeId = typeId(i);
|
|
|
|
|
if (!eventRow.contains(eventTypeId)) {
|
|
|
|
|
eventRow[eventTypeId] = m_expandedRowTypes.size();
|
|
|
|
|
m_expandedRowTypes << eventTypeId;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2014-10-28 10:57:32 +01:00
|
|
|
m_data[i].displayRowExpanded = eventRow[eventTypeId];
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
2014-10-28 10:57:32 +01:00
|
|
|
setExpandedRowCount(m_expandedRowTypes.size());
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
void QmlProfilerRangeModel::findBindingLoops()
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-28 10:57:32 +01:00
|
|
|
if (rangeType() != QmlDebug::Binding && rangeType() != QmlDebug::HandlingSignal)
|
2014-06-06 17:36:11 +02:00
|
|
|
return;
|
|
|
|
|
|
2014-06-13 16:34:30 +02:00
|
|
|
typedef QPair<int, int> CallStackEntry;
|
2013-08-08 13:28:08 +02:00
|
|
|
QStack<CallStackEntry> callStack;
|
|
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
for (int i = 0; i < count(); ++i) {
|
|
|
|
|
int potentialParent = callStack.isEmpty() ? -1 : callStack.top().second;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
while (potentialParent != -1 && !(endTime(potentialParent) > startTime(i))) {
|
2013-08-08 13:28:08 +02:00
|
|
|
callStack.pop();
|
2014-10-28 10:57:32 +01:00
|
|
|
potentialParent = callStack.isEmpty() ? -1 : callStack.top().second;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check whether event is already in stack
|
|
|
|
|
for (int ii = 0; ii < callStack.size(); ++ii) {
|
2014-10-28 10:57:32 +01:00
|
|
|
if (callStack.at(ii).first == typeId(i)) {
|
|
|
|
|
m_data[i].bindingLoopHead = callStack.at(ii).second;
|
2013-08-08 13:28:08 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
CallStackEntry newEntry(typeId(i), i);
|
2013-08-08 13:28:08 +02:00
|
|
|
callStack.push(newEntry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////// QML interface
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QString QmlProfilerRangeModel::categoryLabel(QmlDebug::RangeType rangeType)
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-09-10 13:51:36 +02:00
|
|
|
return QCoreApplication::translate("MainView",
|
|
|
|
|
QmlProfilerModelManager::featureName(QmlDebug::featureFromRangeType(rangeType)));
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-11-18 17:37:25 +01:00
|
|
|
int QmlProfilerRangeModel::expandedRow(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-11-18 17:37:25 +01:00
|
|
|
return m_data[index].displayRowExpanded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int QmlProfilerRangeModel::collapsedRow(int index) const
|
|
|
|
|
{
|
|
|
|
|
return m_data[index].displayRowCollapsed;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerRangeModel::bindingLoopDest(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-28 10:57:32 +01:00
|
|
|
return m_data[index].bindingLoopHead;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QColor QmlProfilerRangeModel::color(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-08-29 16:32:42 +02:00
|
|
|
return colorBySelectionId(index);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QVariantList QmlProfilerRangeModel::labels() const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
QVariantList result;
|
|
|
|
|
|
2014-10-29 10:41:27 +01:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
|
|
|
|
|
modelManager()->qmlModel()->getEventTypes();
|
|
|
|
|
for (int i = 1; i < expandedRowCount(); i++) { // Ignore the -1 for the first row
|
|
|
|
|
QVariantMap element;
|
|
|
|
|
int typeId = m_expandedRowTypes[i];
|
|
|
|
|
element.insert(QLatin1String("displayName"), QVariant(types[typeId].displayName));
|
|
|
|
|
element.insert(QLatin1String("description"), QVariant(types[typeId].data));
|
|
|
|
|
element.insert(QLatin1String("id"), QVariant(typeId));
|
|
|
|
|
result << element;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QVariantMap QmlProfilerRangeModel::details(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-07-07 14:02:29 +02:00
|
|
|
QVariantMap result;
|
2014-08-29 16:32:42 +02:00
|
|
|
int id = selectionId(index);
|
2014-06-13 16:34:30 +02:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
|
2014-10-28 10:57:32 +01:00
|
|
|
modelManager()->qmlModel()->getEventTypes();
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-10-28 10:57:32 +01:00
|
|
|
result.insert(QStringLiteral("displayName"), categoryLabel(rangeType()));
|
2014-10-27 18:42:39 +01:00
|
|
|
result.insert(tr("Duration"), QmlProfilerBaseModel::formatTime(duration(index)));
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-07-07 14:03:33 +02:00
|
|
|
result.insert(tr("Details"), types[id].data);
|
2014-07-07 14:02:29 +02:00
|
|
|
result.insert(tr("Location"), types[id].displayName);
|
2013-08-08 13:28:08 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
QVariantMap QmlProfilerRangeModel::location(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
QVariantMap result;
|
2014-08-29 16:32:42 +02:00
|
|
|
int id = selectionId(index);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-24 12:20:13 +02:00
|
|
|
const QmlDebug::QmlEventLocation &location
|
2014-10-28 10:57:32 +01:00
|
|
|
= modelManager()->qmlModel()->getEventTypes().at(id).location;
|
2013-08-08 13:28:08 +02:00
|
|
|
|
2014-06-24 12:20:13 +02:00
|
|
|
result.insert(QStringLiteral("file"), location.filename);
|
|
|
|
|
result.insert(QStringLiteral("line"), location.line);
|
|
|
|
|
result.insert(QStringLiteral("column"), location.column);
|
2013-08-08 13:28:08 +02:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-28 14:26:57 +01:00
|
|
|
int QmlProfilerRangeModel::typeId(int index) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
2014-10-28 14:26:57 +01:00
|
|
|
return selectionId(index);
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-27 17:41:22 +01:00
|
|
|
int QmlProfilerRangeModel::selectionIdForLocation(const QString &filename, int line, int column) const
|
2013-08-08 13:28:08 +02:00
|
|
|
{
|
|
|
|
|
// if this is called from v8 view, we don't have the column number, it will be -1
|
2014-06-13 16:34:30 +02:00
|
|
|
const QVector<QmlProfilerDataModel::QmlEventTypeData> &types =
|
2014-10-28 10:57:32 +01:00
|
|
|
modelManager()->qmlModel()->getEventTypes();
|
|
|
|
|
for (int i = 1; i < expandedRowCount(); ++i) {
|
|
|
|
|
int typeId = m_expandedRowTypes[i];
|
2014-06-13 16:34:30 +02:00
|
|
|
const QmlProfilerDataModel::QmlEventTypeData &eventData = types[typeId];
|
2013-08-08 13:28:08 +02:00
|
|
|
if (eventData.location.filename == filename &&
|
|
|
|
|
eventData.location.line == line &&
|
|
|
|
|
(column == -1 || eventData.location.column == column))
|
2014-06-13 16:34:30 +02:00
|
|
|
return typeId;
|
2013-08-08 13:28:08 +02:00
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|