1// Copyright (C) 2017 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 "qqmlprofilertypedevent_p.h"
5#include "qqmlprofilerclientdefinitions_p.h"
6
7#include <QtCore/qvarlengtharray.h>
8
9QT_BEGIN_NAMESPACE
10
11QDataStream &operator>>(QDataStream &stream, QQmlProfilerTypedEvent &event)
12{
13 qint64 time;
14 qint32 messageType;
15 qint32 subtype;
16
17 stream >> time >> messageType;
18
19 if (messageType < 0 || messageType > MaximumMessage)
20 messageType = MaximumMessage;
21
22 RangeType rangeType = MaximumRangeType;
23 if (!stream.atEnd()) {
24 stream >> subtype;
25 if (subtype >= 0 && subtype < MaximumRangeType)
26 rangeType = static_cast<RangeType>(subtype);
27 } else {
28 subtype = -1;
29 }
30
31 event.event.setTimestamp(time > 0 ? time : 0);
32 event.event.setTypeIndex(-1);
33 event.serverTypeId = 0;
34
35 switch (messageType) {
36 case Event: {
37 event.type = QQmlProfilerEventType(
38 static_cast<Message>(messageType),
39 MaximumRangeType, subtype);
40 switch (subtype) {
41 case StartTrace:
42 case EndTrace: {
43 QVarLengthArray<qint32> engineIds;
44 while (!stream.atEnd()) {
45 qint32 id;
46 stream >> id;
47 engineIds << id;
48 }
49 event.event.setNumbers<QVarLengthArray<qint32>, qint32>(engineIds);
50 break;
51 }
52 case AnimationFrame: {
53 qint32 frameRate, animationCount;
54 qint32 threadId;
55 stream >> frameRate >> animationCount;
56 if (!stream.atEnd())
57 stream >> threadId;
58 else
59 threadId = 0;
60
61 event.event.setNumbers<qint32>({frameRate, animationCount, threadId});
62 break;
63 }
64 case Mouse:
65 case Key:
66 int inputType = (subtype == Key ? InputKeyUnknown : InputMouseUnknown);
67 if (!stream.atEnd())
68 stream >> inputType;
69 qint32 a = -1;
70 if (!stream.atEnd())
71 stream >> a;
72 qint32 b = -1;
73 if (!stream.atEnd())
74 stream >> b;
75
76 event.event.setNumbers<qint32>({inputType, a, b});
77 break;
78 }
79
80 break;
81 }
82 case Complete: {
83 event.type = QQmlProfilerEventType(
84 static_cast<Message>(messageType),
85 MaximumRangeType, subtype);
86 break;
87 }
88 case SceneGraphFrame: {
89 QVarLengthArray<qint64> params;
90 qint64 param;
91
92 while (!stream.atEnd()) {
93 stream >> param;
94 params.push_back(t: param);
95 }
96
97 event.type = QQmlProfilerEventType(
98 static_cast<Message>(messageType),
99 MaximumRangeType, subtype);
100 event.event.setNumbers<QVarLengthArray<qint64>, qint64>(params);
101 break;
102 }
103 case PixmapCacheEvent: {
104 qint32 width = 0, height = 0, refcount = 0;
105 QString filename;
106 stream >> filename;
107 if (subtype == PixmapReferenceCountChanged || subtype == PixmapCacheCountChanged) {
108 stream >> refcount;
109 } else if (subtype == PixmapSizeKnown) {
110 stream >> width >> height;
111 refcount = 1;
112 }
113
114 event.type = QQmlProfilerEventType(
115 static_cast<Message>(messageType),
116 MaximumRangeType, subtype,
117 QQmlProfilerEventLocation(filename, 0, 0));
118 event.event.setNumbers<qint32>({width, height, refcount});
119 break;
120 }
121 case MemoryAllocation: {
122 qint64 delta;
123 stream >> delta;
124
125 event.type = QQmlProfilerEventType(
126 static_cast<Message>(messageType),
127 MaximumRangeType, subtype);
128 event.event.setNumbers<qint64>({delta});
129 break;
130 }
131 case RangeStart: {
132 if (!stream.atEnd()) {
133 qint64 typeId;
134 stream >> typeId;
135 if (stream.status() == QDataStream::Ok)
136 event.serverTypeId = typeId;
137 // otherwise it's the old binding type of 4 bytes
138 }
139
140 event.type = QQmlProfilerEventType(MaximumMessage, rangeType, -1);
141 event.event.setRangeStage(RangeStart);
142 break;
143 }
144 case RangeData: {
145 QString data;
146 stream >> data;
147
148 event.type = QQmlProfilerEventType(MaximumMessage, rangeType, -1,
149 QQmlProfilerEventLocation(), data);
150 event.event.setRangeStage(RangeData);
151 if (!stream.atEnd())
152 stream >> event.serverTypeId;
153 break;
154 }
155 case RangeLocation: {
156 QString filename;
157 qint32 line = 0;
158 qint32 column = 0;
159 stream >> filename >> line;
160
161 if (!stream.atEnd()) {
162 stream >> column;
163 if (!stream.atEnd())
164 stream >> event.serverTypeId;
165 }
166
167 event.type = QQmlProfilerEventType(MaximumMessage, rangeType, -1,
168 QQmlProfilerEventLocation(filename, line, column));
169 event.event.setRangeStage(RangeLocation);
170 break;
171 }
172 case RangeEnd: {
173 event.type = QQmlProfilerEventType(MaximumMessage, rangeType, -1);
174 event.event.setRangeStage(RangeEnd);
175 break;
176 }
177 default:
178 event.event.setNumbers<char>({});
179 event.type = QQmlProfilerEventType(
180 static_cast<Message>(messageType),
181 MaximumRangeType, subtype);
182 break;
183 }
184
185 return stream;
186}
187
188QT_END_NAMESPACE
189

source code of qtdeclarative/src/qmldebug/qqmlprofilertypedevent.cpp