File indexing completed on 2024-11-10 04:56:24
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2021 David Edmundson <davidedmundson@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include <QObject> 0011 #include <QTemporaryFile> 0012 #include <QTest> 0013 0014 #include "ftrace.h" 0015 0016 class TestFTrace : public QObject 0017 { 0018 Q_OBJECT 0019 public: 0020 TestFTrace(); 0021 private Q_SLOTS: 0022 void benchmarkTraceOff(); 0023 void benchmarkTraceDurationOff(); 0024 void enable(); 0025 0026 private: 0027 QTemporaryFile m_tempFile; 0028 }; 0029 0030 TestFTrace::TestFTrace() 0031 { 0032 m_tempFile.open(); 0033 qputenv("KWIN_PERF_FTRACE_FILE", m_tempFile.fileName().toLatin1()); 0034 0035 KWin::FTraceLogger::create(); 0036 } 0037 0038 void TestFTrace::benchmarkTraceOff() 0039 { 0040 // this macro should no-op, so take no time at all 0041 QBENCHMARK { 0042 fTrace("BENCH", 123, "foo"); 0043 } 0044 } 0045 0046 void TestFTrace::benchmarkTraceDurationOff() 0047 { 0048 QBENCHMARK { 0049 fTraceDuration("BENCH", 123, "foo"); 0050 } 0051 } 0052 0053 void TestFTrace::enable() 0054 { 0055 KWin::FTraceLogger::self()->setEnabled(true); 0056 QVERIFY(KWin::FTraceLogger::self()->isEnabled()); 0057 0058 { 0059 fTrace("TEST", 123, "foo"); 0060 fTraceDuration("TEST_DURATION", "boo"); 0061 fTrace("TEST", 123, "foo"); 0062 } 0063 0064 QCOMPARE(m_tempFile.readLine(), "TEST123foo\n"); 0065 QCOMPARE(m_tempFile.readLine(), "TEST_DURATIONboo begin_ctx=1\n"); 0066 QCOMPARE(m_tempFile.readLine(), "TEST123foo\n"); 0067 QCOMPARE(m_tempFile.readLine(), "TEST_DURATIONboo end_ctx=1\n"); 0068 } 0069 0070 QTEST_MAIN(TestFTrace) 0071 0072 #include "test_ftrace.moc"