forked from qt-creator/qt-creator
CtfVisualizer: Do not crash on unexpected types again
And print a nicer error message.
Amends c05f9cacc6
Task-number: QTCREATORBUG-29659
Change-Id: I1db6bea0bedf1fae034fecbbbeae56bb2fee49ed
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -46,6 +46,7 @@ qint64 CtfTraceManager::traceEnd() const
|
|||||||
|
|
||||||
void CtfTraceManager::addEvent(const json &event)
|
void CtfTraceManager::addEvent(const json &event)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
const double timestamp = event.value(CtfTracingClockTimestampKey, -1.0);
|
const double timestamp = event.value(CtfTracingClockTimestampKey, -1.0);
|
||||||
if (timestamp < 0) {
|
if (timestamp < 0) {
|
||||||
// events without or with negative timestamp will be ignored
|
// events without or with negative timestamp will be ignored
|
||||||
@@ -56,7 +57,8 @@ void CtfTraceManager::addEvent(const json &event)
|
|||||||
m_timeOffset = timestamp;
|
m_timeOffset = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const auto getStringValue = [](const json &event, const char *key, const QString &def) {
|
static const auto getStringValue =
|
||||||
|
[](const json &event, const char *key, const QString &def) {
|
||||||
if (!event.contains(key))
|
if (!event.contains(key))
|
||||||
return def;
|
return def;
|
||||||
const json val = event[key];
|
const json val = event[key];
|
||||||
@@ -91,6 +93,10 @@ void CtfTraceManager::addEvent(const json &event)
|
|||||||
// -> reset the time offset again:
|
// -> reset the time offset again:
|
||||||
m_timeOffset = -1.0;
|
m_timeOffset = -1.0;
|
||||||
}
|
}
|
||||||
|
} catch (...) {
|
||||||
|
m_errorString = Tr::tr("Error while parsing CTF data: %1.")
|
||||||
|
.arg("<pre>" + QString::fromStdString(event.dump()) + "</pre>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CtfTraceManager::finalize()
|
void CtfTraceManager::finalize()
|
||||||
@@ -216,6 +222,7 @@ void CtfTraceManager::updateStatistics()
|
|||||||
|
|
||||||
void CtfTraceManager::clearAll()
|
void CtfTraceManager::clearAll()
|
||||||
{
|
{
|
||||||
|
m_errorString.clear();
|
||||||
m_modelAggregator->clear();
|
m_modelAggregator->clear();
|
||||||
for (CtfTimelineModel *model: std::as_const(m_threadModels)) {
|
for (CtfTimelineModel *model: std::as_const(m_threadModels)) {
|
||||||
model->deleteLater();
|
model->deleteLater();
|
||||||
@@ -226,6 +233,10 @@ void CtfTraceManager::clearAll()
|
|||||||
m_timeOffset = -1;
|
m_timeOffset = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CtfTraceManager::errorString() const
|
||||||
|
{
|
||||||
|
return m_errorString;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CtfVisualizer
|
} // namespace CtfVisualizer
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ public:
|
|||||||
void updateStatistics();
|
void updateStatistics();
|
||||||
void clearAll();
|
void clearAll();
|
||||||
|
|
||||||
|
QString errorString() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void detailsRequested(const QString &title);
|
void detailsRequested(const QString &title);
|
||||||
|
|
||||||
@@ -66,6 +68,7 @@ protected:
|
|||||||
double m_traceEnd = std::numeric_limits<double>::min();
|
double m_traceEnd = std::numeric_limits<double>::min();
|
||||||
double m_timeOffset = -1.0;
|
double m_timeOffset = -1.0;
|
||||||
|
|
||||||
|
QString m_errorString;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -231,6 +231,10 @@ void CtfVisualizerTool::loadJson(const QString &fileName)
|
|||||||
QMessageBox::warning(Core::ICore::dialogParent(),
|
QMessageBox::warning(Core::ICore::dialogParent(),
|
||||||
Tr::tr("CTF Visualizer"),
|
Tr::tr("CTF Visualizer"),
|
||||||
Tr::tr("The file does not contain any trace data."));
|
Tr::tr("The file does not contain any trace data."));
|
||||||
|
} else if (!m_traceManager->errorString().isEmpty()) {
|
||||||
|
QMessageBox::warning(Core::ICore::dialogParent(),
|
||||||
|
Tr::tr("CTF Visualizer"),
|
||||||
|
m_traceManager->errorString());
|
||||||
} else {
|
} else {
|
||||||
m_traceManager->finalize();
|
m_traceManager->finalize();
|
||||||
m_perspective.select();
|
m_perspective.select();
|
||||||
|
|||||||
Reference in New Issue
Block a user