Allow users to enable/disable multithreaded frame parsing

This commit is contained in:
Alex Spataru 2021-11-01 03:20:04 -06:00
parent 41dba80f07
commit 5197846241
14 changed files with 95 additions and 11 deletions

View File

@ -109,10 +109,11 @@ Item {
// App settings // App settings
// //
property alias language: settings.language property alias language: settings.language
property alias tcpPlugins: settings.tcpPlugins
property alias endSequence: settings.endSequence property alias endSequence: settings.endSequence
property alias startSequence: settings.startSequence property alias startSequence: settings.startSequence
property alias tcpPlugins: settings.tcpPlugins
property alias separatorSequence: settings.separatorSequence property alias separatorSequence: settings.separatorSequence
property alias multithreadedFrameProcessing: settings.multithreadedFrameProcessing
} }
// //

View File

@ -32,10 +32,11 @@ Control {
// Access to properties // Access to properties
// //
property alias endSequence: _endSequence.text property alias endSequence: _endSequence.text
property alias tcpPlugins: _tcpPlugins.checked
property alias language: _langCombo.currentIndex property alias language: _langCombo.currentIndex
property alias startSequence: _startSequence.text property alias startSequence: _startSequence.text
property alias tcpPlugins: _tcpPlugins.checked
property alias separatorSequence: _separatorSequence.text property alias separatorSequence: _separatorSequence.text
property alias multithreadedFrameProcessing: _multithreadedFrameProcessing.checked
// //
// Layout // Layout
@ -149,6 +150,22 @@ Control {
} }
} }
//
// Multi-threaded frame processing
//
Label {
text: qsTr("Multithreaded frame parsing") + ": "
} Switch {
id: _multithreadedFrameProcessing
Layout.leftMargin: -app.spacing
Layout.alignment: Qt.AlignLeft
checked: Cpp_JSON_Generator.processFramesInSeparateThread
onCheckedChanged: {
if (checked != Cpp_JSON_Generator.processFramesInSeparateThread)
Cpp_JSON_Generator.processFramesInSeparateThread = checked
}
}
// //
// Plugins enabled // Plugins enabled
// //

Binary file not shown.

View File

@ -1988,6 +1988,14 @@
<source>Rendering engine</source> <source>Rendering engine</source>
<translation>Rendering Motor</translation> <translation>Rendering Motor</translation>
</message> </message>
<message>
<source>Threaded frame parsing</source>
<translation type="vanished">Analyse von Multithreading-Rahmen</translation>
</message>
<message>
<source>Multithreaded frame parsing</source>
<translation>Analyse von Multithreading-Rahmen</translation>
</message>
</context> </context>
<context> <context>
<name>Setup</name> <name>Setup</name>

Binary file not shown.

View File

@ -1536,6 +1536,10 @@
<source>Rendering engine</source> <source>Rendering engine</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Multithreaded frame parsing</source>
<translation></translation>
</message>
</context> </context>
<context> <context>
<name>Setup</name> <name>Setup</name>

Binary file not shown.

View File

@ -2112,6 +2112,14 @@
<source>Rendering engine</source> <source>Rendering engine</source>
<translation>Motor de renderizado</translation> <translation>Motor de renderizado</translation>
</message> </message>
<message>
<source>Threaded frame parsing</source>
<translation type="vanished">Análisis multihilo de tramas</translation>
</message>
<message>
<source>Multithreaded frame parsing</source>
<translation>Análisis multihilo de tramas</translation>
</message>
</context> </context>
<context> <context>
<name>Setup</name> <name>Setup</name>

Binary file not shown.

View File

@ -1790,6 +1790,14 @@
<source>Rendering engine</source> <source>Rendering engine</source>
<translation>Механизм рендеринга</translation> <translation>Механизм рендеринга</translation>
</message> </message>
<message>
<source>Threaded frame parsing</source>
<translation type="vanished">Многопоточный анализ кадров</translation>
</message>
<message>
<source>Multithreaded frame parsing</source>
<translation>Многопоточный анализ кадров</translation>
</message>
</context> </context>
<context> <context>
<name>Setup</name> <name>Setup</name>

Binary file not shown.

View File

@ -2044,6 +2044,14 @@
<source>Rendering engine</source> <source>Rendering engine</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Threaded frame parsing</source>
<translation type="vanished">线</translation>
</message>
<message>
<source>Multithreaded frame parsing</source>
<translation>线</translation>
</message>
</context> </context>
<context> <context>
<name>Setup</name> <name>Setup</name>

