diff --git a/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.cpp b/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.cpp index f6490107..9184a889 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.cpp @@ -47,6 +47,12 @@ using namespace std; +PythonCaller &PythonCaller::instance() +{ + static PythonCaller instance; + return instance; +} + PythonCaller::PythonCaller() : testModuleName("tests"), testFunctionName("runTests"), diff --git a/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.h b/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.h index 9adab575..0f843189 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.h +++ b/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.h @@ -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 list); @@ -67,6 +68,9 @@ public: QString exportAsVcd(QString pathToTrace); private: + PythonCaller(); + ~PythonCaller(); + PyObject *pRunTestsFunction, *pCalculateMetricsFunction, *pGetMetricsFunction; PyObject *pGenPlotsFunction; PyObject *pVcdExportFunction = nullptr; diff --git a/DRAMSys/traceAnalyzer/evaluationtool.cpp b/DRAMSys/traceAnalyzer/evaluationtool.cpp index 83223bdd..8820eb1f 100644 --- a/DRAMSys/traceAnalyzer/evaluationtool.cpp +++ b/DRAMSys/traceAnalyzer/evaluationtool.cpp @@ -35,6 +35,7 @@ * Matthias Jung * Éder F. Zulian * Felipe S. Prado + * Derek Christ */ #include @@ -105,7 +106,7 @@ vector EvaluationTool::getMetrics() vector metrics; for (int row = 0; row < traceFilesModel->rowCount(); ++row) { TraceFileItem *item = static_cast(traceFilesModel->item(row)); - vector result = pythonCaller.getMetrics(item->getPath()); + vector 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 selectedMetrics) TraceFileItem *item = static_cast(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(); diff --git a/DRAMSys/traceAnalyzer/evaluationtool.h b/DRAMSys/traceAnalyzer/evaluationtool.h index 509cfc3c..95a232fa 100644 --- a/DRAMSys/traceAnalyzer/evaluationtool.h +++ b/DRAMSys/traceAnalyzer/evaluationtool.h @@ -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 - #include #include #include @@ -96,7 +91,6 @@ private: std::vector calculatedMetrics; QString resourcesRelPath; SelectMetrics *selectMetrics; - PythonCaller pythonCaller; class TraceFileItem : public QStandardItem { diff --git a/DRAMSys/traceAnalyzer/traceanalyzer.cpp b/DRAMSys/traceAnalyzer/traceanalyzer.cpp index 6e599219..02103ce7 100644 --- a/DRAMSys/traceAnalyzer/traceanalyzer.cpp +++ b/DRAMSys/traceAnalyzer/traceanalyzer.cpp @@ -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); diff --git a/DRAMSys/traceAnalyzer/tracefiletab.cpp b/DRAMSys/traceAnalyzer/tracefiletab.cpp index b42c743c..d8b7f457 100644 --- a/DRAMSys/traceAnalyzer/tracefiletab.cpp +++ b/DRAMSys/traceAnalyzer/tracefiletab.cpp @@ -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);