Skip to content

Commit

Permalink
populate ecus tree efficiently
Browse files Browse the repository at this point in the history
fix symbols visibility

Fix macos-13 build

It still uses qmake, so new sources should be added there too

Signed-off-by: Viktor Kopp <[email protected]>
  • Loading branch information
vifactor committed Jan 7, 2025
1 parent b45cbae commit 1b050c0
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 41 deletions.
2 changes: 2 additions & 0 deletions qdlt/qdlt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ SOURCES += \
fieldnames.cpp \
qdltimporter.cpp \
dltmessagematcher.cpp \
qdltctrlmsg.cpp \

HEADERS += qdlt.h \
export_rules.h \
Expand Down Expand Up @@ -101,6 +102,7 @@ HEADERS += qdlt.h \
fieldnames.h \
qdltimporter.h \
dltmessagematcher.h \
qdltctrlmsg.h \

unix:VERSION = 1.0.0

Expand Down
4 changes: 3 additions & 1 deletion qdlt/qdltctrlmsg.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef QDLTCTRLMSG_H
#define QDLTCTRLMSG_H

#include "export_rules.h"

#include <vector>
#include <variant>

Expand Down Expand Up @@ -57,7 +59,7 @@ struct UnregisterContext {
using Type = std::variant<GetLogInfo, GetSoftwareVersion, GetDefaultLogLevel, SetLogLevel, Timezone,
UnregisterContext>;

Type parse(const QByteArray&, bool isBigEndian);
QDLT_EXPORT Type parse(const QByteArray&, bool isBigEndian);

} // namespace qdlt::msg::payload

Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ add_executable(dlt-viewer
searchform.cpp
${UI_RESOURCES_RCC}
resources/dlt_viewer.rc
)
ecutree.h
ecutree.cpp
)

target_link_libraries(dlt-viewer
qdlt
Expand Down
17 changes: 17 additions & 0 deletions src/ecutree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "ecutree.h"

void EcuTree::add(const QString& ecuId, const qdlt::msg::payload::GetLogInfo& info)
{
for (const auto& app : info.apps) {
App appData;
appData.description = app.description;
for (const auto& ctx : app.ctxs) {
Ctx ctxData;
ctxData.description = ctx.description;
ctxData.logLevel = ctx.logLevel;
ctxData.traceStatus = ctx.traceStatus;
appData.contexts[ctx.id] = std::move(ctxData);
}
ecus[ecuId][app.id] = std::move(appData);
}
}
27 changes: 27 additions & 0 deletions src/ecutree.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef ECUTREEBUILDER_H
#define ECUTREEBUILDER_H

#include <qdltctrlmsg.h>

#include <map>

struct EcuTree
{
void add(const QString& ecuId, const qdlt::msg::payload::GetLogInfo&);

using EcuId = QString;
using AppId = QString;
using CtxId = QString;
struct Ctx {
QString description;
int8_t logLevel;
int8_t traceStatus;
};
struct App {
QString description;
std::map<CtxId, Ctx> contexts;
};
std::map<EcuId, std::map<AppId, App>> ecus;
};

#endif // ECUTREEBUILDER_H
78 changes: 47 additions & 31 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ extern "C" {
#include "sortfilterproxymodel.h"
#include "qdltoptmanager.h"
#include "qdltctrlmsg.h"
#include "ecutree.h"


MainWindow::MainWindow(QWidget *parent) :
Expand Down Expand Up @@ -1893,45 +1894,52 @@ void MainWindow::on_action_menuFile_Clear_triggered()
return;
}

void MainWindow::contextLoadingFile(const QDltMsg &msg)
void MainWindow::populateEcusTree(EcuTree&& ecuTree)
{
/* find ecu item */
EcuItem *ecuitemFound = 0;
for(int num = 0; num < project.ecu->topLevelItemCount (); num++)
{
EcuItem *ecuitem = (EcuItem*)project.ecu->topLevelItem(num);
if(ecuitem->id == msg.getEcuid())
{
ecuitemFound = ecuitem;
break;
}
}
QList<QTreeWidgetItem*> ecus;
// populate ECUs tree view
for (auto& [ecuid, apps] : ecuTree.ecus) {
EcuItem* ecuItem = new EcuItem(nullptr);

if(!ecuitemFound)
{
/* no Ecuitem found, create a new one */
ecuitemFound = new EcuItem(0);
ecuItem->id = ecuid;

/* update ECU item */
ecuitemFound->id = msg.getEcuid();
ecuitemFound->update();
QList<QTreeWidgetItem*> appsItems;
for(const auto& [appid, appdata] : apps) {
ApplicationItem* appItem = new ApplicationItem(ecuItem);
appItem->id = appid;
appItem->description = appdata.description;
appItem->update();

/* add ECU to configuration */
project.ecu->addTopLevelItem(ecuitemFound);
QList<QTreeWidgetItem*> contextsItems;
for(const auto& [ctxid, ctxdata] : appdata.contexts) {
ContextItem* conItem = new ContextItem(appItem);
conItem->id = ctxid;
conItem->loglevel = ctxdata.logLevel;
conItem->tracestatus = ctxdata.traceStatus;
conItem->description = ctxdata.description;
conItem->status = ContextItem::valid;
conItem->update();

/* Update the ECU list in control plugins */
updatePluginsECUList();
contextsItems.append(conItem);
}

pluginManager.stateChanged(project.ecu->indexOfTopLevelItem(ecuitemFound), QDltConnection::QDltConnectionOffline,ecuitemFound->getHostname());
appItem->addChildren(contextsItems);
appsItems.append(appItem);
}

}
ecuItem->addChildren(appsItems);
ecuItem->update();

controlMessage_ReceiveControlMessage(ecuitemFound, msg);
}
pluginManager.stateChanged(ecus.size(), QDltConnection::QDltConnectionOffline,
ecuItem->getHostname());

void MainWindow::reloadLogFileStop()
{
ecus.append(ecuItem);
}

project.ecu->addTopLevelItems(ecus);

/* Update the ECU list in control plugins */
updatePluginsECUList();
}

void MainWindow::reloadLogFileProgressMax(int num)
Expand Down Expand Up @@ -2062,13 +2070,21 @@ void MainWindow::reloadLogFileFinishFilter()
settings->updateContextLoadingFile) {
const QList<int> &msgIndexList = dltIndexer->getGetLogInfoList();

// FIXME: this is slow operation running in the main loop
QDltMsg msg;
EcuTree ecuTree;
for (const auto msgIndex : msgIndexList) {
if (qfile.getMsg(msgIndex, msg)) {
contextLoadingFile(msg);
auto ctrlMsg = qdlt::msg::payload::parse(msg.getPayload(), msg.getEndianness() == QDltMsg::DltEndiannessBigEndian);
std::visit([&ecuTree, ecuId = msg.getEcuid()](auto&& payload) {
using T = std::decay_t<decltype(payload)>;
if constexpr (std::is_same_v<T, qdlt::msg::payload::GetLogInfo>) {
ecuTree.add(ecuId, payload);
}
}, ctrlMsg);
}
}
project.ecu->clear();
populateEcusTree(std::move(ecuTree));
}

