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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
* Robert Gernhardt
|
||||
* Matthias Jung
|
||||
* Felipe S. Prado
|
||||
* Derek Christ
|
||||
*/
|
||||
|
||||
#ifndef PYTHONCALLER_H
|
||||
@@ -62,22 +63,29 @@ public:
|
||||
std::vector<std::string> 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<long> list);
|
||||
};
|
||||
|
||||
42
DRAMSys/traceAnalyzer/scripts/checkDependencies.py
Executable file
42
DRAMSys/traceAnalyzer/scripts/checkDependencies.py
Executable file
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -85,6 +85,9 @@
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionReload_all">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reload databases</string>
|
||||
</property>
|
||||
@@ -93,6 +96,9 @@
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSaveChangesToDB">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save changes to DB</string>
|
||||
</property>
|
||||
@@ -101,6 +107,9 @@
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClose_all">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close all</string>
|
||||
</property>
|
||||
@@ -127,6 +136,9 @@
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionTest">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Test</string>
|
||||
</property>
|
||||
@@ -135,6 +147,9 @@
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionMetrics">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Metrics</string>
|
||||
</property>
|
||||
@@ -143,6 +158,9 @@
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExportAsVCD">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Export as VCD</string>
|
||||
</property>
|
||||
|
||||
Reference in New Issue
Block a user