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