forked from qt-creator/qt-creator
QmlProfiler: Add tests for FlameGraph
Change-Id: I1eadb2675e16fcc61e073ea1a730ab065456f964 Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
@@ -78,6 +78,7 @@ QtcPlugin {
|
|||||||
prefix: "tests/"
|
prefix: "tests/"
|
||||||
files: [
|
files: [
|
||||||
"debugmessagesmodel_test.cpp", "debugmessagesmodel_test.h",
|
"debugmessagesmodel_test.cpp", "debugmessagesmodel_test.h",
|
||||||
|
"flamegraph_test.cpp", "flamegraph_test.h",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
#include "tests/debugmessagesmodel_test.h"
|
#include "tests/debugmessagesmodel_test.h"
|
||||||
|
#include "tests/flamegraph_test.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
@@ -81,6 +82,7 @@ QList<QObject *> QmlProfiler::Internal::QmlProfilerPlugin::createTestObjects() c
|
|||||||
QList<QObject *> tests;
|
QList<QObject *> tests;
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
tests << new DebugMessagesModelTest;
|
tests << new DebugMessagesModelTest;
|
||||||
|
tests << new FlameGraphTest;
|
||||||
#endif
|
#endif
|
||||||
return tests;
|
return tests;
|
||||||
}
|
}
|
||||||
|
|||||||
123
src/plugins/qmlprofiler/tests/flamegraph_test.cpp
Normal file
123
src/plugins/qmlprofiler/tests/flamegraph_test.cpp
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "flamegraph_test.h"
|
||||||
|
#include <QtTest>
|
||||||
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
namespace QmlProfiler {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
void FlameGraphTest::initTestCase()
|
||||||
|
{
|
||||||
|
flameGraph.setDelegate(&delegate);
|
||||||
|
flameGraph.setModel(&model);
|
||||||
|
flameGraph.setSizeRole(sizeRole);
|
||||||
|
flameGraph.setWidth(100);
|
||||||
|
flameGraph.setHeight(100);
|
||||||
|
flameGraph.setSizeThreshold(0.01);
|
||||||
|
|
||||||
|
QCOMPARE(flameGraph.delegate(), &delegate);
|
||||||
|
QCOMPARE(flameGraph.model(), &model);
|
||||||
|
QCOMPARE(flameGraph.sizeRole(), Qt::UserRole + 1);
|
||||||
|
QCOMPARE(flameGraph.sizeThreshold(), 0.01);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlameGraphTest::testRebuild()
|
||||||
|
{
|
||||||
|
flameGraph.setModel(nullptr);
|
||||||
|
qreal sum = 0;
|
||||||
|
for (int i = 1; i < 10; ++i) {
|
||||||
|
QStandardItem *item = new QStandardItem;
|
||||||
|
item->setData(i, sizeRole);
|
||||||
|
item->setData(100 / i, dataRole);
|
||||||
|
|
||||||
|
for (int j = 1; j < i; ++j) {
|
||||||
|
QStandardItem *item2 = new QStandardItem;
|
||||||
|
item2->setData(1, sizeRole);
|
||||||
|
for (int k = 0; k < 10; ++k) {
|
||||||
|
QStandardItem *skipped = new QStandardItem;
|
||||||
|
skipped->setData(0.001, sizeRole);
|
||||||
|
item2->appendRow(skipped);
|
||||||
|
}
|
||||||
|
item->appendRow(item2);
|
||||||
|
}
|
||||||
|
|
||||||
|
model.appendRow(item);
|
||||||
|
sum += i;
|
||||||
|
}
|
||||||
|
model.invisibleRootItem()->setData(sum, sizeRole);
|
||||||
|
flameGraph.setModel(nullptr);
|
||||||
|
flameGraph.setModel(&model);
|
||||||
|
QCOMPARE(flameGraph.depth(), 3);
|
||||||
|
qreal i = 0;
|
||||||
|
qreal position = 0;
|
||||||
|
foreach (QQuickItem *child, flameGraph.childItems()) {
|
||||||
|
FlameGraphAttached *attached = FlameGraph::qmlAttachedProperties(child);
|
||||||
|
QCOMPARE(attached->relativeSize(), (++i) / sum);
|
||||||
|
QCOMPARE(attached->relativePosition(), position / sum);
|
||||||
|
QCOMPARE(attached->data(dataRole).toInt(), 100 / static_cast<int>(i));
|
||||||
|
QVERIFY(attached->isDataValid());
|
||||||
|
|
||||||
|
qreal j = 0;
|
||||||
|
foreach (QQuickItem *grandchild, child->childItems()) {
|
||||||
|
FlameGraphAttached *attached2 = FlameGraph::qmlAttachedProperties(grandchild);
|
||||||
|
QCOMPARE(attached2->relativeSize(), 1.0 / i);
|
||||||
|
QCOMPARE(attached2->relativePosition(), (j++) / i);
|
||||||
|
QCOMPARE(grandchild->childItems().count(), 1);
|
||||||
|
FlameGraphAttached *skipped =
|
||||||
|
FlameGraph::qmlAttachedProperties(grandchild->childItems()[0]);
|
||||||
|
QCOMPARE(skipped->relativePosition(), 0.0);
|
||||||
|
QCOMPARE(skipped->relativeSize(), 0.001 * 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
position += i;
|
||||||
|
}
|
||||||
|
QCOMPARE(i, 9.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlameGraphTest::cleanupTestCase()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *DelegateComponent::create(QQmlContext *context)
|
||||||
|
{
|
||||||
|
QObject *ret = beginCreate(context);
|
||||||
|
completeCreate();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *DelegateComponent::beginCreate(QQmlContext *)
|
||||||
|
{
|
||||||
|
return new DelegateObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DelegateComponent::completeCreate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QmlProfiler
|
||||||
69
src/plugins/qmlprofiler/tests/flamegraph_test.h
Normal file
69
src/plugins/qmlprofiler/tests/flamegraph_test.h
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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.
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <qmlprofiler/flamegraph.h>
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
#include <QQmlComponent>
|
||||||
|
#include <QQuickItem>
|
||||||
|
|
||||||
|
namespace QmlProfiler {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class DelegateObject : public QQuickItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
};
|
||||||
|
|
||||||
|
class DelegateComponent : public QQmlComponent
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QObject *create(QQmlContext *context) override;
|
||||||
|
QObject *beginCreate(QQmlContext *) override;
|
||||||
|
void completeCreate() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class FlameGraphTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private slots:
|
||||||
|
void initTestCase();
|
||||||
|
void testRebuild();
|
||||||
|
void cleanupTestCase();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const int sizeRole = Qt::UserRole + 1;
|
||||||
|
static const int dataRole = Qt::UserRole + 2;
|
||||||
|
FlameGraph flameGraph;
|
||||||
|
QStandardItemModel model;
|
||||||
|
DelegateComponent delegate;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QmlProfiler
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
SOURCES += \
|
SOURCES += \
|
||||||
$$PWD/debugmessagesmodel_test.cpp
|
$$PWD/debugmessagesmodel_test.cpp \
|
||||||
|
$$PWD/flamegraph_test.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/debugmessagesmodel_test.h
|
$$PWD/debugmessagesmodel_test.h \
|
||||||
|
$$PWD/flamegraph_test.h
|
||||||
|
|||||||
Reference in New Issue
Block a user