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
qquickprofileradapter.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
5
6#include <QCoreApplication>
7#include <private/qqmldebugconnector_p.h>
8#include <private/qversionedpacket_p.h>
9#include <private/qqmldebugserviceinterfaces_p.h>
10#include <private/qquickprofiler_p.h>
11
13
14using QQmlDebugPacket = QVersionedPacket<QQmlDebugConnector>;
15
18{
19 QQuickProfiler::initialize(this);
20
21 // We can always do DirectConnection here as all methods are protected by mutexes
23 QQuickProfiler::s_instance, &QQuickProfiler::startProfilingImpl, Qt::DirectConnection);
25 QQuickProfiler::s_instance, &QQuickProfiler::startProfilingImpl, Qt::DirectConnection);
27 QQuickProfiler::s_instance, &QQuickProfiler::setTimer, Qt::DirectConnection);
29 QQuickProfiler::s_instance, &QQuickProfiler::stopProfilingImpl, Qt::DirectConnection);
31 QQuickProfiler::s_instance, &QQuickProfiler::stopProfilingImpl, Qt::DirectConnection);
33 QQuickProfiler::s_instance, &QQuickProfiler::reportDataImpl, Qt::DirectConnection);
34 connect(QQuickProfiler::s_instance, &QQuickProfiler::dataReady,
36}
37
39{
40 if (service)
41 service->removeGlobalProfiler(this);
42}
43
44// convert to QByteArrays that can be sent to the debug client
45static void qQuickProfilerDataToByteArrays(const QQuickProfilerData &data,
46 QList<QByteArray> &messages)
47{
49 Q_ASSERT_X(((data.messageType | data.detailType) & (1 << 31)) == 0, Q_FUNC_INFO,
50 "You can use at most 31 message types and 31 detail types.");
51 for (uint decodedMessageType = 0; (data.messageType >> decodedMessageType) != 0;
52 ++decodedMessageType) {
53 if ((data.messageType & (1 << decodedMessageType)) == 0)
54 continue;
55
56 for (uint decodedDetailType = 0; (data.detailType >> decodedDetailType) != 0;
57 ++decodedDetailType) {
58 if ((data.detailType & (1 << decodedDetailType)) == 0)
59 continue;
60
61 ds << data.time << decodedMessageType << decodedDetailType;
62
63 switch (decodedMessageType) {
64 case QQuickProfiler::Event:
65 switch (decodedDetailType) {
66 case QQuickProfiler::AnimationFrame:
67 ds << data.framerate << data.count << data.threadId;
68 break;
69 case QQuickProfiler::Key:
70 case QQuickProfiler::Mouse:
71 ds << data.inputType << data.inputA << data.inputB;
72 break;
73 }
74 break;
75 case QQuickProfiler::PixmapCacheEvent:
76 ds << data.detailUrl.toString();
77 switch (decodedDetailType) {
78 case QQuickProfiler::PixmapSizeKnown: ds << data.x << data.y; break;
79 case QQuickProfiler::PixmapReferenceCountChanged: ds << data.count; break;
80 case QQuickProfiler::PixmapCacheCountChanged: ds << data.count; break;
81 default: break;
82 }
83 break;
84 case QQuickProfiler::SceneGraphFrame:
85 switch (decodedDetailType) {
86 // RendererFrame: preprocessTime, updateTime, bindingTime, renderTime
87 case QQuickProfiler::SceneGraphRendererFrame: ds << data.subtime_1 << data.subtime_2 << data.subtime_3 << data.subtime_4; break;
88 // AdaptationLayerFrame: glyphCount (which is an integer), glyphRenderTime, glyphStoreTime
89 case QQuickProfiler::SceneGraphAdaptationLayerFrame: ds << data.subtime_3 << data.subtime_1 << data.subtime_2; break;
90 // ContextFrame: compiling material time
91 case QQuickProfiler::SceneGraphContextFrame: ds << data.subtime_1; break;
92 // RenderLoop: syncTime, renderTime, swapTime
93 case QQuickProfiler::SceneGraphRenderLoopFrame: ds << data.subtime_1 << data.subtime_2 << data.subtime_3; break;
94 // TexturePrepare: bind, convert, swizzle, upload, mipmap
95 case QQuickProfiler::SceneGraphTexturePrepare: ds << data.subtime_1 << data.subtime_2 << data.subtime_3 << data.subtime_4 << data.subtime_5; break;
96 // TextureDeletion: deletionTime
97 case QQuickProfiler::SceneGraphTextureDeletion: ds << data.subtime_1; break;
98 // PolishAndSync: polishTime, waitTime, syncTime, animationsTime,
99 case QQuickProfiler::SceneGraphPolishAndSync: ds << data.subtime_1 << data.subtime_2 << data.subtime_3 << data.subtime_4; break;
100 // WindowsRenderLoop: GL time, make current time, SceneGraph time
101 case QQuickProfiler::SceneGraphWindowsRenderShow: ds << data.subtime_1 << data.subtime_2 << data.subtime_3; break;
102 // WindowsAnimations: update time
103 case QQuickProfiler::SceneGraphWindowsAnimations: ds << data.subtime_1; break;
104 // non-threaded rendering: polish time
105 case QQuickProfiler::SceneGraphPolishFrame: ds << data.subtime_1; break;
106 default:break;
107 }
108 break;
109 default:
110 Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid message type.");
111 break;
112 }
113 messages.append(ds.squeezedData());
114 ds.clear();
115 }
116 }
117}
118
119qint64 QQuickProfilerAdapter::sendMessages(qint64 until, QList<QByteArray> &messages)
120{
121 while (next < m_data.size()) {
122 if (m_data[next].time <= until && messages.size() <= s_numMessagesPerBatch)
123 qQuickProfilerDataToByteArrays(m_data[next++], messages);
124 else
125 return m_data[next].time;
126 }
127 m_data.clear();
128 next = 0;
129 return -1;
130}
131
132void QQuickProfilerAdapter::receiveData(const QVector<QQuickProfilerData> &new_data)
133{
134 if (m_data.isEmpty())
135 m_data = new_data;
136 else
137 m_data.append(new_data);
138 service->dataReady(this);
139}
140
142
143#include "moc_qquickprofileradapter.cpp"
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QByteArray squeezedData() const
Returns a copy of the raw packet data, with extra reserved space removed.
Definition qpacket.cpp:86
void clear()
Clears the packet, discarding any data.
Definition qpacket.cpp:96
void profilingEnabled(quint64 features)
void profilingEnabledWhileWaiting(quint64 features)
void referenceTimeKnown(const QElapsedTimer &timer)
qint64 sendMessages(qint64 until, QList< QByteArray > &messages) override
void receiveData(const QVector< QQuickProfilerData > &new_data)
QQuickProfilerAdapter(QObject *parent=nullptr)
short next
Definition keywords.cpp:445
Combined button and popup list for selecting options.
@ DirectConnection
#define Q_FUNC_INFO
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
static void qQuickProfilerDataToByteArrays(const QQuickProfilerData &data, QList< QByteArray > &messages)
#define Q_ASSERT_X(cond, x, msg)
Definition qrandom.cpp:48
unsigned int uint
Definition qtypes.h:34
long long qint64
Definition qtypes.h:60