Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
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// Qt-Security score:significant reason:default
4
6
7#include <QtQml/private/qqmlabstractprofileradapter_p.h>
8
9#include <QtCore/qcoreapplication.h>
10#include <QtCore/qthread.h>
11
13
14// instance will be set, unset in constructor. Allows static methods to be inlined.
15QQuickProfiler *QQuickProfiler::s_instance = nullptr;
16quint64 QQuickProfiler::featuresEnabled = 0;
17
18void QQuickProfiler::initialize(QObject *parent)
19{
20 Q_ASSERT(s_instance == nullptr);
21 s_instance = new QQuickProfiler(parent);
22}
23
24void animationTimerCallback(qint64 delta)
25{
26 Q_QUICK_PROFILE(QQuickProfiler::ProfileAnimations, animationFrame(delta,
27 QThread::currentThread() == QCoreApplication::instance()->thread() ?
28 QQuickProfiler::GuiThread : QQuickProfiler::RenderThread));
29}
30
31void QQuickProfiler::registerAnimationCallback()
32{
33 QUnifiedTimer::instance()->registerProfilerCallback(&animationTimerCallback);
34}
35
38public:
44};
45
46QQuickProfiler::QQuickProfiler(QObject *parent) : QObject(parent)
47{
48 // This is safe because at this point the m_instance isn't initialized, yet.
49 m_timer.start();
50 CallbackRegistrationHelper *helper = new CallbackRegistrationHelper; // will delete itself
51 helper->moveToThread(QCoreApplication::instance()->thread());
52
53 // Queue the signal to have the animation timer registration run in the right thread;
54 QObject signalSource;
55 connect(&signalSource, &QObject::destroyed,
56 helper, &CallbackRegistrationHelper::registerAnimationTimerCallback,
57 Qt::QueuedConnection);
58}
59
60QQuickProfiler::~QQuickProfiler()
61{
62 QMutexLocker lock(&m_dataMutex);
63 featuresEnabled = 0;
64 s_instance = nullptr;
65}
66
67void QQuickProfiler::startProfilingImpl(quint64 features)
68{
69 QMutexLocker lock(&m_dataMutex);
70 featuresEnabled = features;
71}
72
73void QQuickProfiler::stopProfilingImpl()
74{
75 QMutexLocker lock(&m_dataMutex);
76 featuresEnabled = 0;
77 emit dataReady(m_data);
78 m_data.clear();
79}
80
81void QQuickProfiler::reportDataImpl()
82{
83 QMutexLocker lock(&m_dataMutex);
84 emit dataReady(m_data);
85 m_data.clear();
86}
87
88void QQuickProfiler::setTimer(const QElapsedTimer &t)
89{
90 QMutexLocker lock(&m_dataMutex);
91 m_timer = t;
92}
93
94QT_END_NAMESPACE
95
96#include "qquickprofiler.moc"
97#include "moc_qquickprofiler_p.cpp"
void animationTimerCallback(qint64 delta)
#define Q_QUICK_PROFILE(feature, Method)