Switch to pybind11

With the switch to pybind11, the complexity of the Python integration
in the TraceAnalyzer can be greatly reduced. The new code is much
easier to understand and fixes a number of bugs regarding the Python
integration.
This commit is contained in:
2023-05-11 12:28:21 +02:00
parent 50e87b7a63
commit edd52e0fe1
13 changed files with 130 additions and 274 deletions

View File

@@ -51,11 +51,9 @@
#include "evaluationtool.h"
#include "ui_evaluationtool.h"
using namespace std;
EvaluationTool::EvaluationTool(PythonCaller &pythonCaller, QWidget *parent) :
QWidget(parent),
ui(new Ui::EvaluationTool), resourcesRelPath("/../../dram/resources/scripts"""), pythonCaller(pythonCaller)
ui(new Ui::EvaluationTool), pythonCaller(pythonCaller)
{
ui->setupUi(this);
traceFilesModel = new QStandardItemModel(this);
@@ -85,16 +83,15 @@ void EvaluationTool::showAndEvaluateMetrics(QList<QString> paths)
show();
ui->toolBox->setCurrentIndex(1);
selectMetrics->setMetrics(getMetrics());
cout << "done" << endl;
}
vector<string> EvaluationTool::getMetrics()
std::vector<std::string> EvaluationTool::getMetrics()
{
vector<string> metrics;
std::vector<std::string> metrics;
for (int row = 0; row < traceFilesModel->rowCount(); ++row) {
TraceFileItem *item = static_cast<TraceFileItem *>(traceFilesModel->item(row));
vector<string> result = pythonCaller.getMetrics(item->getPath());
if (result.size() > metrics.size())
std::vector<std::string> result = PythonCaller::availableMetrics(item->getPath().toStdString());
if (result.size() > metrics.size()) // TODO use std::set
metrics = result;
}
return metrics;
@@ -127,22 +124,21 @@ void EvaluationTool::on_btn_calculateMetrics_clicked()
void EvaluationTool::getSelectedMetrics()
{
vector<long> selectedMetrics;
std::vector<long> selectedMetrics;
for (QCheckBox *metric : selectMetrics->metrics) {
selectedMetrics.push_back(metric->isChecked());
}
calculateMetrics(selectedMetrics);
}
void EvaluationTool::calculateMetrics(vector<long> selectedMetrics)
void EvaluationTool::calculateMetrics(std::vector<long> selectedMetrics)
{
ui->traceMetricTreeWidget->clear();
for (int row = 0; row < traceFilesModel->rowCount(); ++row) {
TraceFileItem *item = static_cast<TraceFileItem *>(traceFilesModel->item(row));
if (item->checkState() == Qt::Checked)
{
TraceCalculatedMetrics result = pythonCaller.calculateMetricsOnTrace(
item->getPath(), selectedMetrics);
TraceCalculatedMetrics result = pythonCaller.evaluateMetrics(item->getPath().toStdString(), selectedMetrics);
calculatedMetrics.push_back(result);
ui->traceMetricTreeWidget->addTraceMetricResults(result);
}
@@ -194,9 +190,9 @@ void EvaluationTool::genPlots()
TraceFileItem *item = static_cast<TraceFileItem *>(traceFilesModel->item(row));
if (item->checkState() == Qt::Checked)
{
ui->traceMetricTreeWidget->addTracePlotResults(QFileInfo(
item->getPath()).baseName(),
pythonCaller.generatePlotsOnTrace(item->getPath()));
ui->traceMetricTreeWidget->addTracePlotResults(
QFileInfo(item->getPath()).baseName(),
PythonCaller::generatePlots(item->getPath().toStdString()).c_str());
}
}
ui->traceMetricTreeWidget->expandAll();