1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-22 02:32:29 +01:00

Add benchmark and doctest metrics

This commit is contained in:
Elias Steurer 2020-10-30 16:40:16 +01:00
parent 927973868e
commit dcc7986ff9
7 changed files with 71 additions and 2 deletions

View File

@ -2,6 +2,7 @@ stages:
- check - check
- build - build
- test - test
- benchmark
check: check:
stage: check stage: check
@ -125,6 +126,24 @@ test:windows_release:
when: always when: always
reports: reports:
junit: test-report-junit.xml junit: test-report-junit.xml
benchmark:windows_release:
stage: benchmark
tags:
- windows10
- vs2019
dependencies:
- build:windows_release
needs:
- build:windows_release
script:
- ./build-x64-window-release/bin/ScreenPlay.exe --benchmark
artifacts:
expire_in: '4 weeks'
when: always
reports:
metrics: metrics.txt
build_docs: build_docs:

View File

@ -0,0 +1,7 @@
### Continous Inegration
##### Code Checks
##### Benchmarks
##### Unit tests

View File

@ -43,6 +43,9 @@ namespace ScreenPlay {
App::App() App::App()
: QObject(nullptr) : QObject(nullptr)
{ {
m_continuousIntegrationMetricsTimer.start();
QGuiApplication::setWindowIcon(QIcon(":/assets/icons/app.ico")); QGuiApplication::setWindowIcon(QIcon(":/assets/icons/app.ico"));
QGuiApplication::setOrganizationName("ScreenPlay"); QGuiApplication::setOrganizationName("ScreenPlay");
QGuiApplication::setOrganizationDomain("screen-play.app"); QGuiApplication::setOrganizationDomain("screen-play.app");
@ -120,6 +123,7 @@ App::App()
// ScreenPlayManager first to check if another ScreenPlay Instace is running // ScreenPlayManager first to check if another ScreenPlay Instace is running
m_screenPlayManager = std::make_unique<ScreenPlayManager>(); m_screenPlayManager = std::make_unique<ScreenPlayManager>();
m_isAnotherScreenPlayInstanceRunning = m_screenPlayManager->isAnotherScreenPlayInstanceRunning(); m_isAnotherScreenPlayInstanceRunning = m_screenPlayManager->isAnotherScreenPlayInstanceRunning();
Util::appendToMetricsFile("screenplay_app_constructor", m_continuousIntegrationMetricsTimer.msecsSinceReference());
} }
/*! /*!
@ -130,6 +134,9 @@ App::App()
*/ */
void App::init() void App::init()
{ {
Util::appendToMetricsFile("screenplay_app_init", m_continuousIntegrationMetricsTimer.msecsSinceReference());
using std::make_shared, std::make_unique; using std::make_shared, std::make_unique;
// Util should be created as first so we redirect qDebugs etc. into the log // Util should be created as first so we redirect qDebugs etc. into the log
@ -187,8 +194,9 @@ void App::init()
} }
qmlRegisterSingletonInstance("ScreenPlay", 1, 0, "ScreenPlay", this); qmlRegisterSingletonInstance("ScreenPlay", 1, 0, "ScreenPlay", this);
Util::appendToMetricsFile("Screenplay_app_qqmlapplicationengine_load_begin", m_continuousIntegrationMetricsTimer.msecsSinceReference());
m_mainWindowEngine->load(QUrl(QStringLiteral("qrc:/main.qml"))); m_mainWindowEngine->load(QUrl(QStringLiteral("qrc:/main.qml")));
Util::appendToMetricsFile("Screenplay_app_qqmlapplicationengine_load_end", m_continuousIntegrationMetricsTimer.msecsSinceReference());
} }
/*! /*!

View File

@ -35,6 +35,7 @@
#pragma once #pragma once
#include <QDir> #include <QDir>
#include <QElapsedTimer>
#include <QIcon> #include <QIcon>
#include <QObject> #include <QObject>
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
@ -252,6 +253,7 @@ public slots:
private: private:
QPluginLoader m_workshopPlugin; QPluginLoader m_workshopPlugin;
QNetworkAccessManager m_networkAccessManager; QNetworkAccessManager m_networkAccessManager;
QElapsedTimer m_continuousIntegrationMetricsTimer;
std::unique_ptr<QQmlApplicationEngine> m_mainWindowEngine; std::unique_ptr<QQmlApplicationEngine> m_mainWindowEngine;
std::unique_ptr<Create> m_create; std::unique_ptr<Create> m_create;

View File

@ -34,10 +34,15 @@
#include "app.h" #include "app.h"
#include <QApplication> #include <QApplication>
#include <QCommandLineParser>
#include <QDebug> #include <QDebug>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <sentry.h> #include <sentry.h>
#endif #endif
#define DOCTEST_CONFIG_IMPLEMENT
#define DOCTEST_CONFIG_SUPER_FAST_ASSERTS
#include <doctest/doctest.h>
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
@ -52,6 +57,12 @@ int main(int argc, char* argv[])
QApplication qtGuiApp(argc, argv); QApplication qtGuiApp(argc, argv);
if (QGuiApplication::arguments().contains("--benchmark")) {
QFile metricsFile { QGuiApplication::applicationDirPath() + "/metrics.txt" };
if (metricsFile.exists())
qInfo() << "Removing old Continuous Integration Metrics Timer: " << metricsFile.remove();
}
ScreenPlay::App app; ScreenPlay::App app;
if (app.m_isAnotherScreenPlayInstanceRunning) { if (app.m_isAnotherScreenPlayInstanceRunning) {

View File

@ -168,13 +168,34 @@ QString Util::toString(const QStringList& list)
return out; return out;
} }
void Util::appendToMetricsFile(const QString& key, const QVariant& value)
{
if (!QGuiApplication::arguments().contains("--benchmark"))
return;
const QString appDir = QGuiApplication::applicationDirPath();
QFile metricsFile { appDir + "/metrics.txt" };
if (!metricsFile.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
qWarning() << "Cannot open metrix file:" << appDir << metricsFile.fileName();
return;
}
QString text = key + "\t" + value.toString() + "\n";
QTextStream out(&metricsFile);
out << text;
metricsFile.flush();
metricsFile.close();
}
/*! /*!
\brief Parses a QByteArray to a QJsonObject. If returns and std::nullopt on failure. \brief Parses a QByteArray to a QJsonObject. If returns and std::nullopt on failure.
*/ */
std::optional<QJsonObject> Util::parseQByteArrayToQJsonObject(const QByteArray& byteArray) std::optional<QJsonObject> Util::parseQByteArrayToQJsonObject(const QByteArray& byteArray)
{ {
QJsonObject obj; QJsonObject obj;
QJsonParseError err; QJsonParseError err {};
QJsonDocument doc = QJsonDocument::fromJson(byteArray, &err); QJsonDocument doc = QJsonDocument::fromJson(byteArray, &err);
if (err.error == QJsonParseError::NoError) { if (err.error == QJsonParseError::NoError) {

View File

@ -113,6 +113,7 @@ public slots:
static std::optional<QVersionNumber> getVersionNumberFromString(const QString& str); static std::optional<QVersionNumber> getVersionNumberFromString(const QString& str);
static bool writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObject& object, bool truncate = true); static bool writeJsonObjectToFile(const QString& absoluteFilePath, const QJsonObject& object, bool truncate = true);
static QString toString(const QStringList& list); static QString toString(const QStringList& list);
static void appendToMetricsFile(const QString& key, const QVariant& value);
static void logToGui(QtMsgType type, const QMessageLogContext& context, const QString& msg); static void logToGui(QtMsgType type, const QMessageLogContext& context, const QString& msg);
static QString generateRandomString(quint32 length = 32); static QString generateRandomString(quint32 length = 32);