plugins: RealtimeLogger plugin

Logs access to a given global variable of the SUT, given by
a symbol name, and outputs value when variable is written to file.
Format:
<Simulation time>;<Value of variable>

Change-Id: I81b581e571be4255a1a2200c41e7c16657ddfd3d
This commit is contained in:
Martin Hoffmann
2013-10-17 18:10:15 +02:00
committed by Gerrit Code Review
parent 443b3e4919
commit 5d867be83b
3 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,10 @@
set(PLUGIN_NAME realtimelogger)
set(MY_PLUGIN_SRCS
RealtimeLogger.cc
RealtimeLogger.hpp
)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
## Build library
add_library(fail-${PLUGIN_NAME} ${MY_PLUGIN_SRCS})

View File

@ -0,0 +1,50 @@
#include "RealtimeLogger.hpp"
#include "sal/Listener.hpp"
#include "sal/Memory.hpp"
using namespace std;
using namespace fail;
bool RealtimeLogger::run()
{
MemoryManager& mm = simulator.getMemoryManager();
uint32_t value; //! @todo more generic datatype
m_log << "Realtime Logger started. Listening to: " << m_symbol << std::endl;
MemAccessListener ev_mem(m_symbol.getAddress());
if(m_ostream.is_open()) {
m_log << "Writing output to: " << m_outputfile << std::endl;
while (true) {
simulator.addListenerAndResume(&ev_mem);
/* A Memory Accesses happend: Get simulation time and log it */
fail::simtime_t simtime = simulator.getTimerTicks();
mm.getBytes(m_symbol.getAddress(), m_symbol.getSize(), &value);
handleEvent(simtime, value);
}
} else {
m_log << "No output file." << std::endl;
}
return true;
}
void RealtimeLogger::handleEvent(fail::simtime_t simtime, uint32_t value)
{
simtime_t per_second = simulator.getTimerTicksPerSecond();
double sec = (double)simtime / per_second;
double msec = sec*1000;
if(m_ostream.is_open()){
m_ostream << std::dec << msec << ";" << value << std::endl;
}
}

View File

@ -0,0 +1,50 @@
#ifndef __REALTIMELOGGER_HPP__
#define __REALTIMELOGGER_HPP__
#include <string>
#include <unistd.h>
#include "efw/ExperimentFlow.hpp"
#include "config/FailConfig.hpp"
#include "util/Logger.hpp"
#include <fstream>
#include "util/ElfReader.hpp"
/**
* @class RealtimeLogger
* @brief Listens to a memory location and outputs content on write access
* from SUT to file
*/
class RealtimeLogger : public fail::ExperimentFlow
{
private:
const fail::ElfSymbol m_symbol; //!< the target's memory symbol the plugin is listening on
std::string m_outputfile; //!< the output filename
fail::Logger m_log; //!< debug output
std::ofstream m_ostream; //!< Outputfile stream
public:
/**
* Constructor of RealtimeLogger.
*
* @param symbol The global memory address the plugin listens to
* @param outputfile The path to the file to write the output to
*/
RealtimeLogger( const fail::ElfSymbol & symbol, const std::string& outputfile ) : m_symbol(symbol), m_outputfile(outputfile) , m_log("RTLogger", false) {
m_ostream.open(m_outputfile.c_str() );
if(!m_ostream.is_open()){
m_log << "Could not open " << m_outputfile.c_str() << " for writing." << std::endl;
}
}
bool run();
private:
/**
* Handle the memory event
*/
void handleEvent(fail::simtime_t simtime, uint32_t value);
};
#endif // __REALTIMELOGGER_HPP__