KWin
Loading...
Searching...
No Matches
test_ftrace.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2021 David Edmundson <davidedmundson@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include <QObject>
11#include <QTemporaryFile>
12#include <QTest>
13
14#include "ftrace.h"
15
16class TestFTrace : public QObject
17{
18 Q_OBJECT
19public:
20 TestFTrace();
21private Q_SLOTS:
22 void benchmarkTraceOff();
23 void benchmarkTraceDurationOff();
24 void enable();
25
26private:
27 QTemporaryFile m_tempFile;
28};
29
31{
32 m_tempFile.open();
33 qputenv("KWIN_PERF_FTRACE_FILE", m_tempFile.fileName().toLatin1());
34
35 KWin::FTraceLogger::create();
36}
37
38void TestFTrace::benchmarkTraceOff()
39{
40 // this macro should no-op, so take no time at all
41 QBENCHMARK {
42 fTrace("BENCH", 123, "foo");
43 }
44}
45
46void TestFTrace::benchmarkTraceDurationOff()
47{
48 QBENCHMARK {
49 fTraceDuration("BENCH", 123, "foo");
50 }
51}
52
53void TestFTrace::enable()
54{
55 KWin::FTraceLogger::self()->setEnabled(true);
56 QVERIFY(KWin::FTraceLogger::self()->isEnabled());
57
58 {
59 fTrace("TEST", 123, "foo");
60 fTraceDuration("TEST_DURATION", "boo");
61 fTrace("TEST", 123, "foo");
62 }
63
64 QCOMPARE(m_tempFile.readLine(), "TEST123foo\n");
65 QCOMPARE(m_tempFile.readLine(), "TEST_DURATIONboo begin_ctx=1\n");
66 QCOMPARE(m_tempFile.readLine(), "TEST123foo\n");
67 QCOMPARE(m_tempFile.readLine(), "TEST_DURATIONboo end_ctx=1\n");
68}
69
71
72#include "test_ftrace.moc"
#define fTraceDuration(...)
Definition ftrace.h:106
#define fTrace(...)
Definition ftrace.h:98
QTEST_MAIN(OnScreenNotificationTest)