kwin/autotests/test_ftrace.cpp
David Edmundson 85d04cf60d Add ftrace markers
This logs to a tracefs filesystem which can be viewed in tools such as
gpuvis to see precise timings of activities in relation to other trace
markers in X or graphic drivers.

This patch is loosely based on D23114. Though modified with thread
safety, support for string building, and a RAII pattern for durations.
Ultimately that expanded it somewhat.
2021-01-14 09:31:59 +00:00

72 lines
1.5 KiB
C++

/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2021 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include <QObject>
#include <QTemporaryFile>
#include <QTest>
#include "ftrace.h"
class TestFTrace : public QObject
{
Q_OBJECT
public:
TestFTrace();
private Q_SLOTS:
void benchmarkTraceOff();
void benchmarkTraceDurationOff();
void enable();
private:
QTemporaryFile m_tempFile;
};
TestFTrace::TestFTrace()
{
m_tempFile.open();
qputenv("KWIN_PERF_FTRACE_FILE", m_tempFile.fileName().toLatin1());
KWin::FTraceLogger::create();
}
void TestFTrace::benchmarkTraceOff()
{
// this macro should no-op, so take no time at all
QBENCHMARK {
fTrace("BENCH", 123, "foo");
}
}
void TestFTrace::benchmarkTraceDurationOff()
{
QBENCHMARK {
fTraceDuration("BENCH", 123, "foo");
}
}
void TestFTrace::enable()
{
KWin::FTraceLogger::self()->setEnabled(true);
QVERIFY(KWin::FTraceLogger::self()->isEnabled());
{
fTrace("TEST", 123, "foo");
fTraceDuration("TEST_DURATION", "boo");
fTrace("TEST", 123, "foo");
}
QCOMPARE(m_tempFile.readLine(), "TEST123foo\n");
QCOMPARE(m_tempFile.readLine(), "TEST_DURATIONboo begin_ctx=1\n");
QCOMPARE(m_tempFile.readLine(), "TEST123foo\n");
QCOMPARE(m_tempFile.readLine(), "TEST_DURATIONboo end_ctx=1\n");
}
QTEST_MAIN(TestFTrace)
#include "test_ftrace.moc"