View File

@ -45,6 +45,7 @@ static Generator *INSTANCE = nullptr;
Generator::Generator() Generator::Generator()
: m_frameCount(0) : m_frameCount(0)
, m_opMode(kAutomatic) , m_opMode(kAutomatic)
, m_processInSeparateThread(false)
{ {
auto io = IO::Manager::getInstance(); auto io = IO::Manager::getInstance();
auto cp = CSV::Player::getInstance(); auto cp = CSV::Player::getInstance();
@ -110,6 +111,13 @@ Generator::OperationMode Generator::operationMode() const
return m_opMode; return m_opMode;
} }
/**
* Returns @c true if JSON frames shall be generated in a separate thread
*/
bool Generator::processFramesInSeparateThread() const {
return m_processInSeparateThread;
}
/** /**
* Creates a file dialog & lets the user select the JSON file map * Creates a file dialog & lets the user select the JSON file map
*/ */
@ -202,6 +210,14 @@ void Generator::setOperationMode(const JSON::Generator::OperationMode mode)
emit operationModeChanged(); emit operationModeChanged();
} }
/**
* Enables or disables multi-threaded frame processing
*/
void Generator::setProcessFramesInSeparateThread(const bool threaded) {
m_processInSeparateThread = threaded;
emit processFramesInSeparateThreadChanged();
}
/** /**
* Loads the last saved JSON map file (if any) * Loads the last saved JSON map file (if any)
*/ */
@ -285,15 +301,21 @@ void Generator::readData(const QByteArray &data)
m_frameCount++; m_frameCount++;
// Create new worker thread to read JSON data // Create new worker thread to read JSON data
QThread *thread = new QThread; if (processFramesInSeparateThread()) {
JSONWorker *worker = new JSONWorker(data, m_frameCount, QDateTime::currentDateTime()); QThread *thread = new QThread;
worker->moveToThread(thread); JSONWorker *worker = new JSONWorker(data, m_frameCount, QDateTime::currentDateTime());
connect(thread, SIGNAL(started()), worker, SLOT(process())); worker->moveToThread(thread);
connect(worker, SIGNAL(finished()), thread, SLOT(quit())); connect(thread, SIGNAL(started()), worker, SLOT(process()));
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater())); connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
connect(worker, &JSONWorker::jsonReady, this, &Generator::loadJFI); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start(); connect(worker, &JSONWorker::jsonReady, this, &Generator::loadJFI);
thread->start();
}
// Process frames in main thread
else
processFrame(data, m_frameCount, QDateTime::currentDateTime());
} }
/** /**

View File

@ -103,12 +103,17 @@ class Generator : public QObject
READ operationMode READ operationMode
WRITE setOperationMode WRITE setOperationMode
NOTIFY operationModeChanged) NOTIFY operationModeChanged)
Q_PROPERTY(bool processFramesInSeparateThread
READ processFramesInSeparateThread
WRITE setProcessFramesInSeparateThread
NOTIFY processFramesInSeparateThreadChanged)
// clang-format on // clang-format on
signals: signals:
void jsonFileMapChanged(); void jsonFileMapChanged();
void operationModeChanged(); void operationModeChanged();
void jsonChanged(const JFI_Object &info); void jsonChanged(const JFI_Object &info);
void processFramesInSeparateThreadChanged();
public: public:
enum OperationMode enum OperationMode
@ -125,10 +130,12 @@ public:
QString jsonMapFilename() const; QString jsonMapFilename() const;
QString jsonMapFilepath() const; QString jsonMapFilepath() const;
OperationMode operationMode() const; OperationMode operationMode() const;
bool processFramesInSeparateThread() const;
public slots: public slots:
void loadJsonMap(); void loadJsonMap();
void loadJsonMap(const QString &path); void loadJsonMap(const QString &path);
void setProcessFramesInSeparateThread(const bool threaded);
void setOperationMode(const JSON::Generator::OperationMode mode); void setOperationMode(const JSON::Generator::OperationMode mode);
private: private:
@ -152,6 +159,7 @@ private:
QSettings m_settings; QSettings m_settings;
QString m_jsonMapData; QString m_jsonMapData;
OperationMode m_opMode; OperationMode m_opMode;
bool m_processInSeparateThread;
}; };
} }