QmlProfiler: Don't trust in externally provided timestamps

We might get timestamps that are outside the trace time, negative
timestamps, ranges that go backwards, and other insane things.

In order to deal with this, we clamp all negative timestamps to 0, and
treat the specified trace time as minimum range, that can be overridden
by events.

Change-Id: Iba661f2a4346077871fc62a46759e169b2aad49d
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
This commit is contained in:
Ulf Hermann
2017-09-08 17:35:28 +02:00
parent 8fa07c81f6
commit 9cdb0ec22e
6 changed files with 28 additions and 13 deletions

View File

@@ -257,6 +257,8 @@ void QmlProfilerFileReader::loadQzt(QIODevice *device)
return;
}
m_loadedFeatures |= (1ULL << m_eventTypes[event.typeIndex()].feature());
if (event.timestamp() < 0)
event.setTimestamp(0);
} else if (bufferStream.status() == QDataStream::ReadPastEnd) {
break; // Apparently EOF is a character so we end up here after the last event.
} else if (bufferStream.status() == QDataStream::ReadCorruptData) {
@@ -506,15 +508,16 @@ void QmlProfilerFileReader::loadEvents(QXmlStreamReader &stream)
continue;
}
event.setTimestamp(attributes.value(_("startTime")).toLongLong());
const qint64 timestamp = attributes.value(_("startTime")).toLongLong();
event.setTimestamp(timestamp > 0 ? timestamp : 0);
event.setTypeIndex(attributes.value(_("eventIndex")).toInt());
if (attributes.hasAttribute(_("duration"))) {
event.setRangeStage(RangeStart);
QmlEvent rangeEnd(event);
rangeEnd.setRangeStage(RangeEnd);
rangeEnd.setTimestamp(event.timestamp()
+ attributes.value(_("duration")).toLongLong());
const qint64 duration = attributes.value(_("duration")).toLongLong();
rangeEnd.setTimestamp(event.timestamp() + (duration > 0 ? duration : 0));
events.addRange(event, rangeEnd);
} else {
// attributes for special events