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>
This commit is contained in:
Antti Määttä
2022-09-26 09:02:16 +03:00
parent 0f49728c32
commit b16d1e2b11
9 changed files with 55 additions and 27 deletions

View File

@@ -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)));

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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:

View File

@@ -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>>();

View File

@@ -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},

View File

@@ -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));