Commit 87aa1652 authored by Manon Linder's avatar Manon Linder
Browse files

Remove TestBenchmark and TestBenchmark_NoDebug

Replace them by Sample/3_Benchmark
Can add QT_NO_DEBUG_OUTPUT for Benchmark
parent 2a82583b
......@@ -4,11 +4,10 @@ SUBDIRS += modmedLog \
TestData \
TestLogger \
TestLogger_exe \
TestBenchmark \
TestBenchmark_NoDebug \
# torrent \
1_HowToLog \
2_HowToLogUserData \
3_Benchmark \
# scripts
CONFIG += debug_and_release
......@@ -24,17 +23,14 @@ TestLogger.depends = modmedLog
TestLogger_exe.subdir = tests/TestLogger_exe
TestLogger_exe.depends = modmedLog
TestBenchmark.subdir = tests/TestBenchmark
TestBenchmark.depends = modmedLog
TestBenchmark_NoDebug.subdir = tests/TestBenchmark_NoDebug
TestBenchmark_NoDebug.depends = modmedLog
1_HowToLog.subdir = samples/1_HowToLog
1_HowToLog.depends = modmedLog
2_HowToLogUserData.subdir = samples/2_HowToLogUserData
2_HowToLogUserData.depends = modmedLog
3_Benchmark.subdir = samples/3_Benchmark
3_Benchmark.depends = modmedLog
torrent.subdir = samples/torrent
torrent.depends = modmedLog
QT += testlib core
QT += core network
QT -= gui
TEMPLATE = app
TARGET = TestBenchmark
CONFIG += c++11 console debug_and_release
CONFIG -= app_bundle
TARGET = 3_Benchmark
CONFIG += c++11 debug_and_release
CONFIG -= app_bundle console
INCLUDEPATH += ../../include
......@@ -20,16 +20,12 @@ CONFIG(debug, debug|release) {
CONFIG(debug, debug|release) { unix:QMAKE_RPATHDIR += $$_PRO_FILE_PWD_/../../lib/Debug }
else { unix:QMAKE_RPATHDIR += $$_PRO_FILE_PWD_/../../lib/Release }
CONFIG(release, debug|release) { DEFINES += QT_MESSAGELOGCONTEXT }
CONFIG(release, debug|release) { DEFINES += QT_MESSAGELOGCONTEXT}
LIBS += -lmodmedLog
HEADERS += \
TestBenchmark.h \
../Common/ConsoleLogWriterBenchmark.h
SOURCES += main.cpp
SOURCES += \
main.cpp \
TestBenchmark.cpp
HEADERS += ConsoleLogWriterBenchmark.h\
include(../../modmedLog.pri)
This diff is collapsed.
This diff is collapsed.
/****************************************************************************
* **
* ** Copyright (C) 2016 MinMaxMedical.
* ** All rights reserved.
* ** Contact: MinMaxMedical <InCAS@MinMaxMedical.com>
* **
* ** This file is part of the modmedLog module.
* **
* ** $QT_BEGIN_LICENSE:BSD$
* ** You may use this file under the terms of the BSD license as follows:
* **
* ** "Redistribution and use in source and binary forms, with or without
* ** modification, are permitted provided that the following conditions are
* ** met:
* ** * Redistributions of source code must retain the above copyright
* ** notice, this list of conditions and the following disclaimer.
* ** * Redistributions in binary form must reproduce the above copyright
* ** notice, this list of conditions and the following disclaimer in
* ** the documentation and/or other materials provided with the
* ** distribution.
* ** * Neither the name of MinMaxMedical S.A.S. and its Subsidiary(-ies) nor
* ** the names of its contributors may be used to endorse or promote
* ** products derived from this software without specific prior written
* ** permission.
* **
* ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
* ** $QT_END_LICENSE$
* **
* ****************************************************************************/
#pragma once
#include <QtCore/qobject.h>
#include <modmed/log/LogEvent.h>
#include <modmed/log/LogMessage.h>
using namespace modmed;
using namespace log;
namespace _ {
M_NAMESPACE_LOG_CATEGORY()
}
class TestBenchmark : public QObject
{
Q_OBJECT
// Compare bind with JsonWriter, XmlWriter, CborWriter
Q_SLOT void Bind_Benchmark_01(); // with various data
Q_SLOT void Bind_Benchmark_01_data();
Q_SLOT void Bind_Benchmark_02(); // with numbers
Q_SLOT void Bind_Benchmark_02_data();
// Compare LogMessage with JsonWriter, XmlWriter, CborWriter and with various data
Q_SLOT void LogMessage_Benchmark_01(); // no args
Q_SLOT void LogMessage_Benchmark_01_data();
Q_SLOT void LogMessage_Benchmark_02(); // various args
Q_SLOT void LogMessage_Benchmark_02_data();
Q_SLOT void LogMessage_Benchmark_03(); // numbers
Q_SLOT void LogMessage_Benchmark_03_data();
// Compare LogEvent with LogWriter (Json, Xml), TsvJsonLogWriter, LttngLogWriter
Q_SLOT void Event_Benchmark_01(); // To files + various args
Q_SLOT void Event_Benchmark_01_data();
Q_SLOT void Event_Benchmark_02(); // To files + double args
Q_SLOT void Event_Benchmark_02_data();
Q_SLOT void Event_Console_Benchmark_01(); // To console + just text
Q_SLOT void Event_Console_Benchmark_01_data();
Q_SLOT void Event_Console_Benchmark_02(); // To console + various args
Q_SLOT void Event_Console_Benchmark_02_data();
Q_SLOT void Event_Console_Benchmark_03(); // To console + double
Q_SLOT void Event_Console_Benchmark_03_data();
};
/****************************************************************************
* **
* ** Copyright (C) 2016 MinMaxMedical.
* ** All rights reserved.
* ** Contact: MinMaxMedical <InCAS@MinMaxMedical.com>
* **
* ** This file is part of the modmedLog module.
* **
* ** $QT_BEGIN_LICENSE:BSD$
* ** You may use this file under the terms of the BSD license as follows:
* **
* ** "Redistribution and use in source and binary forms, with or without
* ** modification, are permitted provided that the following conditions are
* ** met:
* ** * Redistributions of source code must retain the above copyright
* ** notice, this list of conditions and the following disclaimer.
* ** * Redistributions in binary form must reproduce the above copyright
* ** notice, this list of conditions and the following disclaimer in
* ** the documentation and/or other materials provided with the
* ** distribution.
* ** * Neither the name of MinMaxMedical S.A.S. and its Subsidiary(-ies) nor
* ** the names of its contributors may be used to endorse or promote
* ** products derived from this software without specific prior written
* ** permission.
* **
* ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
* ** $QT_END_LICENSE$
* **
* ****************************************************************************/
#include <QtTest/qtest.h>
#include "TestBenchmark.h"
QTEST_APPLESS_MAIN(TestBenchmark);
/****************************************************************************
* **
* ** Copyright (C) 2016 MinMaxMedical.
* ** All rights reserved.
* ** Contact: MinMaxMedical <InCAS@MinMaxMedical.com>
* **
* ** This file is part of the modmedLog module.
* **
* ** $QT_BEGIN_LICENSE:BSD$
* ** You may use this file under the terms of the BSD license as follows:
* **
* ** "Redistribution and use in source and binary forms, with or without
* ** modification, are permitted provided that the following conditions are
* ** met:
* ** * Redistributions of source code must retain the above copyright
* ** notice, this list of conditions and the following disclaimer.
* ** * Redistributions in binary form must reproduce the above copyright
* ** notice, this list of conditions and the following disclaimer in
* ** the documentation and/or other materials provided with the
* ** distribution.
* ** * Neither the name of MinMaxMedical S.A.S. and its Subsidiary(-ies) nor
* ** the names of its contributors may be used to endorse or promote
* ** products derived from this software without specific prior written
* ** permission.
* **
* ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
* ** $QT_END_LICENSE$
* **
* ****************************************************************************/
#include "TestBenchmark.h"
#include <QtTest/qtest.h>
#include <QtCore/qbuffer.h>
#include <QtCore/qstring.h>
#include <modmed/data/JsonWriter.h>
#include <modmed/data/XmlWriter.h>
#include <modmed/data/CborWriter.h>
#include <modmed/log/LogManager.h>
#include <modmed/log/LogEvent.h>
#include <modmed/log/LogMessage.h>
#include <modmed/log/TsvJsonLogWriter.h>
#include <modmed/log/LogWriter.h>
#ifdef Q_OS_UNIX
#include <modmed/log/LttngLogWriter.h>
#include <modmed/log/JournaldWriter.h>
#endif
#ifdef Q_CC_MSVC
#include <modmed/log/EtlLogWriter.h>
#endif
#include <../Common/ConsoleLogWriterBenchmark.h>
void TestBenchmark::Event_Benchmark_01_data()
{
QTest::addColumn<int>("tracepoint");
QTest::newRow("QDebug") << 0;
QTest::newRow("QDebug+Context") << 1;
QTest::newRow("TsvJson") << 2;
QTest::newRow("LogWriter + Json") << 3;
QTest::newRow("LogWriter + Xml") << 4;
#ifdef Q_OS_UNIX
QTest::newRow("Lttng") << 5;
QTest::newRow("Journald") << 6;
#elif Q_CC_MSVC
QTest::newRow("Etl") << 5;
#endif
}
void TestBenchmark::Event_Benchmark_01()
{
QFETCH(int, tracepoint);
QTemporaryDir tmpDir;
QString msg(QStringLiteral("a message can contain free text with spaces at the end"));
if (0==tracepoint)
{
QFile s(tmpDir.path() + "_qt.log");
s.open(QIODevice::WriteOnly);
QBENCHMARK
{
QDebug(&s)
<< "free text"
<< "number"
<< 2
<< "text with atomic data types"
<< true
<< 1.23f
<< msg
;
}
}
else if (1==tracepoint)
{
qSetMessagePattern("[%{time} %{type} %{category} %{file}(%{line}) %{function} %{threadid} %{message}");
QFile s(tmpDir.path() + "_qtContext.log");
s.open(QIODevice::WriteOnly);
QBENCHMARK
{
QDebug(&s) << qFormatLogMessage(QtDebugMsg, QMessageLogContext(), "")
<< "free text"
<< "number"
<< 2
<< "text with atomic data types"
<< true
<< 1.23f
<< msg
;
}
}
else if (2==tracepoint)
{
QFile logFile(tmpDir.path() + "_tsvjson.tsv");
if (!logFile.open(QIODevice::WriteOnly|QIODevice::Truncate))
QFAIL("");
QTextStream sfile(&logFile);
TsvJsonLogWriter writer(&sfile);
LogManager::getInstance().setOutput(&writer);
QBENCHMARK {
mDebug()
<< "free text"
<< "number"
<< 2
<< "text with atomic data types"
<< true
<< 1.23f
<< msg
;
}
}
else if (3==tracepoint)
{
QFile logFile(tmpDir.path() + "_log.json");
if (!logFile.open(QIODevice::WriteOnly|QIODevice::Truncate))
QFAIL("");
QTextStream sfile(&logFile);
LogWriter<data::JsonWriter> writer(&sfile);
LogManager::getInstance().setOutput(&writer);
QBENCHMARK {
mDebug()
<< "free text"
<< "number"
<< 2
<< "text with atomic data types"
<< true
<< 1.23f
<< msg
;
}
}
else if (4==tracepoint)
{
QFile logFile(tmpDir.path() + "_log.xml");
if (!logFile.open(QIODevice::WriteOnly|QIODevice::Truncate))
QFAIL("");
QTextStream sfile(&logFile);
LogWriter<data::XmlWriter> writer(&sfile);
LogManager::getInstance().setOutput(&writer);
QBENCHMARK {
mDebug()
<< "free text"
<< "number"
<< 2
<< "text with atomic data types"
<< true
<< 1.23f
<< msg
;
}
}
else if (5==tracepoint)
{
#ifdef Q_OS_UNIX
log::LttngLogWriter writer;
LogManager::getInstance().setOutput(&writer);
#elif Q_CC_MSVC
log::EtlLogWriter writer;
LogManager::getInstance().setOutput(&writer);
#endif
QBENCHMARK {
mDebug()
<< "free text"
<< "number"
<< 2
<< "text with atomic data types"
<< true
<< 1.23f
<< msg
;
}
}
else if (6==tracepoint)
{
#ifdef Q_OS_UNIX
log::JournaldWriter writer;
LogManager::getInstance().setOutput(&writer);
#endif
QBENCHMARK {
mDebug()
<< "free text"
<< "number"
<< 2
<< "text with atomic data types"
<< true
<< 1.23f
<< msg
;
}
}
// reset log output
LogManager::getInstance().setOutput(nullptr);
}
void TestBenchmark::Event_Benchmark_02_data()
{
QTest::addColumn<int>("tracepoint");
QTest::newRow("QDebug") << 0;
QTest::newRow("QDebug+Context") << 1;
QTest::newRow("TsvJson") << 2;
QTest::newRow("LogWriter + Json") << 3;
QTest::newRow("LogWriter + Xml") << 4;
#ifdef Q_OS_UNIX
QTest::newRow("Lttng") << 5;
QTest::newRow("Journald") << 6;
#elif Q_CC_MSVC
QTest::newRow("Etl") << 5;
#endif
}
void TestBenchmark::Event_Benchmark_02()
{
QTemporaryDir tmpDir;
double mat[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16.};
QFETCH(int, tracepoint);
if (0==tracepoint)
{
QFile s(tmpDir.path() + "_qt.log");
s.open(QIODevice::WriteOnly);
QBENCHMARK
{
QDebug(&s)
<< mat[0] << mat[1] << mat[2] << mat[3]
<< mat[4] << mat[5] << mat[6] << mat[7]
<< mat[8] << mat[9] << mat[10] << mat[11]
<< mat[12] << mat[13] << mat[14] << mat[15];
;
}
}
else if (1==tracepoint)
{
qSetMessagePattern("[%{time} %{type} %{category} %{file}(%{line}) %{function} %{threadid} %{message}");
QFile s(tmpDir.path() + "_qtContext.log");
s.open(QIODevice::WriteOnly);
QBENCHMARK {
QDebug(&s) << qFormatLogMessage(QtDebugMsg, QMessageLogContext(), "")
<< mat[0] << mat[1] << mat[2] << mat[3]
<< mat[4] << mat[5] << mat[6] << mat[7]
<< mat[8] << mat[9] << mat[10] << mat[11]
<< mat[12] << mat[13] << mat[14] << mat[15];
;
}
}
else if (2==tracepoint)
{
QFile logFile(tmpDir.path() + "_tsvjson.tsv");
if (!logFile.open(QIODevice::WriteOnly|QIODevice::Truncate))
QFAIL("");
QTextStream sfile(&logFile);
TsvJsonLogWriter writer(&sfile);
LogManager::getInstance().setOutput(&writer);
QBENCHMARK {
mDebug() << mat;
}
}
else if (3==tracepoint)
{
QFile logFile(tmpDir.path() + "_log.tsv");
if (!logFile.open(QIODevice::WriteOnly|QIODevice::Truncate))
QFAIL("");
QTextStream sfile(&logFile);
LogWriter<data::JsonWriter> writer(&sfile);
LogManager::getInstance().setOutput(&writer);
QBENCHMARK {
mDebug() << mat;
}
}
else if (4==tracepoint)
{
QFile logFile(tmpDir.path() + "_log.xml");
if (!logFile.open(QIODevice::WriteOnly|QIODevice::Truncate))
QFAIL("");
QTextStream sfile(&logFile);
LogWriter<data::XmlWriter> writer(&sfile);
LogManager::getInstance().setOutput(&writer);
QBENCHMARK {
mDebug() << mat;
}
}
else if (5==tracepoint)
{
#ifdef Q_OS_UNIX
log::LttngLogWriter writer;
LogManager::getInstance().setOutput(&writer);
#elif Q_CC_MSVC
log::EtlLogWriter writer;
LogManager::getInstance().setOutput(&writer);
#endif
QBENCHMARK {
mDebug() << mat;
}
}
else if (6==tracepoint)
{
#ifdef Q_OS_UNIX
log::JournaldWriter writer;
LogManager::getInstance().setOutput(&writer);
#endif
QBENCHMARK {
mDebug() << mat;
}
}
// reset log output
LogManager::getInstance().setOutput(nullptr);
}
void TestBenchmark::Event_Console_Benchmark_01_data()
{
QTest::addColumn<int>("tracepoint");
QTest::newRow("QDebug") << 0;
QTest::newRow("ConsoleWriter") << 1;
}
void TestBenchmark::Event_Console_Benchmark_01()
{
QFETCH(int, tracepoint);
if (0==tracepoint)
{
qSetMessagePattern("%{type} | %{message}");
QBENCHMARK
{
qDebug() << "free text";
}
}
else if (1==tracepoint)
{
modmed::log::ConsoleLogWriterBenchmark writer(false); // Use stderr output for testing purpose
modmed::log::LogManager::getInstance().setOutput(&writer);
QBENCHMARK {
mDebug() << "free text";
}
}
}
void TestBenchmark::Event_Console_Benchmark_02_data()
{
QTest::addColumn<int>("tracepoint");
QTest::newRow("QDebug") << 0;
QTest::newRow("ConsoleWriter") << 1;
}
void TestBenchmark::Event_Console_Benchmark_02()
{
QFETCH(int, tracepoint);
QString msg(QStringLiteral("a message can contain free text with spaces at the end"));
if (0==tracepoint)
{
qSetMessagePattern("%{type} | %{message}");
QBENCHMARK
{
qDebug()
<< "free text"