Make a singleton out of the PythonCaller
Prevents unnecessary instances of PythonCaller.
This commit is contained in:
@@ -47,6 +47,12 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
PythonCaller &PythonCaller::instance()
|
||||
{
|
||||
static PythonCaller instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
PythonCaller::PythonCaller() :
|
||||
testModuleName("tests"),
|
||||
testFunctionName("runTests"),
|
||||
|
||||
@@ -55,8 +55,9 @@
|
||||
class PythonCaller
|
||||
{
|
||||
public:
|
||||
PythonCaller();
|
||||
~PythonCaller();
|
||||
static PythonCaller &instance();
|
||||
PythonCaller(const PythonCaller &other) = delete;
|
||||
|
||||
TraceTestResults runTestsOnTrace(QString pathToTrace);
|
||||
TraceCalculatedMetrics calculateMetricsOnTrace(QString pathToTrace,
|
||||
std::vector<long> list);
|
||||
@@ -67,6 +68,9 @@ public:
|
||||
QString exportAsVcd(QString pathToTrace);
|
||||
|
||||
private:
|
||||
PythonCaller();
|
||||
~PythonCaller();
|
||||
|
||||
PyObject *pRunTestsFunction, *pCalculateMetricsFunction, *pGetMetricsFunction;
|
||||
PyObject *pGenPlotsFunction;
|
||||
PyObject *pVcdExportFunction = nullptr;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
* Matthias Jung
|
||||
* Éder F. Zulian
|
||||
* Felipe S. Prado
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#include <QFileInfo>
|
||||
@@ -105,7 +106,7 @@ vector<string> EvaluationTool::getMetrics()
|
||||
vector<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());
|
||||
vector<string> result = PythonCaller::instance().getMetrics(item->getPath());
|
||||
if (result.size() > metrics.size())
|
||||
metrics = result;
|
||||
}
|
||||
@@ -152,7 +153,7 @@ void EvaluationTool::runTests()
|
||||
if (item->checkState() == Qt::Checked)
|
||||
{
|
||||
boxesChecked = true;
|
||||
TraceTestResults traceTestResult = pythonCaller.runTestsOnTrace(item->getPath());
|
||||
TraceTestResults traceTestResult = PythonCaller::instance().runTestsOnTrace(item->getPath());
|
||||
if (!traceTestResult.hasPassedAllTests())
|
||||
allTestsPassed = false;
|
||||
ui->traceTestTreeWidget->addTraceTestResult(traceTestResult);
|
||||
@@ -193,7 +194,7 @@ void EvaluationTool::calculateMetrics(vector<long> selectedMetrics)
|
||||
TraceFileItem *item = static_cast<TraceFileItem *>(traceFilesModel->item(row));
|
||||
if (item->checkState() == Qt::Checked)
|
||||
{
|
||||
TraceCalculatedMetrics result = pythonCaller.calculateMetricsOnTrace(
|
||||
TraceCalculatedMetrics result = PythonCaller::instance().calculateMetricsOnTrace(
|
||||
item->getPath(), selectedMetrics);
|
||||
calculatedMetrics.push_back(result);
|
||||
ui->traceMetricTreeWidget->addTraceMetricResults(result);
|
||||
@@ -253,7 +254,7 @@ void EvaluationTool::genPlots()
|
||||
{
|
||||
ui->traceMetricTreeWidget->addTracePlotResults(QFileInfo(
|
||||
item->getPath()).baseName(),
|
||||
pythonCaller.generatePlotsOnTrace(item->getPath()));
|
||||
PythonCaller::instance().generatePlotsOnTrace(item->getPath()));
|
||||
}
|
||||
}
|
||||
ui->traceMetricTreeWidget->expandAll();
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
* Matthias Jung
|
||||
* Éder F. Zulian
|
||||
* Felipe S. Prado
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef EVALUATIONTOOL_H
|
||||
@@ -42,12 +43,6 @@
|
||||
|
||||
#include "selectmetrics.h"
|
||||
|
||||
// Workaround for CMAKE and Python
|
||||
#ifdef slots
|
||||
#undef slots
|
||||
#endif
|
||||
#include <Python.h>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QStandardItem>
|
||||
#include <QStandardItemModel>
|
||||
@@ -96,7 +91,6 @@ private:
|
||||
std::vector<TraceCalculatedMetrics> calculatedMetrics;
|
||||
QString resourcesRelPath;
|
||||
SelectMetrics *selectMetrics;
|
||||
PythonCaller pythonCaller;
|
||||
|
||||
class TraceFileItem : public QStandardItem
|
||||
{
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
* Janik Schlemminger
|
||||
* Robert Gernhardt
|
||||
* Matthias Jung
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#include "traceanalyzer.h"
|
||||
@@ -122,8 +123,7 @@ void TraceAnalyzer::openTracefile(const QString &path)
|
||||
ui->actionReload_all->setEnabled(true);
|
||||
ui->actionSaveChangesToDB->setEnabled(true);
|
||||
|
||||
PythonCaller pythonCaller;
|
||||
if (pythonCaller.vcdExportDependenciesAvailable())
|
||||
if (PythonCaller::instance().vcdExportDependenciesAvailable())
|
||||
ui->actionExportAsVCD->setEnabled(true);
|
||||
|
||||
ui->actionClose_all->setEnabled(true);
|
||||
|
||||
@@ -93,8 +93,7 @@ void TraceFileTab::exportAsVCD()
|
||||
QString filename = QFileDialog::getSaveFileName(this, "Export to VCD", "",
|
||||
"VCD files (*.vcd)");
|
||||
|
||||
PythonCaller pythonCaller;
|
||||
QString dump = pythonCaller.exportAsVcd(path);
|
||||
QString dump = PythonCaller::instance().exportAsVcd(path);
|
||||
|
||||
if (filename != "") {
|
||||
QFile file(filename);
|
||||
|
||||
Reference in New Issue
Block a user