aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2022-09-26 09:02:16 +0300
committerAntti Määttä <antti.maatta@qt.io>2022-09-29 11:04:24 +0000
commitb16d1e2b1141e1c1500f4b01f9b8ac2777997fae (patch)
tree9bedb359000e7e4661ec66e168d700d1dba6b847
parent0f49728c329a4bbf575a36b0b18e169dc4c82ac0 (diff)
Add more checks for backwards compatibility
Stop using MaximumXXXType in events where they might be saved into trace files. It makes older traces incompatible with new traces if new fields are added since new versions treat them as valid events. Instead use UndefinedXXXType that doesn't change if new fields are added. Add checks for event types greater or equal to MaximumXXXType where they are missing so that older versions do not process new unrecognized events. Fix opening old traces by checking missmatch between quick3d event and the range type. Fixes: QTCREATORBUG-28146 Change-Id: I8950da2d636ef1fedf4500916896a9ecae222166 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r--src/plugins/qmlprofiler/inputeventsmodel.cpp2
-rw-r--r--src/plugins/qmlprofiler/inputeventsmodel.h2
-rw-r--r--src/plugins/qmlprofiler/qmleventtype.cpp11
-rw-r--r--src/plugins/qmlprofiler/qmlprofilereventtypes.h29
-rw-r--r--src/plugins/qmlprofiler/qmlprofilertraceclient.cpp2
-rw-r--r--src/plugins/qmlprofiler/qmltypedevent.cpp2
-rw-r--r--src/plugins/qmlprofiler/quick3dmodel.cpp4
-rw-r--r--src/plugins/qmlprofiler/tests/qmleventtype_test.cpp26
-rw-r--r--src/plugins/qmlprofiler/tests/qmlprofilertraceclient_test.cpp4
9 files changed, 55 insertions, 27 deletions
diff --git a/src/plugins/qmlprofiler/inputeventsmodel.cpp b/src/plugins/qmlprofiler/inputeventsmodel.cpp
index 088a9acdcb..748aeab6e0 100644
--- a/src/plugins/qmlprofiler/inputeventsmodel.cpp
+++ b/src/plugins/qmlprofiler/inputeventsmodel.cpp
@@ -154,6 +154,8 @@ int InputEventsModel::collapsedRow(int index) const
void InputEventsModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
+ if (type.detailType() >= MaximumInputEventType)
+ return;
m_data.insert(insert(event.timestamp(), 0, type.detailType()),
Item(static_cast<InputEventType>(event.number<qint32>(0)),
event.number<qint32>(1), event.number<qint32>(2)));
diff --git a/src/plugins/qmlprofiler/inputeventsmodel.h b/src/plugins/qmlprofiler/inputeventsmodel.h
index dbd1515894..bdfcf1dc24 100644
--- a/src/plugins/qmlprofiler/inputeventsmodel.h
+++ b/src/plugins/qmlprofiler/inputeventsmodel.h
@@ -36,7 +36,7 @@ class InputEventsModel : public QmlProfilerTimelineModel
public:
struct Item {
- Item(InputEventType type = MaximumInputEventType, int a = 0, int b = 0);
+ Item(InputEventType type = UndefinedInputEventType, int a = 0, int b = 0);
InputEventType type;
int a;
int b;
diff --git a/src/plugins/qmlprofiler/qmleventtype.cpp b/src/plugins/qmlprofiler/qmleventtype.cpp
index 4963b68495..7557b81aa6 100644
--- a/src/plugins/qmlprofiler/qmleventtype.cpp
+++ b/src/plugins/qmlprofiler/qmleventtype.cpp
@@ -39,7 +39,7 @@ static ProfileFeature qmlFeatureFromType(Message message, RangeType rangeType, i
case AnimationFrame:
return ProfileAnimations;
default:
- return MaximumProfileFeature;
+ return UndefinedProfileFeature;
}
}
case PixmapCacheEvent:
@@ -51,7 +51,11 @@ static ProfileFeature qmlFeatureFromType(Message message, RangeType rangeType, i
case DebugMessage:
return ProfileDebugMessages;
case Quick3DEvent:
- return ProfileQuick3D;
+ // Check if it's actually Quick3DEvent since old traces used MaximumMessage
+ // (whose value is now Quick3DEvent value) as undefined value
+ if (rangeType == UndefinedRangeType)
+ return ProfileQuick3D;
+ return featureFromRangeType(rangeType);
default:
return featureFromRangeType(rangeType);
}
@@ -68,6 +72,9 @@ QDataStream &operator>>(QDataStream &stream, QmlEventType &type)
type.m_message = static_cast<Message>(message);
type.m_rangeType = static_cast<RangeType>(rangeType);
type.setFeature(qmlFeatureFromType(type.m_message, type.m_rangeType, type.m_detailType));
+ // Update message if qmlFeatureFromType determined it is not Quick3D event
+ if (type.m_message == Quick3DEvent && type.feature() != ProfileQuick3D)
+ type.m_message = UndefinedMessage;
return stream;
}
diff --git a/src/plugins/qmlprofiler/qmlprofilereventtypes.h b/src/plugins/qmlprofiler/qmlprofilereventtypes.h
index b8bc25e5e9..d5f7475028 100644
--- a/src/plugins/qmlprofiler/qmlprofilereventtypes.h
+++ b/src/plugins/qmlprofiler/qmlprofilereventtypes.h
@@ -47,7 +47,8 @@ enum Message {
};
enum EventType {
- FramePaint, // unused
+ UndefinedEventType = 0xff,
+ FramePaint = 0, // unused
Mouse,
Key,
AnimationFrame, // new Qt5 paint events
@@ -58,7 +59,8 @@ enum EventType {
};
enum Quick3DEventType {
- Quick3DRenderFrame,
+ UndefinedQuick3DEventType = 0xff,
+ Quick3DRenderFrame = 0,
Quick3DSynchronizeFrame,
Quick3DPrepareFrame,
Quick3DMeshLoad,
@@ -85,7 +87,8 @@ enum RangeType {
};
enum BindingType {
- QmlBinding,
+ UndefinedBindingType = 0xff,
+ QmlBinding = 0,
V8Binding,
OptimizedBinding,
QPainterEvent,
@@ -94,7 +97,8 @@ enum BindingType {
};
enum PixmapEventType {
- PixmapSizeKnown,
+ UndefinedPixmapEventType = 0xff,
+ PixmapSizeKnown = 0,
PixmapReferenceCountChanged,
PixmapCacheCountChanged,
PixmapLoadingStarted,
@@ -105,7 +109,8 @@ enum PixmapEventType {
};
enum InputEventType {
- InputKeyPress,
+ UndefinedInputEventType = 0xff,
+ InputKeyPress = 0,
InputKeyRelease,
InputKeyUnknown,
@@ -120,7 +125,8 @@ enum InputEventType {
};
enum SceneGraphFrameType {
- SceneGraphRendererFrame, // Render Thread
+ UndefinedSceheGraphFrameType = 0xff,
+ SceneGraphRendererFrame = 0, // Render Thread
SceneGraphAdaptationLayerFrame, // Render Thread
SceneGraphContextFrame, // Render Thread
SceneGraphRenderLoopFrame, // Render Thread
@@ -135,7 +141,8 @@ enum SceneGraphFrameType {
};
enum MemoryType {
- HeapPage,
+ UndefinedMemoryType = 0xff,
+ HeapPage = 0,
LargeItem,
SmallItem,
@@ -143,14 +150,16 @@ enum MemoryType {
};
enum AnimationThread {
- GuiThread,
+ UndefinedAnimationThread = 0xff,
+ GuiThread = 0,
RenderThread,
MaximumAnimationThread
};
enum ProfileFeature {
- ProfileJavaScript,
+ UndefinedProfileFeature = 0xff,
+ ProfileJavaScript = 0,
ProfileMemory,
ProfilePixmapCache,
ProfileSceneGraph,
@@ -183,7 +192,7 @@ inline ProfileFeature featureFromRangeType(RangeType range)
case Javascript:
return ProfileJavaScript;
default:
- return MaximumProfileFeature;
+ return UndefinedProfileFeature;
}
}
diff --git a/src/plugins/qmlprofiler/qmlprofilertraceclient.cpp b/src/plugins/qmlprofiler/qmlprofilertraceclient.cpp
index a7e01208c0..193b5c3414 100644
--- a/src/plugins/qmlprofiler/qmlprofilertraceclient.cpp
+++ b/src/plugins/qmlprofiler/qmlprofilertraceclient.cpp
@@ -350,6 +350,8 @@ void QmlProfilerTraceClient::setFlushInterval(quint32 flushInterval)
bool QmlProfilerTraceClientPrivate::updateFeatures(quint8 feature)
{
+ if (feature == UndefinedProfileFeature)
+ return true;
quint64 flag = 1ULL << feature;
if (!(requestedFeatures & flag))
return false;
diff --git a/src/plugins/qmlprofiler/qmltypedevent.cpp b/src/plugins/qmlprofiler/qmltypedevent.cpp
index e79080d48e..105eb644ab 100644
--- a/src/plugins/qmlprofiler/qmltypedevent.cpp
+++ b/src/plugins/qmlprofiler/qmltypedevent.cpp
@@ -54,6 +54,8 @@ QDataStream &operator>>(QDataStream &stream, QmlTypedEvent &event)
switch (messageType) {
case Event: {
+ if (subtype >= MaximumEventType)
+ subtype = UndefinedEventType;
event.type = QmlEventType(static_cast<Message>(messageType), UndefinedRangeType, subtype);
switch (subtype) {
case StartTrace:
diff --git a/src/plugins/qmlprofiler/quick3dmodel.cpp b/src/plugins/qmlprofiler/quick3dmodel.cpp
index be52181845..aa5efd426e 100644
--- a/src/plugins/qmlprofiler/quick3dmodel.cpp
+++ b/src/plugins/qmlprofiler/quick3dmodel.cpp
@@ -156,7 +156,9 @@ int Quick3DModel::collapsedRow(int index) const
void Quick3DModel::loadEvent(const QmlEvent &event, const QmlEventType &type)
{
- auto detailType = type.detailType();
+ int detailType = type.detailType();
+ if (detailType >= MaximumQuick3DFrameType)
+ return;
qint64 eventDuration = event.number<qint64>(0);
qint64 eventTime = event.timestamp() - eventDuration;
QVector<quint64> numbers = event.numbers<QVector<quint64>>();
diff --git a/src/plugins/qmlprofiler/tests/qmleventtype_test.cpp b/src/plugins/qmlprofiler/tests/qmleventtype_test.cpp
index a43a72581b..7e82ae17c8 100644
--- a/src/plugins/qmlprofiler/tests/qmleventtype_test.cpp
+++ b/src/plugins/qmlprofiler/tests/qmleventtype_test.cpp
@@ -43,7 +43,7 @@ void QmlEventTypeTest::testAccessors()
QVERIFY(!type.location().isValid());
QVERIFY(type.data().isEmpty());
QVERIFY(type.displayName().isEmpty());
- QCOMPARE(static_cast<ProfileFeature>(type.feature()), MaximumProfileFeature);
+ QCOMPARE(static_cast<ProfileFeature>(type.feature()), UndefinedProfileFeature);
type.setLocation(QmlEventLocation("blah.js", 12, 13));
QCOMPARE(type.location().filename(), QString("blah.js"));
@@ -71,23 +71,23 @@ void QmlEventTypeTest::testFeature()
{
const quint8 features[][MaximumEventType] = {
// Event
- {MaximumProfileFeature, ProfileInputEvents, ProfileInputEvents,
- ProfileAnimations, MaximumProfileFeature, MaximumProfileFeature},
+ {UndefinedProfileFeature, ProfileInputEvents, ProfileInputEvents,
+ ProfileAnimations, UndefinedProfileFeature, UndefinedProfileFeature},
// RangeStart
- {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
- MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
+ {UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature,
+ UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature},
// RangeData
- {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
- MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
+ {UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature,
+ UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature},
// RangeLocation
- {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
- MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
+ {UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature,
+ UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature},
// RangeEnd
- {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
- MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
+ {UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature,
+ UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature},
// Complete
- {MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature,
- MaximumProfileFeature, MaximumProfileFeature, MaximumProfileFeature},
+ {UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature,
+ UndefinedProfileFeature, UndefinedProfileFeature, UndefinedProfileFeature},
// PixmapCacheEvent
{ProfilePixmapCache, ProfilePixmapCache, ProfilePixmapCache,
ProfilePixmapCache, ProfilePixmapCache, ProfilePixmapCache},
diff --git a/src/plugins/qmlprofiler/tests/qmlprofilertraceclient_test.cpp b/src/plugins/qmlprofiler/tests/qmlprofilertraceclient_test.cpp
index 055e5ef000..dbb55fac79 100644
--- a/src/plugins/qmlprofiler/tests/qmlprofilertraceclient_test.cpp
+++ b/src/plugins/qmlprofiler/tests/qmlprofilertraceclient_test.cpp
@@ -80,6 +80,10 @@ void QmlProfilerTraceClientTest::testMessageReceived()
quint8 message;
quint8 rangeType;
checkStream >> timestamp >> message >> rangeType;
+ QVERIFY(message != MaximumMessage);
+ QVERIFY(rangeType != MaximumRangeType);
+ QVERIFY(type.message() != MaximumMessage);
+ QVERIFY(type.rangeType() != MaximumRangeType);
QCOMPARE(event.timestamp(), timestamp);
QCOMPARE(type.message(), static_cast<Message>(message));
QCOMPARE(type.rangeType(), static_cast<RangeType>(rangeType));