From 071b1551b3b0667d9d9518fed6e5df21a3de9a9b Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 12 Dec 2016 16:51:25 +0100 Subject: [PATCH] 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 --- .../qmlprofiler/qmlprofilerrangemodel.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/plugins/qmlprofiler/qmlprofilerrangemodel.cpp b/src/plugins/qmlprofiler/qmlprofilerrangemodel.cpp index a4c76f9d90b..bb060d1bc0f 100644 --- a/src/plugins/qmlprofiler/qmlprofilerrangemodel.cpp +++ b/src/plugins/qmlprofiler/qmlprofilerrangemodel.cpp @@ -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();