aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/ctfvisualizer/ctftracemanager.cpp
diff options
context:
space:
mode:
authorJarek Kobus <[email protected]>2023-09-27 16:16:43 +0200
committerJarek Kobus <[email protected]>2023-09-27 15:09:56 +0000
commitc05f9cacc6be1038a1a9ecee0af07ac84c01738c (patch)
treee2d841a1a7ac4427f119da5b566cb2fcd38e674b /src/plugins/ctfvisualizer/ctftracemanager.cpp
parentc32022f0857dfca38359c7cc32a578a677af18d5 (diff)
CtfVisualizer: Fix multithreading issues
Simplify the CtfVisualizerTool::loadJson(). Don't create a QThread manually, but use TaskTree with AsyncTask instead. Move pure parsing into the separate thread, and leave the nlohmann::json event handling in the main thread. Avoid moving m_modelAggregator between threads. Fixes: QTCREATORBUG-29657 Change-Id: I0c6a9a4ea8298dbbdbafcddd338d39ad73c3f82b Reviewed-by: Alessandro Portale <[email protected]>
Diffstat (limited to 'src/plugins/ctfvisualizer/ctftracemanager.cpp')
-rw-r--r--src/plugins/ctfvisualizer/ctftracemanager.cpp71
1 files changed, 1 insertions, 70 deletions
diff --git a/src/plugins/ctfvisualizer/ctftracemanager.cpp b/src/plugins/ctfvisualizer/ctftracemanager.cpp
index 82e5b54b762..29dbed73c28 100644
--- a/src/plugins/ctfvisualizer/ctftracemanager.cpp
+++ b/src/plugins/ctfvisualizer/ctftracemanager.cpp
@@ -8,17 +8,11 @@
#include "ctfvisualizertr.h"
#include <coreplugin/icore.h>
+
#include <tracing/timelinemodelaggregator.h>
-#include <QByteArray>
-#include <QDebug>
-#include <QFile>
-#include <QList>
#include <QMessageBox>
-#include <fstream>
-
-
namespace CtfVisualizer {
namespace Internal {
@@ -26,48 +20,6 @@ using json = nlohmann::json;
using namespace Constants;
-
-class CtfJsonParserCallback
-{
-
-public:
-
- explicit CtfJsonParserCallback(CtfTraceManager *traceManager)
- : m_traceManager(traceManager)
- {}
-
- bool callback(int depth, nlohmann::json::parse_event_t event, nlohmann::json &parsed)
- {
- if ((event == json::parse_event_t::array_start && depth == 0)
- || (event == json::parse_event_t::key && depth == 1 && parsed == json(CtfTraceEventsKey))) {
- m_isInTraceArray = true;
- m_traceArrayDepth = depth;
- return true;
- }
- if (m_isInTraceArray && event == json::parse_event_t::array_end && depth == m_traceArrayDepth) {
- m_isInTraceArray = false;
- return false;
- }
- if (m_isInTraceArray && event == json::parse_event_t::object_end && depth == m_traceArrayDepth + 1) {
- m_traceManager->addEvent(parsed);
- return false;
- }
- if (m_isInTraceArray || (event == json::parse_event_t::object_start && depth == 0)) {
- // keep outer object and values in trace objects:
- return true;
- }
- // discard any objects outside of trace array:
- // TODO: parse other data, e.g. stack frames
- return false;
- }
-
-protected:
- CtfTraceManager *m_traceManager;
-
- bool m_isInTraceArray = false;
- int m_traceArrayDepth = 0;
-};
-
CtfTraceManager::CtfTraceManager(QObject *parent,
Timeline::TimelineModelAggregator *modelAggregator,
CtfStatisticsModel *statisticsModel)
@@ -75,7 +27,6 @@ CtfTraceManager::CtfTraceManager(QObject *parent,
, m_modelAggregator(modelAggregator)
, m_statisticsModel(statisticsModel)
{
-
}
qint64 CtfTraceManager::traceDuration() const
@@ -142,26 +93,6 @@ void CtfTraceManager::addEvent(const json &event)
}
}
-void CtfTraceManager::load(const QString &filename)
-{
- clearAll();
-
- std::ifstream file(filename.toStdString());
- if (!file.is_open()) {
- QMessageBox::warning(Core::ICore::dialogParent(),
- Tr::tr("CTF Visualizer"),
- Tr::tr("Cannot read the CTF file."));
- return;
- }
- CtfJsonParserCallback ctfParser(this);
- json::parser_callback_t callback = [&ctfParser](int depth, json::parse_event_t event, json &parsed) {
- return ctfParser.callback(depth, event, parsed);
- };
- json unusedValues = json::parse(file, callback, /*allow_exceptions*/ false);
- file.close();
- updateStatistics();
-}
-
void CtfTraceManager::finalize()
{
bool userConsentToIgnoreDeepTraces = false;