refactoring of debugManager
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
<builder autoBuildTarget="all" buildPath="${workspace_loc:/dram}/build-simulation" cleanBuildTarget="clean" enableAutoBuild="false" id="org.eclipse.cdt.build.core.internal.builder.1698165306" incrementalBuildTarget="all" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="org.eclipse.cdt.build.core.internal.builder"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1509734096" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
|
||||
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug.789860529" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.exe.debug">
|
||||
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.2041174282" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.exe.debug.option.optimization.level.2041174282" name="Optimization Level" superClass="gnu.cpp.compiler.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.exe.debug.option.debugging.level.2092267417" name="Debug Level" superClass="gnu.cpp.compiler.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
|
||||
<option id="gnu.cpp.compiler.option.include.paths.1823643375" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
|
||||
<listOptionValue builtIn="false" value="/opt/systemc-2.3.0/include"/>
|
||||
@@ -90,24 +90,24 @@
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||
<storageModule moduleId="refreshScope" versionNumber="2">
|
||||
<configuration configurationName="unit_test"/>
|
||||
<configuration configurationName="Release">
|
||||
<resource resourceType="PROJECT" workspacePath="/DRAM-Model"/>
|
||||
</configuration>
|
||||
<configuration configurationName="unit_test"/>
|
||||
<configuration configurationName="platformArchitect">
|
||||
<resource resourceType="PROJECT" workspacePath="/DRAM"/>
|
||||
</configuration>
|
||||
<configuration configurationName="build-simulation"/>
|
||||
<configuration configurationName="testing"/>
|
||||
<configuration configurationName="Debug">
|
||||
<resource resourceType="PROJECT" workspacePath="/DRAM-Model"/>
|
||||
</configuration>
|
||||
<configuration configurationName="simulation-build">
|
||||
<resource resourceType="PROJECT" workspacePath="/dram"/>
|
||||
</configuration>
|
||||
<configuration configurationName="Debug">
|
||||
<resource resourceType="PROJECT" workspacePath="/DRAM-Model"/>
|
||||
</configuration>
|
||||
<configuration configurationName="standalone"/>
|
||||
<configuration configurationName="build-testing"/>
|
||||
<configuration configurationName="simulation"/>
|
||||
<configuration configurationName="build-testing"/>
|
||||
</storageModule>
|
||||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings">
|
||||
<doc-comment-owner id="org.eclipse.cdt.internal.ui.text.doctools.NullDocCommentOwner">
|
||||
|
||||
@@ -23,7 +23,7 @@ void DebugManager::printDebug(string message, Sender sender, Importance importan
|
||||
pair<Sender, Importance>(sender, importance));
|
||||
if (show)
|
||||
{
|
||||
cout << "[" << importanceToString(importance) << "]";
|
||||
cout << importanceToString(importance);
|
||||
if (printTime)
|
||||
std::cout << " at " << sc_time_stamp();
|
||||
if (printLocation)
|
||||
@@ -32,16 +32,25 @@ void DebugManager::printDebug(string message, Sender sender, Importance importan
|
||||
}
|
||||
}
|
||||
|
||||
void DebugManager::addToWhiteList(Sender sender, Importance importance)
|
||||
{
|
||||
whiteList.push_back(pair<Sender, Importance>(sender, importance));
|
||||
}
|
||||
|
||||
void DebugManager::addToWhiteList(Sender sender)
|
||||
{
|
||||
addToWhiteList(sender, Importance::Info);
|
||||
addToWhiteList(sender, Importance::Warning);
|
||||
}
|
||||
|
||||
string DebugManager::importanceToString(Importance importancy)
|
||||
{
|
||||
switch (importancy)
|
||||
{
|
||||
case Importance::Info:
|
||||
return "Info";
|
||||
return "";
|
||||
case Importance::Warning:
|
||||
return "Warning";
|
||||
case Importance::Error:
|
||||
return "Error";
|
||||
return "[Warning]";
|
||||
}
|
||||
return "unknown importance";
|
||||
}
|
||||
@@ -56,6 +65,8 @@ string DebugManager::senderToString(Sender sender)
|
||||
return "Scheduler";
|
||||
case Sender::TracePlayer:
|
||||
return "TracePlayer";
|
||||
case Sender::TraceRecorder:
|
||||
return "TraceRecorder";
|
||||
}
|
||||
return "unknown sender";
|
||||
}
|
||||
|
||||
@@ -10,24 +10,26 @@
|
||||
|
||||
#include <systemc.h>
|
||||
|
||||
enum class Importance {Warning, Error, Info};
|
||||
enum class Sender {Core, Scheduler, TracePlayer};
|
||||
enum class Importance {Warning, Info};
|
||||
enum class Sender {Core, Scheduler, TracePlayer, TraceRecorder};
|
||||
|
||||
class DebugManager
|
||||
{
|
||||
public:
|
||||
static DebugManager& getInstance();
|
||||
|
||||
std::vector<std::pair<Sender, Importance>> whiteList;
|
||||
|
||||
bool printTime;
|
||||
bool printLocation;
|
||||
|
||||
void printDebug(std::string message, Sender sender, Importance importance=Importance::Info);
|
||||
void addToWhiteList(Sender sender, Importance importance);
|
||||
void addToWhiteList(Sender sender);
|
||||
|
||||
private:
|
||||
DebugManager() : printTime(true), printLocation(true) {};
|
||||
DebugManager(const DebugManager&);
|
||||
|
||||
std::vector<std::pair<Sender, Importance>> whiteList;
|
||||
std::string senderToString(Sender sender);
|
||||
std::string importanceToString(Importance importancy);
|
||||
|
||||
|
||||
@@ -6,27 +6,22 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
tlmDBPhaseRecorder::tlmDBPhaseRecorder(string name, string pathToURI) :
|
||||
transactionIDCounter(1), PicosecondsPerNanosecond(1e3)
|
||||
tlmDBPhaseRecorder::tlmDBPhaseRecorder(string dbName, string sqlScriptURI) :
|
||||
dbName(dbName), transactionIDCounter(1), PicosecondsPerNanosecond(1e3)
|
||||
{
|
||||
setUpTransactionTerminatingPhases();
|
||||
openDB(name.c_str());
|
||||
createTables(pathToURI);
|
||||
cout << "Created tables in file " << name << std::endl;
|
||||
cout << "Set up terminating phases " << name << std::endl;
|
||||
openDB(dbName.c_str());
|
||||
createTables(sqlScriptURI);
|
||||
prepareSqlStatements();
|
||||
cout << "Prepared statements " << name << std::endl;
|
||||
sqlite3_exec(db, "BEGIN", 0, 0, 0);
|
||||
cout << "Started new transaction " << name << std::endl;
|
||||
|
||||
debugMessage("Starting new database transaction");
|
||||
}
|
||||
|
||||
tlmDBPhaseRecorder::~tlmDBPhaseRecorder()
|
||||
{
|
||||
insertGeneralInfo();
|
||||
sqlite3_exec(db, "COMMIT", 0, 0, 0);
|
||||
cout << "Number of transactions written to DB: " << transactionIDCounter - 1 << endl;
|
||||
cout << "tlmPhaseRecorder:\tEnd Recording" << endl;
|
||||
sqlite3_close(db);
|
||||
if (db)
|
||||
closeConnection();
|
||||
}
|
||||
|
||||
void tlmDBPhaseRecorder::recordPhase(tlm::tlm_generic_payload& trans, tlm::tlm_phase phase,
|
||||
@@ -104,7 +99,7 @@ void tlmDBPhaseRecorder::openDB(std::string name)
|
||||
{
|
||||
if (sqlite3_open(name.c_str(), &db))
|
||||
{
|
||||
cout << "ERROR Cannot open DB" << endl;
|
||||
SC_REPORT_FATAL("Error in TraceRecorder", "Error cannot open database");
|
||||
sqlite3_close(db);
|
||||
}
|
||||
}
|
||||
@@ -120,7 +115,8 @@ void tlmDBPhaseRecorder::insertGeneralInfo()
|
||||
{
|
||||
sqlite3_bind_int64(insertGeneralInfoStatement, 1, transactionIDCounter - 1);
|
||||
sqlite3_bind_int64(insertGeneralInfoStatement, 2, recordingEndTime.value());
|
||||
sqlite3_bind_int(insertGeneralInfoStatement, 3, xmlAddressDecoder::getInstance().getNumberOfBanks());
|
||||
sqlite3_bind_int(insertGeneralInfoStatement, 3,
|
||||
xmlAddressDecoder::getInstance().getNumberOfBanks());
|
||||
sqlite3_bind_text(insertGeneralInfoStatement, 4, "", 0, NULL);
|
||||
sqlite3_bind_int(insertGeneralInfoStatement, 5, 6);
|
||||
sqlite3_bind_text(insertGeneralInfoStatement, 6, "NS", 2, NULL);
|
||||
@@ -181,7 +177,9 @@ void tlmDBPhaseRecorder::introduceNewTransactionToSystem(const sc_time& time,
|
||||
if (id % transactionCommitRate == 0)
|
||||
{
|
||||
sqlite3_exec(db, "COMMIT", 0, 0, 0);
|
||||
cout << "Committing trasaction nr. " << id << " (and previous) to database" << endl;
|
||||
debugMessage(
|
||||
"Committing transactions " + to_string(id - transactionCommitRate + 1) + " - "
|
||||
+ to_string(id));
|
||||
sqlite3_exec(db, "BEGIN", 0, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -198,24 +196,23 @@ void tlmDBPhaseRecorder::executeSqlStatement(sqlite3_stmt* statement)
|
||||
{
|
||||
if (sqlite3_step(statement) != SQLITE_DONE)
|
||||
{
|
||||
cout << "Could not execute statement" << endl;
|
||||
SC_REPORT_FATAL("Error in TraceRecorder", "Could not execute statement");
|
||||
}
|
||||
sqlite3_reset(statement);
|
||||
}
|
||||
void tlmDBPhaseRecorder::executeSqlCommand(string command)
|
||||
{
|
||||
cout << "executing sql-script" << endl;
|
||||
debugMessage("Creating database by running provided sql script");
|
||||
|
||||
char * errMsg = 0;
|
||||
int rc = sqlite3_exec(db, command.c_str(), NULL, 0, &errMsg);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
cout << errMsg << endl;
|
||||
SC_REPORT_FATAL("SQLITE Error", errMsg);
|
||||
sqlite3_free(errMsg);
|
||||
}
|
||||
|
||||
cout << "done executing script" << endl;
|
||||
debugMessage("Database created successfully");
|
||||
}
|
||||
string tlmDBPhaseRecorder::getFileContents(string filename)
|
||||
{
|
||||
@@ -239,3 +236,20 @@ string tlmDBPhaseRecorder::phaseToString(tlm::tlm_phase phase)
|
||||
string str = oss.str();
|
||||
return str;
|
||||
}
|
||||
|
||||
void tlmDBPhaseRecorder::debugMessage(std::string message, Importance importance)
|
||||
{
|
||||
DebugManager::getInstance().printDebug(dbName + " - " + message, Sender::TraceRecorder,
|
||||
Importance::Info);
|
||||
}
|
||||
|
||||
void tlmDBPhaseRecorder::closeConnection()
|
||||
{
|
||||
insertGeneralInfo();
|
||||
sqlite3_exec(db, "COMMIT", 0, 0, 0);
|
||||
debugMessage(
|
||||
"Number of transactions written to DB: " + std::to_string(transactionIDCounter - 1));
|
||||
debugMessage("tlmPhaseRecorder:\tEnd Recording");
|
||||
sqlite3_close(db);
|
||||
db = NULL;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <tlm.h>
|
||||
#include <systemc.h>
|
||||
#include "xmlAddressdecoder.h"
|
||||
#include "DebugManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -19,13 +20,16 @@ class tlmDBPhaseRecorder
|
||||
{
|
||||
public:
|
||||
|
||||
tlmDBPhaseRecorder(std::string name, std::string pathToURI);
|
||||
tlmDBPhaseRecorder(std::string dbName, std::string sqlScriptURI);
|
||||
~tlmDBPhaseRecorder();
|
||||
|
||||
void recordPhase(tlm::tlm_generic_payload &trans, tlm::tlm_phase phase, sc_time time);
|
||||
void recordDebugMessage(std::string message, sc_time time);
|
||||
|
||||
void closeConnection();
|
||||
|
||||
private:
|
||||
std::string dbName;
|
||||
std::string phaseToString(tlm::tlm_phase phase);
|
||||
std::string getFileContents(std::string filename);
|
||||
|
||||
@@ -46,6 +50,8 @@ private:
|
||||
void updatePhaseEndInDB(string phaseName, const sc_time& time, unsigned int transactionID);
|
||||
void insertDebugMessageInDB(string message, const sc_time& time);
|
||||
|
||||
void debugMessage(std::string message, Importance importance = Importance::Info);
|
||||
|
||||
static const int transactionCommitRate = 10000;
|
||||
map<tlm::tlm_generic_payload*, unsigned int> currentTransactionsInSystem;
|
||||
unsigned int transactionIDCounter;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
* Author: robert
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <systemc.h>
|
||||
#include <fstream>
|
||||
@@ -29,47 +27,39 @@ string pathOfFile(string file)
|
||||
return file.substr(0, file.find_last_of('/'));
|
||||
}
|
||||
|
||||
int sc_main(int argc, char **argv) {
|
||||
int sc_main(int argc, char **argv)
|
||||
{
|
||||
string resources = pathOfFile(argv[0]) + string("/../resources/");
|
||||
|
||||
xmlAddressDecoder::URI = resources + string("configs/addressConfig.xml");
|
||||
tlmDBPhaseRecorder *recorder = new tlmDBPhaseRecorder("tpr.tdb", resources + string("scripts/createTraceDB.sql"));
|
||||
tlmDBPhaseRecorder recorder("tpr.tdb", resources + string("scripts/createTraceDB.sql"));
|
||||
TracePlayer<> player("player", resources + string("traces/mediabench-h263encode_32.stl"));
|
||||
|
||||
//DebugManager::getInstance().whiteList.push_back(pair<Sender, Importance>(Sender::TracePlayer, Importance::Info));
|
||||
cout << "Toplevel: build player" << std::endl;
|
||||
Dram<> dram("dram");
|
||||
cout << "Toplevel: build dram" << std::endl;
|
||||
Arbiter<> arbiter("arbiter");
|
||||
cout << "Toplevel: build arbiter" << std::endl;
|
||||
ControllerWrapper<> controller("controller",*recorder);
|
||||
cout << "Toplevel: build controller" << std::endl;
|
||||
ControllerWrapper<> controller("controller", recorder);
|
||||
|
||||
cout << "Toplevel: binding sockets" << std::endl;
|
||||
player.iSocket.bind(arbiter.tSockets[0]);
|
||||
arbiter.iSocket.bind(controller.tSocket);
|
||||
controller.iSocket.bind(dram.tSocket);
|
||||
|
||||
cout << "Toplevel: simulation start" << std::endl;
|
||||
//DebugManager::getInstance().addToWhiteList(Sender::TraceRecorder);
|
||||
|
||||
cout << "Toplevel: simulation start" << std::endl;
|
||||
clock_t begin = clock();
|
||||
sc_start();
|
||||
|
||||
clock_t end = clock();
|
||||
|
||||
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
|
||||
|
||||
cout << "Simulation took " << elapsed_secs << " seconds. You better optimize your model ! " << endl;
|
||||
|
||||
delete recorder;
|
||||
recorder.closeConnection();
|
||||
cout << "Simulation took " << elapsed_secs << " seconds." << endl;
|
||||
|
||||
string testingScript = resources + string("/scripts/tests.py");
|
||||
string runTestCommand = string("python ") + testingScript + string(" tpr.tdb");
|
||||
//system(runTestCommand.c_str());
|
||||
|
||||
string run_tpr = "/home/jonny/git/analyzer/build-traceAnalyzer-Desktop-Debug/traceAnalyzer tpr.tdb";
|
||||
string run_tpr =
|
||||
"/home/jonny/git/analyzer/build-traceAnalyzer-Desktop-Debug/traceAnalyzer tpr.tdb";
|
||||
system(run_tpr.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user