Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qctf.cpp
Go to the documentation of this file.
1
// Copyright (C) 2022 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
define
BUILD_LIBRARY
6
7
#
include
<
qthread
.
h
>
8
#
include
<
qpluginloader
.
h
>
9
#
include
<
qfileinfo
.
h
>
10
#
include
<
qdir
.
h
>
11
#
include
<
qtenvironmentvariables
.
h
>
12
#
include
<
qjsonarray
.
h
>
13
14
#
include
"qctf_p.h"
15
16
QT_BEGIN_NAMESPACE
17
18
using
namespace
Qt::StringLiterals;
19
20
static
bool
s_initialized
=
false
;
21
static
bool
s_triedLoading
=
false
;
22
static
bool
s_prevent_recursion
=
false
;
23
static
bool
s_shutdown
=
false
;
24
static
QCtfLib
*
s_plugin
=
nullptr
;
25
26
#
if
QT_CONFIG
(
library
)
&&
defined
(
QT_SHARED
)
27
28
#
if
defined
(
Q_OS_ANDROID
)
29
static
QString findPlugin(QLatin1StringView plugin)
30
{
31
const
QString pluginPath = qEnvironmentVariable(
"QT_PLUGIN_PATH"
);
32
for
(
const
auto
&entry : QDirListing(pluginPath, QDirListing::IteratorFlag::FilesOnly)) {
33
if
(entry.fileName().contains(plugin))
34
return
entry.absoluteFilePath();
35
}
36
return
{};
37
}
38
#
endif
39
40
static
bool
loadPlugin(
bool
&retry)
41
{
42
retry =
false
;
43
#
ifdef
Q_OS_WIN
44
#
ifdef
QT_DEBUG
45
QPluginLoader loader(QStringLiteral(
"tracing/QCtfTracePlugind.dll"
));
46
#
else
47
QPluginLoader loader(QStringLiteral(
"tracing/QCtfTracePlugin.dll"
));
48
#
endif
49
#
elif
defined
(
Q_OS_ANDROID
)
50
51
const
QString plugin = findPlugin(
"QCtfTracePlugin"_L1
);
52
if
(plugin.isEmpty()) {
53
retry =
true
;
54
return
false
;
55
}
56
QPluginLoader loader(plugin);
57
#
elif
defined
(
Q_OS_DARWIN
)
58
QPluginLoader loader(QStringLiteral(
"tracing/libQCtfTracePlugin.dylib"
));
59
#
else
60
QPluginLoader loader(QStringLiteral(
"tracing/libQCtfTracePlugin.so"
));
61
#
endif
62
63
if
(!loader.isLoaded()) {
64
if
(!loader.load())
65
return
false
;
66
}
67
s_plugin = qobject_cast<QCtfLib *>(loader.instance());
68
if
(!s_plugin)
69
return
false
;
70
s_plugin->shutdown(&s_shutdown);
71
return
true
;
72
}
73
74
#
else
75
76
#
define
QCtfPluginIID
QStringLiteral
(
"org.qt-project.Qt.QCtfLib"
)
77
78
static
bool
loadPlugin
(
bool
&retry)
79
{
80
retry =
false
;
81
const
auto
&plugins = QPluginLoader::staticPlugins();
82
for
(
const
auto
&plugin : plugins) {
83
const
auto
json = plugin.metaData();
84
const
auto
IID = json[QStringLiteral(
"IID"
)];
85
if
(IID.toString() ==
QCtfPluginIID
) {
86
s_plugin = qobject_cast<QCtfLib *>(plugin.instance());
87
if
(!s_plugin)
88
return
false
;
89
s_plugin->shutdown(&s_shutdown);
90
return
true
;
91
}
92
}
93
return
false
;
94
}
95
96
#
endif
97
98
static
bool
initialize
()
99
{
100
if
(
s_shutdown
||
s_prevent_recursion
)
101
return
false
;
102
if
(
s_initialized
||
s_triedLoading
)
103
return
s_initialized
;
104
s_prevent_recursion
=
true
;
105
bool
retry =
false
;
106
if
(!
loadPlugin
(
retry
)
) {
107
if
(!retry) {
108
s_triedLoading
=
true
;
109
s_initialized
=
false
;
110
}
111
}
else
{
112
bool
enabled = s_plugin->sessionEnabled();
113
if
(!enabled) {
114
s_triedLoading
=
true
;
115
s_initialized
=
false
;
116
}
else
{
117
s_initialized
=
true
;
118
}
119
}
120
s_prevent_recursion
=
false
;
121
return
s_initialized
;
122
}
123
124
bool
_tracepoint_enabled
(
const
QCtfTracePointEvent &point)
125
{
126
if
(!
initialize
(
)
)
127
return
false
;
128
return
s_plugin ? s_plugin->tracepointEnabled(point) :
false
;
129
}
130
131
void
_do_tracepoint
(
const
QCtfTracePointEvent &point,
const
QByteArray
&arr)
132
{
133
if
(!
initialize
(
)
)
134
return
;
135
if
(
s_plugin
)
136
s_plugin
->doTracepoint(point, arr);
137
}
138
139
QCtfTracePointPrivate
*
_initialize_tracepoint
(
const
QCtfTracePointEvent &point)
140
{
141
if
(!
initialize
(
)
)
142
return
nullptr
;
143
return
s_plugin ? s_plugin->initializeTracepoint(point) :
nullptr
;
144
}
145
146
QT_END_NAMESPACE
147
148
#
include
"moc_qctf_p.cpp"
QByteArray::FromBase64Result
\inmodule QtCore
Definition
qbytearray.h:824
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
s_prevent_recursion
static bool s_prevent_recursion
Definition
qctf.cpp:22
_tracepoint_enabled
bool _tracepoint_enabled(const QCtfTracePointEvent &point)
Definition
qctf.cpp:124
s_plugin
static QCtfLib * s_plugin
Definition
qctf.cpp:24
_do_tracepoint
void _do_tracepoint(const QCtfTracePointEvent &point, const QByteArray &arr)
Definition
qctf.cpp:131
s_shutdown
static bool s_shutdown
Definition
qctf.cpp:23
loadPlugin
static bool loadPlugin(bool &retry)
Definition
qctf.cpp:78
s_initialized
static bool s_initialized
Definition
qctf.cpp:20
_initialize_tracepoint
QCtfTracePointPrivate * _initialize_tracepoint(const QCtfTracePointEvent &point)
Definition
qctf.cpp:139
s_triedLoading
static bool s_triedLoading
Definition
qctf.cpp:21
QCtfPluginIID
#define QCtfPluginIID
Definition
qctf.cpp:76
initialize
static bool initialize()
Definition
qctf.cpp:98
QCtfTracePointPrivate
Definition
qctflib_p.h:36
qtbase
src
corelib
tracing
qctf.cpp
Generated on
for Qt by
1.18.0