Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qquickprofiler.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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#include "qquickprofiler_p.h"
5
6#include <QtQml/private/qqmlabstractprofileradapter_p.h>
7
8#include <QtCore/qcoreapplication.h>
9#include <QtCore/qthread.h>
10
12
13// instance will be set, unset in constructor. Allows static methods to be inlined.
14QQuickProfiler *QQuickProfiler::s_instance = nullptr;
15quint64 QQuickProfiler::featuresEnabled = 0;
16
17void QQuickProfiler::initialize(QObject *parent)
18{
19 Q_ASSERT(s_instance == nullptr);
20 s_instance = new QQuickProfiler(parent);
21}
22
24{
25 Q_QUICK_PROFILE(QQuickProfiler::ProfileAnimations, animationFrame(delta,
27 QQuickProfiler::GuiThread : QQuickProfiler::RenderThread));
28}
29
31{
33}
34
37public:
39 {
41 delete this;
42 }
43};
44
45QQuickProfiler::QQuickProfiler(QObject *parent) : QObject(parent)
46{
47 // This is safe because at this point the m_instance isn't initialized, yet.
48 m_timer.start();
49 CallbackRegistrationHelper *helper = new CallbackRegistrationHelper; // will delete itself
51
52 // Queue the signal to have the animation timer registration run in the right thread;
53 QObject signalSource;
54 connect(&signalSource, &QObject::destroyed,
57}
58
59QQuickProfiler::~QQuickProfiler()
60{
61 QMutexLocker lock(&m_dataMutex);
62 featuresEnabled = 0;
63 s_instance = nullptr;
64}
65
66void QQuickProfiler::startProfilingImpl(quint64 features)
67{
68 QMutexLocker lock(&m_dataMutex);
69 featuresEnabled = features;
70}
71
72void QQuickProfiler::stopProfilingImpl()
73{
74 QMutexLocker lock(&m_dataMutex);
75 featuresEnabled = 0;
76 emit dataReady(m_data);
77 m_data.clear();
78}
79
80void QQuickProfiler::reportDataImpl()
81{
82 QMutexLocker lock(&m_dataMutex);
83 emit dataReady(m_data);
84 m_data.clear();
85}
86
87void QQuickProfiler::setTimer(const QElapsedTimer &t)
88{
89 QMutexLocker lock(&m_dataMutex);
90 m_timer = t;
91}
92
94
95#include "qquickprofiler.moc"
96#include "moc_qquickprofiler_p.cpp"
NSData * m_data
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
\inmodule QtCore
\inmodule QtCore
Definition qmutex.h:317
\inmodule QtCore
Definition qobject.h:90
void moveToThread(QThread *thread)
Changes the thread affinity for this object and its children.
Definition qobject.cpp:1606
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
QThread * thread() const
Returns the thread in which the object lives.
Definition qobject.cpp:1561
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
static QThread * currentThread()
Definition qthread.cpp:966
void registerProfilerCallback(void(*cb)(qint64))
static QUnifiedTimer * instance()
Combined button and popup list for selecting options.
@ QueuedConnection
GLdouble GLdouble t
Definition qopenglext.h:243
void animationTimerCallback(qint64 delta)
#define Q_QUICK_PROFILE(feature, Method)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_OBJECT
#define emit
unsigned long long quint64
Definition qtypes.h:56
long long qint64
Definition qtypes.h:55
QReadWriteLock lock
[0]
static void registerAnimationCallback()
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent