From a126fa86bf67f758ef253e6bc0af3aa36ec7064d Mon Sep 17 00:00:00 2001 From: Derek Christ Date: Mon, 16 Aug 2021 14:40:31 +0200 Subject: [PATCH] Check for vcd export dependencies. The TraceAnalyzer now checks if the python module pyvcd is installed and if not prints a warning and disables the export option. --- .../businessObjects/pythoncaller.cpp | 37 +++++++++++++++- .../businessObjects/pythoncaller.h | 10 ++++- .../scripts/checkDependencies.py | 42 +++++++++++++++++++ DRAMSys/traceAnalyzer/traceanalyzer.cpp | 6 ++- DRAMSys/traceAnalyzer/traceanalyzer.ui | 18 ++++++++ 5 files changed, 109 insertions(+), 4 deletions(-) create mode 100755 DRAMSys/traceAnalyzer/scripts/checkDependencies.py diff --git a/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.cpp b/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.cpp index ce890fa5..f6490107 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.cpp +++ b/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.cpp @@ -34,6 +34,7 @@ * Robert Gernhardt * Matthias Jung * Felipe S. Prado + * Derek Christ */ #include "pythoncaller.h" @@ -57,8 +58,10 @@ PythonCaller::PythonCaller() : "/../../DRAMSys/traceAnalyzer/scripts/"), plotsModuleName("plots"), plotsFunctionName("generatePlots"), + checkDependenciesModuleName("checkDependencies"), vcdExportModuleName("vcdExport"), - vcdExportFunctionName("dumpVcd") + vcdExportFunctionName("dumpVcd"), + vcdExportDependenciesFunctionName("checkVcd") { Py_Initialize(); PyObject *sysPath = PySys_GetObject((char *)"path"); @@ -79,7 +82,12 @@ PythonCaller::PythonCaller() : pGetMetricsFunction = loadFunctionFromModule(metricModuleName, getMetricFunctionName); - pVcdExportFunction = loadFunctionFromModule(vcdExportModuleName, vcdExportFunctionName); + pVcdExportDependenciesFunction = loadFunctionFromModule(checkDependenciesModuleName, vcdExportDependenciesFunctionName); + + if (vcdExportDependenciesAvailable()) + pVcdExportFunction = loadFunctionFromModule(vcdExportModuleName, vcdExportFunctionName); + else + std::cerr << "Warning: Python module pyvcd not installed! Exporting as VCD not possible." << std::endl; } @@ -162,6 +170,19 @@ PyObject *PythonCaller::callFunctionWithStringArgument(PyObject *function, return pResult; } +PyObject *PythonCaller::callFunctionWithoutArguments(PyObject *function) +{ + assert(PyCallable_Check(function)); + PyObject *pResult = PyObject_CallObject(function, NULL); + + if (!pResult) { + PyErr_Print(); + throw runtime_error(string("Error in calling python function")); + } + + return pResult; +} + TraceTestResults PythonCaller::runTestsOnTrace(QString pathToTrace) { TraceTestResults traceTestResult(QFileInfo(pathToTrace).baseName()); @@ -228,9 +249,21 @@ QString PythonCaller::generatePlotsOnTrace(QString pathToTrace) QString PythonCaller::exportAsVcd(QString pathToTrace) { + if (!pVcdExportFunction) + return QString(); + PyObject *pResult = callFunctionWithStringArgument(pVcdExportFunction, pathToTrace); QString dump(PyUnicode_AsUTF8(pResult)); Py_DECREF(pResult); return dump; } + +bool PythonCaller::vcdExportDependenciesAvailable() +{ + PyObject *result = callFunctionWithoutArguments(pVcdExportDependenciesFunction); + bool available = PyObject_IsTrue(result); + Py_DECREF(result); + + return available; +} diff --git a/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.h b/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.h index bf50aa0d..9adab575 100644 --- a/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.h +++ b/DRAMSys/traceAnalyzer/businessObjects/pythoncaller.h @@ -34,6 +34,7 @@ * Robert Gernhardt * Matthias Jung * Felipe S. Prado + * Derek Christ */ #ifndef PYTHONCALLER_H @@ -62,22 +63,29 @@ public: std::vector getMetrics(QString pathToTrace); QString generatePlotsOnTrace(QString pathToTrace); + bool vcdExportDependenciesAvailable(); QString exportAsVcd(QString pathToTrace); private: PyObject *pRunTestsFunction, *pCalculateMetricsFunction, *pGetMetricsFunction; PyObject *pGenPlotsFunction; - PyObject *pVcdExportFunction; + PyObject *pVcdExportFunction = nullptr; + PyObject *pVcdExportDependenciesFunction; PyObject *loadFunctionFromModule(std::string moduleName, std::string functionName); std::string testModuleName, testFunctionName, metricModuleName, metricFunctionName, getMetricFunctionName, pathToScripts; std::string plotsModuleName; std::string plotsFunctionName; + + std::string checkDependenciesModuleName; + std::string vcdExportModuleName; std::string vcdExportFunctionName; + std::string vcdExportDependenciesFunctionName; PyObject *callFunctionWithStringArgument(PyObject *function, QString argument); + PyObject *callFunctionWithoutArguments(PyObject *function); PyObject *callMetricsFunction(PyObject *function, QString argument, std::vector list); }; diff --git a/DRAMSys/traceAnalyzer/scripts/checkDependencies.py b/DRAMSys/traceAnalyzer/scripts/checkDependencies.py new file mode 100755 index 00000000..3cfe9dfd --- /dev/null +++ b/DRAMSys/traceAnalyzer/scripts/checkDependencies.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2021, Technische Universität Kaiserslautern +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER +# OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Authors: +# Derek Christ + +import importlib.util + +def checkVcd(): + if (spec := importlib.util.find_spec("vcd")) is not None: + return True + else: + return False diff --git a/DRAMSys/traceAnalyzer/traceanalyzer.cpp b/DRAMSys/traceAnalyzer/traceanalyzer.cpp index bc79755c..6e599219 100644 --- a/DRAMSys/traceAnalyzer/traceanalyzer.cpp +++ b/DRAMSys/traceAnalyzer/traceanalyzer.cpp @@ -121,7 +121,11 @@ void TraceAnalyzer::openTracefile(const QString &path) // Enable actions ui->actionReload_all->setEnabled(true); ui->actionSaveChangesToDB->setEnabled(true); - ui->actionExportAsVCD->setEnabled(true); + + PythonCaller pythonCaller; + if (pythonCaller.vcdExportDependenciesAvailable()) + ui->actionExportAsVCD->setEnabled(true); + ui->actionClose_all->setEnabled(true); ui->actionTest->setEnabled(true); ui->actionMetrics->setEnabled(true); diff --git a/DRAMSys/traceAnalyzer/traceanalyzer.ui b/DRAMSys/traceAnalyzer/traceanalyzer.ui index ba36d631..6a364223 100644 --- a/DRAMSys/traceAnalyzer/traceanalyzer.ui +++ b/DRAMSys/traceAnalyzer/traceanalyzer.ui @@ -85,6 +85,9 @@ + + false + Reload databases @@ -93,6 +96,9 @@ + + false + Save changes to DB @@ -101,6 +107,9 @@ + + false + Close all @@ -127,6 +136,9 @@ + + false + Test @@ -135,6 +147,9 @@ + + false + Metrics @@ -143,6 +158,9 @@ + + false + Export as VCD