// reconnect ecus again
Expand Down
10 changes: 3 additions & 7 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ namespace Ui {
class MainWindow;
}

struct EcuTree;

class MainWindow : public QMainWindow
{
Q_OBJECT
Expand Down Expand Up @@ -236,13 +238,8 @@ class MainWindow : public QMainWindow

void getSelectedItems(EcuItem **ecuitem,ApplicationItem** appitem,ContextItem** conitem);

/**
* @brief Reload the complete log file
* @param update if this parameter is false, the file is loaded the first time, if true the reload is performed because of a changed configuration
*
*/
void reloadLogFileStop();
void reloadLogFile(bool update=false, bool multithreaded = true);
void populateEcusTree(EcuTree&& ecuTree);

void reloadLogFileDefaultFilter();

Expand Down Expand Up @@ -275,7 +272,6 @@ class MainWindow : public QMainWindow
void updatePluginsECUList();
void updatePlugins();
void updatePlugin(PluginItem *item);
void contextLoadingFile(const QDltMsg &msg);
void versionString(const QDltMsg &msg);
void pluginsAutoload(QString version);

Expand Down
4 changes: 3 additions & 1 deletion src/src.pro
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ SOURCES += main.cpp \
dltmsgqueue.cpp \
dltfileindexerthread.cpp \
dltfileindexerdefaultfilterthread.cpp \
ecutree.cpp \

# Show these headers in the project
HEADERS += mainwindow.h \
Expand Down Expand Up @@ -180,7 +181,8 @@ HEADERS += mainwindow.h \
dltmsgqueue.h \
dltfileindexerthread.h \
dltfileindexerdefaultfilterthread.h \
mcudpsocket.h
mcudpsocket.h \
ecutree.h \

# Compile these UI files
FORMS += mainwindow.ui \
Expand Down

0 comments on commit 1b050c0

Please sign in to comment.