OpenCoverage

qqmlprofilerevent_p.h

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qmldebug/qqmlprofilerevent_p.h
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2017 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtQml module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#ifndef QQMLPROFILEREVENT_P_H-
41#define QQMLPROFILEREVENT_P_H-
42-
43#include "qqmlprofilerclientdefinitions_p.h"-
44-
45#include <QtCore/qstring.h>-
46#include <QtCore/qbytearray.h>-
47#include <QtCore/qvarlengtharray.h>-
48#include <QtCore/qmetatype.h>-
49-
50#include <initializer_list>-
51#include <type_traits>-
52-
53//-
54// W A R N I N G-
55// --------------
56//-
57// This file is not part of the Qt API. It exists purely as an-
58// implementation detail. This header file may change from version to-
59// version without notice, or even be removed.-
60//-
61// We mean it.-
62//-
63-
64QT_BEGIN_NAMESPACE-
65-
66struct QQmlProfilerEvent {-
67 QQmlProfilerEvent() :-
68 m_timestamp(-1), m_typeIndex(-1), m_dataType(Inline8Bit), m_dataLength(0)-
69 {}
executed 36 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
36
70-
71 template<typename Number>-
72 QQmlProfilerEvent(qint64 timestamp, int typeIndex, std::initializer_list<Number> list)-
73 : m_timestamp(timestamp), m_typeIndex(typeIndex)-
74 {-
75 assignNumbers<std::initializer_list<Number>, Number>(list);-
76 }
never executed: end of block
0
77-
78 QQmlProfilerEvent(qint64 timestamp, int typeIndex, const QString &data)-
79 : m_timestamp(timestamp), m_typeIndex(typeIndex)-
80 {-
81 assignNumbers<QByteArray, qint8>(data.toUtf8());-
82 }
never executed: end of block
0
83-
84 template<typename Number>-
85 QQmlProfilerEvent(qint64 timestamp, int typeIndex, const QVector<Number> &data)-
86 : m_timestamp(timestamp), m_typeIndex(typeIndex)-
87 {-
88 assignNumbers<QVector<Number>, Number>(data);-
89 }
executed 70 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
70
90-
91 QQmlProfilerEvent(const QQmlProfilerEvent &other)-
92 : m_timestamp(other.m_timestamp), m_typeIndex(other.m_typeIndex),-
93 m_dataType(other.m_dataType), m_dataLength(other.m_dataLength)-
94 {-
95 assignData(other);-
96 }
executed 1996 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
1996
97-
98 QQmlProfilerEvent(QQmlProfilerEvent &&other)-
99 {-
100 memcpy(static_cast<void *>(this), static_cast<const void *>(&other), sizeof(QQmlProfilerEvent));-
101 other.m_dataType = Inline8Bit; // prevent dtor from deleting the pointer-
102 }
executed 511 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
511
103-
104 QQmlProfilerEvent &operator=(const QQmlProfilerEvent &other)-
105 {-
106 if (this != &other) {
this != &otherDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEnever evaluated
0-2
107 clearPointer();-
108 m_timestamp = other.m_timestamp;-
109 m_typeIndex = other.m_typeIndex;-
110 m_dataType = other.m_dataType;-
111 m_dataLength = other.m_dataLength;-
112 assignData(other);-
113 }
executed 2 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
2
114 return *this;
executed 2 times by 1 test: return *this;
Executed by:
  • tst_qqmlprofilerservice
2
115 }-
116-
117 QQmlProfilerEvent &operator=(QQmlProfilerEvent &&other)-
118 {-
119 if (this != &other) {
this != &otherDescription
TRUEnever evaluated
FALSEnever evaluated
0
120 memcpy(static_cast<void *>(this), static_cast<const void *>(&other), sizeof(QQmlProfilerEvent));-
121 other.m_dataType = Inline8Bit;-
122 }
never executed: end of block
0
123 return *this;
never executed: return *this;
0
124 }-
125-
126 ~QQmlProfilerEvent()-
127 {-
128 clearPointer();-
129 }
executed 2613 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
2613
130-
131 qint64 timestamp() const { return m_timestamp; }
executed 3459 times by 1 test: return m_timestamp;
Executed by:
  • tst_qqmlprofilerservice
3459
132 void setTimestamp(qint64 timestamp) { m_timestamp = timestamp; }
executed 1442 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
1442
133-
134 int typeIndex() const { return m_typeIndex; }
executed 2270 times by 1 test: return m_typeIndex;
Executed by:
  • tst_qqmlprofilerservice
2270
135 void setTypeIndex(int typeIndex) { m_typeIndex = typeIndex; }
executed 2626 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
2626
136-
137 template<typename Number>-
138 Number number(int i) const-
139 {-
140 // Trailing zeroes can be omitted, for example for SceneGraph events-
141 if (i >= m_dataLength)
i >= m_dataLengthDescription
TRUEnever evaluated
FALSEevaluated 559 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
0-559
142 return 0;
never executed: return 0;
0
143 switch (m_dataType) {-
144 case Inline8Bit:
executed 16 times by 1 test: case Inline8Bit:
Executed by:
  • tst_qqmlprofilerservice
16
145 return m_data.internal8bit[i];
executed 16 times by 1 test: return m_data.internal8bit[i];
Executed by:
  • tst_qqmlprofilerservice
16
146QT_WARNING_PUSH-
147QT_WARNING_DISABLE_GCC("-Warray-bounds") // Mingw 5.3 gcc doesn't get the type/length logic.-
148 case Inline16Bit:
executed 6 times by 1 test: case Inline16Bit:
Executed by:
  • tst_qqmlprofilerservice
6
149 return m_data.internal16bit[i];
executed 6 times by 1 test: return m_data.internal16bit[i];
Executed by:
  • tst_qqmlprofilerservice
6
150 case Inline32Bit:
executed 72 times by 1 test: case Inline32Bit:
Executed by:
  • tst_qqmlprofilerservice
72
151 return m_data.internal32bit[i];
executed 72 times by 1 test: return m_data.internal32bit[i];
Executed by:
  • tst_qqmlprofilerservice
72
152 case Inline64Bit:
executed 465 times by 1 test: case Inline64Bit:
Executed by:
  • tst_qqmlprofilerservice
465
153 return m_data.internal64bit[i];
executed 465 times by 1 test: return m_data.internal64bit[i];
Executed by:
  • tst_qqmlprofilerservice
465
154QT_WARNING_POP-
155 case External8Bit:
never executed: case External8Bit:
0
156 return static_cast<const qint8 *>(m_data.external)[i];
never executed: return static_cast<const qint8 *>(m_data.external)[i];
0
157 case External16Bit:
never executed: case External16Bit:
0
158 return static_cast<const qint16 *>(m_data.external)[i];
never executed: return static_cast<const qint16 *>(m_data.external)[i];
0
159 case External32Bit:
never executed: case External32Bit:
0
160 return static_cast<const qint32 *>(m_data.external)[i];
never executed: return static_cast<const qint32 *>(m_data.external)[i];
0
161 case External64Bit:
never executed: case External64Bit:
0
162 return static_cast<const qint64 *>(m_data.external)[i];
never executed: return static_cast<const qint64 *>(m_data.external)[i];
0
163 default:
never executed: default:
0
164 return 0;
never executed: return 0;
0
165 }-
166 }-
167-
168 template<typename Number>-
169 void setNumber(int i, Number number)-
170 {-
171 QVarLengthArray<Number> nums = numbers<QVarLengthArray<Number>, Number>();-
172 int prevSize = nums.size();-
173 if (i >= prevSize) {
i >= prevSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
174 nums.resize(i + 1);-
175 // Fill with zeroes. We don't want to accidentally prevent squeezing.-
176 while (prevSize < i)
prevSize < iDescription
TRUEnever evaluated
FALSEnever evaluated
0
177 nums[prevSize++] = 0;
never executed: nums[prevSize++] = 0;
0
178 }
never executed: end of block
0
179 nums[i] = number;-
180 setNumbers<QVarLengthArray<Number>, Number>(nums);-
181 }
never executed: end of block
0
182-
183 template<typename Container, typename Number>-
184 void setNumbers(const Container &numbers)-
185 {-
186 clearPointer();-
187 assignNumbers<Container, Number>(numbers);-
188 }
executed 646 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
646
189-
190 template<typename Number>-
191 void setNumbers(std::initializer_list<Number> numbers)-
192 {-
193 setNumbers<std::initializer_list<Number>, Number>(numbers);-
194 }
executed 576 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
576
195-
196 template<typename Container, typename Number = qint64>-
197 Container numbers() const-
198 {-
199 Container container;-
200 for (int i = 0; i < m_dataLength; ++i)
i < m_dataLengthDescription
TRUEevaluated 94 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEevaluated 90 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
90-94
201 container.append(number<Number>(i));
executed 94 times by 1 test: container.append(number<Number>(i));
Executed by:
  • tst_qqmlprofilerservice
94
202 return container;
executed 90 times by 1 test: return container;
Executed by:
  • tst_qqmlprofilerservice
90
203 }-
204-
205 QString string() const-
206 {-
207 switch (m_dataType) {-
208 case External8Bit:
never executed: case External8Bit:
0
209 return QString::fromUtf8(static_cast<const char *>(m_data.external), m_dataLength);
never executed: return QString::fromUtf8(static_cast<const char *>(m_data.external), m_dataLength);
0
210 case Inline8Bit:
never executed: case Inline8Bit:
0
211 return QString::fromUtf8(m_data.internalChar, m_dataLength);
never executed: return QString::fromUtf8(m_data.internalChar, m_dataLength);
0
212 default:
never executed: default:
0
213 Q_UNREACHABLE();-
214 return QString();
never executed: return QString();
0
215 }-
216 }-
217-
218 void setString(const QString &data)-
219 {-
220 clearPointer();-
221 assignNumbers<QByteArray, char>(data.toUtf8());-
222 }
executed 18 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
18
223-
224 Message rangeStage() const-
225 {-
226 Q_ASSERT(m_dataType == Inline8Bit);-
227 return static_cast<Message>(m_data.internal8bit[0]);
executed 752 times by 1 test: return static_cast<Message>(m_data.internal8bit[0]);
Executed by:
  • tst_qqmlprofilerservice
752
228 }-
229-
230 void setRangeStage(Message stage)-
231 {-
232 clearPointer();-
233 m_dataType = Inline8Bit;-
234 m_dataLength = 1;-
235 m_data.internal8bit[0] = stage;-
236 }
executed 744 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
744
237-
238 bool isValid() const-
239 {-
240 return m_timestamp != -1;
never executed: return m_timestamp != -1;
0
241 }-
242-
243private:-
244 enum Type: quint16 {-
245 External = 1,-
246 Inline8Bit = 8,-
247 External8Bit = Inline8Bit | External,-
248 Inline16Bit = 16,-
249 External16Bit = Inline16Bit | External,-
250 Inline32Bit = 32,-
251 External32Bit = Inline32Bit | External,-
252 Inline64Bit = 64,-
253 External64Bit = Inline64Bit | External-
254 };-
255-
256 qint64 m_timestamp;-
257-
258 static const int s_internalDataLength = 8;-
259 union {-
260 void *external;-
261 char internalChar [s_internalDataLength];-
262 qint8 internal8bit [s_internalDataLength];-
263 qint16 internal16bit[s_internalDataLength / 2];-
264 qint32 internal32bit[s_internalDataLength / 4];-
265 qint64 internal64bit[s_internalDataLength / 8];-
266 } m_data;-
267-
268 qint32 m_typeIndex;-
269 Type m_dataType;-
270 quint16 m_dataLength;-
271-
272 void assignData(const QQmlProfilerEvent &other)-
273 {-
274 if (m_dataType & External) {
m_dataType & ExternalDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEevaluated 1992 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
6-1992
275 uint length = m_dataLength * (other.m_dataType / 8);-
276 m_data.external = malloc(length);-
277 memcpy(m_data.external, other.m_data.external, length);-
278 } else {
executed 6 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
6
279 memcpy(&m_data, &other.m_data, sizeof(m_data));-
280 }
executed 1992 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
1992
281 }-
282-
283 template<typename Big, typename Small>-
284 bool squeezable(Big source)-
285 {-
286 return static_cast<Small>(source) == source;
executed 1178 times by 1 test: return static_cast<Small>(source) == source;
Executed by:
  • tst_qqmlprofilerservice
1178
287 }-
288-
289 template<typename Container, typename Number>-
290 typename std::enable_if<(sizeof(Number) > 1), bool>::type-
291 squeeze(const Container &numbers)-
292 {-
293 typedef typename QIntegerForSize<sizeof(Number) / 2>::Signed Small;-
294 foreach (Number item, numbers) {
_container_.controlDescription
TRUEevaluated 333 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEevaluated 333 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
_container_.controlDescription
TRUEevaluated 444 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEnever evaluated
_container_.i != _container_.eDescription
TRUEevaluated 333 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEevaluated 111 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
0-444
295 if (!squeezable<Number, Small>(item))
!squeezable<Nu..., Small>(item)Description
TRUEnever evaluated
FALSEevaluated 333 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
0-333
296 return false;
never executed: return false;
0
297 }
executed 333 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
333
298 assignNumbers<Container, Small>(numbers);-
299 return true;
executed 111 times by 1 test: return true;
Executed by:
  • tst_qqmlprofilerservice
111
300 }-
301-
302 template<typename Container, typename Number>-
303 typename std::enable_if<(sizeof(Number) <= 1), bool>::type-
304 squeeze(const Container &)-
305 {-
306 return false;
executed 6 times by 1 test: return false;
Executed by:
  • tst_qqmlprofilerservice
6
307 }-
308-
309 template<typename Container, typename Number>-
310 void assignNumbers(const Container &numbers)-
311 {-
312 Number *data;-
313 m_dataLength = squeezable<size_t, quint16>(static_cast<size_t>(numbers.size())) ?
squeezable<siz...mbers.size()))Description
TRUEevaluated 845 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEnever evaluated
0-845
314 static_cast<quint16>(numbers.size()) : std::numeric_limits<quint16>::max();-
315 if (m_dataLength > sizeof(m_data) / sizeof(Number)) {
m_dataLength >...sizeof(Number)Description
TRUEevaluated 117 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEevaluated 728 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
117-728
316 if (squeeze<Container, Number>(numbers))
squeeze<Contai...mber>(numbers)Description
TRUEevaluated 111 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEevaluated 6 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
6-111
317 return;
executed 111 times by 1 test: return;
Executed by:
  • tst_qqmlprofilerservice
111
318 m_dataType = static_cast<Type>((sizeof(Number) * 8) | External);-
319 m_data.external = malloc(m_dataLength * sizeof(Number));-
320 data = static_cast<Number *>(m_data.external);-
321 } else {
executed 6 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
6
322 m_dataType = static_cast<Type>(sizeof(Number) * 8);-
323 data = static_cast<Number *>(m_dataType & External ? m_data.external : &m_data);-
324 }
executed 728 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
728
325 quint16 i = 0;-
326 for (Number item : numbers) {-
327 if (i >= m_dataLength)
i >= m_dataLengthDescription
TRUEnever evaluated
FALSEevaluated 1052 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
0-1052
328 break;
never executed: break;
0
329 data[i++] = item;-
330 }
executed 1052 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
1052
331 }
executed 734 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
734
332-
333 void clearPointer()-
334 {-
335 if (m_dataType & External)
m_dataType & ExternalDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
FALSEevaluated 4011 times by 1 test
Evaluated by:
  • tst_qqmlprofilerservice
12-4011
336 free(m_data.external);
executed 12 times by 1 test: free(m_data.external);
Executed by:
  • tst_qqmlprofilerservice
12
337 }
executed 4023 times by 1 test: end of block
Executed by:
  • tst_qqmlprofilerservice
4023
338-
339 friend QDataStream &operator>>(QDataStream &stream, QQmlProfilerEvent &event);-
340 friend QDataStream &operator<<(QDataStream &stream, const QQmlProfilerEvent &event);-
341};-
342-
343bool operator==(const QQmlProfilerEvent &event1, const QQmlProfilerEvent &event2);-
344bool operator!=(const QQmlProfilerEvent &event1, const QQmlProfilerEvent &event2);-
345-
346QDataStream &operator>>(QDataStream &stream, QQmlProfilerEvent &event);-
347QDataStream &operator<<(QDataStream &stream, const QQmlProfilerEvent &event);-
348-
349Q_DECLARE_TYPEINFO(QQmlProfilerEvent, Q_MOVABLE_TYPE);-
350-
351QT_END_NAMESPACE-
352-
353Q_DECLARE_METATYPE(QQmlProfilerEvent)-
354-
355#endif // QQMLPROFILEREVENT_P_H-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0