Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#define BUILD_LIBRARY
5
6#include <qthread.h>
7#include <qpluginloader.h>
8#include <qfileinfo.h>
9#include <qdir.h>
10#include <qjsonarray.h>
11
12#include "qctf_p.h"
13
15
16static bool s_initialized = false;
17static bool s_triedLoading = false;
18static bool s_prevent_recursion = false;
19static bool s_shutdown = false;
20static QCtfLib* s_plugin = nullptr;
21
22#if QT_CONFIG(library) && defined(QT_SHARED)
23
24#if defined(Q_OS_ANDROID)
25static QString findPlugin(const QString &plugin)
26{
27 QString pluginPath = QString::fromUtf8(qgetenv("QT_PLUGIN_PATH"));
28 QDir dir(pluginPath);
29 const QStringList files = dir.entryList(QDir::Files);
30 for (const QString &file : files) {
31 if (file.contains(plugin))
32 return QFileInfo(pluginPath + QLatin1Char('/') + file).absoluteFilePath();
33 }
34 return {};
35}
36#endif
37
38static bool loadPlugin(bool &retry)
39{
40 retry = false;
41#ifdef Q_OS_WIN
42#ifdef QT_DEBUG
43 QPluginLoader loader(QStringLiteral("tracing/QCtfTracePlugind.dll"));
44#else
45 QPluginLoader loader(QStringLiteral("tracing/QCtfTracePlugin.dll"));
46#endif
47#elif defined(Q_OS_ANDROID)
48
49 QString plugin = findPlugin(QStringLiteral("QCtfTracePlugin"));
50 if (plugin.isEmpty()) {
51 retry = true;
52 return false;
53 }
54 QPluginLoader loader(plugin);
55#else
56 QPluginLoader loader(QStringLiteral("tracing/libQCtfTracePlugin.so"));
57#endif
58
59 if (!loader.isLoaded()) {
60 if (!loader.load())
61 return false;
62 }
63 s_plugin = qobject_cast<QCtfLib *>(loader.instance());
64 if (!s_plugin)
65 return false;
66 s_plugin->shutdown(&s_shutdown);
67 return true;
68}
69
70#else
71
72#define QCtfPluginIID QStringLiteral("org.qt-project.Qt.QCtfLib")
73
74static bool loadPlugin(bool &retry)
75{
76 retry = false;
77 const auto &plugins = QPluginLoader::staticPlugins();
78 for (const auto &plugin : plugins) {
79 const auto json = plugin.metaData();
80 const auto IID = json[QStringLiteral("IID")];
81 if (IID.toString() == QCtfPluginIID) {
82 s_plugin = qobject_cast<QCtfLib *>(plugin.instance());
83 if (!s_plugin)
84 return false;
85 s_plugin->shutdown(&s_shutdown);
86 return true;
87 }
88 }
89 return false;
90}
91
92#endif
93
94static bool initialize()
95{
97 return false;
99 return s_initialized;
100 s_prevent_recursion = true;
101 bool retry = false;
102 if (!loadPlugin(retry)) {
103 if (!retry) {
104 s_triedLoading = true;
105 s_initialized = false;
106 }
107 } else {
108 bool enabled = s_plugin->sessionEnabled();
109 if (!enabled) {
110 s_triedLoading = true;
111 s_initialized = false;
112 } else {
113 s_initialized = true;
114 }
115 }
116 s_prevent_recursion = false;
117 return s_initialized;
118}
119
121{
122 if (!initialize())
123 return false;
124 return s_plugin ? s_plugin->tracepointEnabled(point) : false;
125}
126
127void _do_tracepoint(const QCtfTracePointEvent &point, const QByteArray &arr)
128{
129 if (!initialize())
130 return;
131 if (s_plugin)
132 s_plugin->doTracepoint(point, arr);
133}
134
136{
137 if (!initialize())
138 return nullptr;
139 return s_plugin ? s_plugin->initializeTracepoint(point) : nullptr;
140}
141
143
144#include "moc_qctf_p.cpp"
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qdir.h:20
@ Files
Definition qdir.h:23
static QList< QStaticPlugin > staticPlugins()
Returns a list of QStaticPlugins held by the plugin loader.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
Combined button and popup list for selecting options.
static bool s_triedLoading
Definition qctf.cpp:17
bool _tracepoint_enabled(const QCtfTracePointEvent &point)
Definition qctf.cpp:120
void _do_tracepoint(const QCtfTracePointEvent &point, const QByteArray &arr)
Definition qctf.cpp:127
static QCtfLib * s_plugin
Definition qctf.cpp:20
static QT_BEGIN_NAMESPACE bool s_initialized
Definition qctf.cpp:16
static bool loadPlugin(bool &retry)
Definition qctf.cpp:74
static bool s_prevent_recursion
Definition qctf.cpp:18
QCtfTracePointPrivate * _initialize_tracepoint(const QCtfTracePointEvent &point)
Definition qctf.cpp:135
#define QCtfPluginIID
Definition qctf.cpp:72
static bool initialize()
Definition qctf.cpp:94
static bool s_shutdown
Definition qctf.cpp:19
GLenum GLenum GLsizei const GLuint GLboolean enabled
#define QStringLiteral(str)
static QString absoluteFilePath(const Options *options, const QString &relativeFileName)
Definition main.cpp:1902
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
QFile file
[0]
QString dir
[11]
QStringList files
[8]
\inmodule QtCore \reentrant
Definition qchar.h:18