2016-05-30 17:40:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** 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 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.
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "flamegraphmodel_test.h"
|
|
|
|
|
|
|
|
|
|
#include <qmlprofiler/qmlprofilerrangemodel.h>
|
|
|
|
|
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
|
|
namespace QmlProfiler {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
FlameGraphModelTest::FlameGraphModelTest(QObject *parent) :
|
2016-12-28 16:45:43 +01:00
|
|
|
QObject(parent), model(&manager)
|
2016-05-30 17:40:19 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-28 15:40:13 +02:00
|
|
|
int FlameGraphModelTest::generateData(QmlProfilerModelManager *manager,
|
|
|
|
|
Timeline::TimelineModelAggregator *aggregator)
|
2016-05-30 17:40:19 +02:00
|
|
|
{
|
2016-05-31 17:32:39 +02:00
|
|
|
// Notes only work with timeline models
|
2018-03-28 15:40:13 +02:00
|
|
|
QmlProfilerRangeModel *rangeModel = new QmlProfilerRangeModel(manager, Javascript, aggregator);
|
2016-12-28 16:50:27 +01:00
|
|
|
int rangeModelId = rangeModel->modelId();
|
2016-05-31 17:32:39 +02:00
|
|
|
manager->notesModel()->addTimelineModel(rangeModel);
|
2016-05-30 17:40:19 +02:00
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
manager->initialize();
|
2016-05-30 17:40:19 +02:00
|
|
|
QmlEvent event;
|
|
|
|
|
|
|
|
|
|
event.setTypeIndex(-1);
|
|
|
|
|
QStack<int> typeIndices;
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < 10) {
|
|
|
|
|
int typeIndex = -1;
|
|
|
|
|
if (i < 5) {
|
2018-05-04 17:19:08 +02:00
|
|
|
typeIndex = manager->appendEventType(
|
|
|
|
|
QmlEventType(MaximumMessage,
|
|
|
|
|
static_cast<RangeType>(static_cast<int>(Javascript) - i), -1,
|
|
|
|
|
QmlEventLocation("somefile.js", i, 20 - i),
|
|
|
|
|
QString("funcfunc")));
|
2016-05-30 17:40:19 +02:00
|
|
|
} else {
|
|
|
|
|
typeIndex = typeIndices[i - 5];
|
|
|
|
|
}
|
|
|
|
|
event.setTypeIndex(typeIndex);
|
|
|
|
|
event.setTimestamp(++i);
|
|
|
|
|
event.setRangeStage(RangeStart);
|
2016-12-28 16:39:57 +01:00
|
|
|
manager->addEvent(event);
|
2016-05-30 17:40:19 +02:00
|
|
|
typeIndices.push(typeIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
event.setRangeStage(RangeEnd);
|
2018-05-08 10:05:35 +02:00
|
|
|
event.setTypeIndex(typeIndices.pop());
|
2016-05-30 17:40:19 +02:00
|
|
|
event.setTimestamp(++i);
|
2016-12-28 16:39:57 +01:00
|
|
|
manager->addEvent(event);
|
2016-05-30 17:40:19 +02:00
|
|
|
|
|
|
|
|
event.setRangeStage(RangeStart);
|
2018-05-08 10:05:35 +02:00
|
|
|
event.setTypeIndex(0); // Have it accepted by the JavaScript range model above
|
|
|
|
|
typeIndices.push(0);
|
2016-05-30 17:40:19 +02:00
|
|
|
event.setTimestamp(++i);
|
2016-12-28 16:39:57 +01:00
|
|
|
manager->addEvent(event);
|
2016-05-30 17:40:19 +02:00
|
|
|
|
2018-05-08 10:05:35 +02:00
|
|
|
while (!typeIndices.isEmpty()) {
|
|
|
|
|
event.setTimestamp(++i);
|
2016-05-30 17:40:19 +02:00
|
|
|
event.setRangeStage(RangeEnd);
|
|
|
|
|
event.setTypeIndex(typeIndices.pop());
|
2016-12-28 16:39:57 +01:00
|
|
|
manager->addEvent(event);
|
2016-05-30 17:40:19 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-27 15:58:43 +02:00
|
|
|
manager->finalize();
|
2016-05-30 17:40:19 +02:00
|
|
|
|
2018-04-05 09:47:33 +02:00
|
|
|
static_cast<QmlProfilerNotesModel *>(manager->notesModel())
|
2018-05-08 10:05:35 +02:00
|
|
|
->setNotes(QVector<QmlNote>({
|
|
|
|
|
// row 2 on purpose to test the range heuristic
|
|
|
|
|
QmlNote(0, 2, 1, 21, "dings"),
|
|
|
|
|
QmlNote(0, 3, 12, 1, "weg")
|
|
|
|
|
}));
|
2018-03-27 16:45:42 +02:00
|
|
|
manager->notesModel()->restore();
|
2016-05-30 17:40:19 +02:00
|
|
|
|
2016-12-28 16:50:27 +01:00
|
|
|
return rangeModelId;
|
2016-05-31 17:32:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlameGraphModelTest::initTestCase()
|
|
|
|
|
{
|
|
|
|
|
QCOMPARE(model.modelManager(), &manager);
|
2018-03-28 15:40:13 +02:00
|
|
|
rangeModelId = generateData(&manager, &aggregator);
|
2016-05-30 17:40:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlameGraphModelTest::testIndex()
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index;
|
|
|
|
|
QModelIndex parent = index;
|
|
|
|
|
for (int i = 0; i < 5; ++i) {
|
|
|
|
|
index = model.index(0, 0, index);
|
|
|
|
|
QVERIFY(index.isValid());
|
|
|
|
|
QCOMPARE(model.parent(index), parent);
|
|
|
|
|
parent = index;
|
|
|
|
|
}
|
|
|
|
|
QVERIFY(!model.parent(QModelIndex()).isValid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlameGraphModelTest::testCounts()
|
|
|
|
|
{
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.rowCount(), 2);
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.rowCount(model.index(0, 0)), 1);
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.rowCount(model.index(1, 0)), 1);
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.columnCount(), 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlameGraphModelTest::testData()
|
|
|
|
|
{
|
|
|
|
|
const QVector<QString> typeRoles({
|
|
|
|
|
FlameGraphModel::tr("JavaScript"),
|
|
|
|
|
FlameGraphModel::tr("Signal"),
|
|
|
|
|
FlameGraphModel::tr("Binding"),
|
2016-09-16 15:14:37 +02:00
|
|
|
FlameGraphModel::tr("Create")
|
2016-05-30 17:40:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
QModelIndex index = model.index(0, 0);
|
2016-09-16 15:14:37 +02:00
|
|
|
QModelIndex index2 = model.index(1, 0);
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::TypeIdRole).toInt(), 0);
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::TypeIdRole).toInt(), 4);
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::TypeRole).toString(),
|
|
|
|
|
FlameGraphModel::tr("JavaScript"));
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::TypeRole).toString(),
|
|
|
|
|
FlameGraphModel::tr("Compile"));
|
2018-05-08 10:05:35 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::DurationRole).toLongLong(), 21);
|
|
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::DurationRole).toLongLong(), 13);
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::CallCountRole).toInt(), 1);
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::CallCountRole).toInt(), 1);
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::DetailsRole).toString(),
|
|
|
|
|
QLatin1String("funcfunc"));
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::DetailsRole).toString(),
|
|
|
|
|
QLatin1String("funcfunc"));
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::FilenameRole).toString(),
|
|
|
|
|
QLatin1String("somefile.js"));
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::FilenameRole).toString(),
|
|
|
|
|
QLatin1String("somefile.js"));
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::LineRole).toInt(), 0);
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::LineRole).toInt(), 4);
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::ColumnRole).toInt(), 20);
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::ColumnRole).toInt(), 16);
|
2018-05-08 10:05:35 +02:00
|
|
|
|
|
|
|
|
// The flame graph model does not know that one of the notes belongs to row 2, and the
|
|
|
|
|
// other one to row 3. It will show both of them for all indexes with that type ID.
|
|
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::NoteRole).toString(), QString("dings\nweg"));
|
|
|
|
|
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::NoteRole).toString(), QString());
|
2018-05-08 10:05:35 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::TimePerCallRole).toLongLong(), 21);
|
|
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::TimePerCallRole).toLongLong(), 13);
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::RangeTypeRole).toInt(),
|
|
|
|
|
static_cast<int>(Javascript));
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::RangeTypeRole).toInt(),
|
|
|
|
|
static_cast<int>(Compiling));
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::LocationRole).toString(),
|
|
|
|
|
QLatin1String("somefile.js:0"));
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::LocationRole).toString(),
|
|
|
|
|
QLatin1String("somefile.js:4"));
|
2016-05-30 17:40:19 +02:00
|
|
|
QVERIFY(!model.data(index, -10).isValid());
|
2016-09-16 15:14:37 +02:00
|
|
|
QVERIFY(!model.data(index2, -10).isValid());
|
2016-05-30 17:40:19 +02:00
|
|
|
QVERIFY(!model.data(QModelIndex(), FlameGraphModel::LineRole).isValid());
|
|
|
|
|
|
2018-05-08 10:05:35 +02:00
|
|
|
for (int i = 1; i < 9; ++i) {
|
2016-05-30 17:40:19 +02:00
|
|
|
index = model.index(0, 0, index);
|
|
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::TypeRole).toString(),
|
|
|
|
|
typeRoles[i % typeRoles.length()]);
|
|
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::NoteRole).toString(),
|
2018-05-08 10:05:35 +02:00
|
|
|
(i % typeRoles.length() == 0) ? QString("dings\nweg") : QString());
|
2016-05-30 17:40:19 +02:00
|
|
|
}
|
2016-09-16 15:14:37 +02:00
|
|
|
QCOMPARE(model.data(index, FlameGraphModel::CallCountRole).toInt(), 1);
|
|
|
|
|
|
|
|
|
|
index2 = model.index(0, 0, index2);
|
|
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::TypeRole).toString(),
|
|
|
|
|
FlameGraphModel::tr("Compile"));
|
|
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::NoteRole).toString(), QString());
|
2018-05-08 10:05:35 +02:00
|
|
|
QCOMPARE(model.data(index2, FlameGraphModel::CallCountRole).toInt(), 1);
|
2016-05-30 17:40:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlameGraphModelTest::testRoleNames()
|
|
|
|
|
{
|
|
|
|
|
auto names = model.roleNames();
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::TypeIdRole], QByteArray("typeId"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::TypeRole], QByteArray("type"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::DurationRole], QByteArray("duration"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::CallCountRole], QByteArray("callCount"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::DetailsRole], QByteArray("details"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::FilenameRole], QByteArray("filename"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::LineRole], QByteArray("line"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::ColumnRole], QByteArray("column"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::NoteRole], QByteArray("note"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::TimePerCallRole], QByteArray("timePerCall"));
|
|
|
|
|
QCOMPARE(names[FlameGraphModel::RangeTypeRole], QByteArray("rangeType"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlameGraphModelTest::testNotes()
|
|
|
|
|
{
|
2016-12-28 16:50:27 +01:00
|
|
|
manager.notesModel()->add(rangeModelId, 1, QString("blubb"));
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.data(model.index(0, 0), FlameGraphModel::NoteRole).toString(),
|
2018-05-08 10:05:35 +02:00
|
|
|
QString("dings\nweg\nblubb"));
|
|
|
|
|
manager.notesModel()->remove(0);
|
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), FlameGraphModel::NoteRole).toString(),
|
|
|
|
|
QString("weg\nblubb"));
|
2016-05-30 17:40:19 +02:00
|
|
|
manager.notesModel()->remove(0);
|
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), FlameGraphModel::NoteRole).toString(),
|
|
|
|
|
QString("blubb"));
|
|
|
|
|
manager.notesModel()->remove(0);
|
|
|
|
|
QCOMPARE(model.data(model.index(0, 0), FlameGraphModel::NoteRole).toString(),
|
|
|
|
|
QString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlameGraphModelTest::cleanupTestCase()
|
|
|
|
|
{
|
2018-04-05 09:47:33 +02:00
|
|
|
manager.clearAll();
|
2016-05-30 17:40:19 +02:00
|
|
|
QCOMPARE(model.rowCount(), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProfiler
|