QmlProfiler: Make sure we can handle inconsistent trace data

Apparently some versions of Qt can produce traces with unmatched start
and end events. We should not crash on those.

Change-Id: Idfb3273f02470156e9f1863c43477d0c3494e0d6
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Ulf Hermann
2016-12-12 16:51:25 +01:00
parent 2c98573e70
commit 071b1551b3

View File

@@ -72,13 +72,26 @@ void QmlProfilerRangeModel::loadEvent(const QmlEvent &event, const QmlEventType
m_stack.append(index);
m_data.insert(index, QmlRangeEventStartInstance());
} else if (event.rangeStage() == RangeEnd) {
int index = m_stack.pop();
insertEnd(index, event.timestamp() - startTime(index));
if (!m_stack.isEmpty()) {
int index = m_stack.pop();
insertEnd(index, event.timestamp() - startTime(index));
} else {
qWarning() << "Received inconsistent trace data from application.";
}
}
}
void QmlProfilerRangeModel::finalize()
{
if (!m_stack.isEmpty()) {
qWarning() << "End times for some events are missing.";
const qint64 endTime = modelManager()->traceTime()->endTime();
do {
int index = m_stack.pop();
insertEnd(index, endTime - startTime(index));
} while (!m_stack.isEmpty());
}
// compute range nesting
computeNesting();