KWin
Loading...
Searching...
No Matches
src
ftrace.h
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
#pragma once
11
12
#include "
effect/globals.h
"
13
14
#include <QFile>
15
#include <QMutex>
16
#include <QMutexLocker>
17
#include <QObject>
18
#include <QTextStream>
19
20
namespace
KWin
21
{
30
class
KWIN_EXPORT
FTraceLogger
:
public
QObject
31
{
32
Q_OBJECT
33
Q_CLASSINFO(
"D-Bus Interface"
,
"org.kde.kwin.FTrace"
);
34
Q_PROPERTY(
bool
isEnabled READ isEnabled NOTIFY enabledChanged)
35
36
public
:
40
bool
isEnabled()
const
;
41
46
template
<
typename
... Args>
47
void
trace
(Args... args)
48
{
49
Q_ASSERT(isEnabled());
50
QMutexLocker lock(&m_mutex);
51
if
(!m_file.isOpen()) {
52
return
;
53
}
54
QTextStream stream(&m_file);
55
(stream << ... << args) << Qt::endl;
56
}
57
58
Q_SIGNALS:
59
void
enabledChanged
();
60
61
public
Q_SLOTS:
62
Q_SCRIPTABLE
void
setEnabled(
bool
enabled);
63
64
private
:
65
static
QString filePath();
66
bool
open();
67
QFile m_file;
68
QMutex m_mutex;
69
KWIN_SINGLETON
(
FTraceLogger
)
70
};
71
72
class
KWIN_EXPORT
FTraceDuration
73
{
74
public
:
75
template
<
typename
... Args>
76
FTraceDuration
(Args... args)
77
{
78
static
QAtomicInteger<quint32> s_context = 0;
79
QTextStream stream(&m_message);
80
(stream << ... << args);
81
stream.flush();
82
m_context = ++s_context;
83
FTraceLogger::self()->trace(m_message,
" begin_ctx="
, m_context);
84
}
85
86
~FTraceDuration
();
87
88
private
:
89
QByteArray m_message;
90
quint32 m_context;
91
};
92
93
}
// namespace KWin
94
98
#define fTrace(...) \
99
if (KWin::FTraceLogger::self()->isEnabled()) \
100
KWin::FTraceLogger::self()->trace(__VA_ARGS__);
101
106
#define fTraceDuration(...) \
107
std::unique_ptr<KWin::FTraceDuration> _duration(KWin::FTraceLogger::self()->isEnabled() ? new KWin::FTraceDuration(__VA_ARGS__) : nullptr);
KWin::FTraceDuration
Definition
ftrace.h:73
KWin::FTraceDuration::FTraceDuration
FTraceDuration(Args... args)
Definition
ftrace.h:76
KWin::FTraceLogger
Definition
ftrace.h:31
KWin::FTraceLogger::trace
void trace(Args... args)
Definition
ftrace.h:47
KWin::FTraceLogger::enabledChanged
void enabledChanged()
globals.h
KWIN_SINGLETON
#define KWIN_SINGLETON(ClassName)
Definition
globals.h:323
KWin
Definition
activation_test.cpp:20
Generated on Sat Feb 17 2024 01:42:09 for KWin by
1.10.0