From 5d867be83b9db41d85e07b46ec3d2039caaeaaaf Mon Sep 17 00:00:00 2001 From: Martin Hoffmann Date: Thu, 17 Oct 2013 18:10:15 +0200 Subject: [PATCH] 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: ; Change-Id: I81b581e571be4255a1a2200c41e7c16657ddfd3d --- src/plugins/realtimelogger/CMakeLists.txt | 10 ++++ src/plugins/realtimelogger/RealtimeLogger.cc | 50 +++++++++++++++++++ src/plugins/realtimelogger/RealtimeLogger.hpp | 50 +++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 src/plugins/realtimelogger/CMakeLists.txt create mode 100644 src/plugins/realtimelogger/RealtimeLogger.cc create mode 100644 src/plugins/realtimelogger/RealtimeLogger.hpp diff --git a/src/plugins/realtimelogger/CMakeLists.txt b/src/plugins/realtimelogger/CMakeLists.txt new file mode 100644 index 00000000..644908f4 --- /dev/null +++ b/src/plugins/realtimelogger/CMakeLists.txt @@ -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}) diff --git a/src/plugins/realtimelogger/RealtimeLogger.cc b/src/plugins/realtimelogger/RealtimeLogger.cc new file mode 100644 index 00000000..c0bbee21 --- /dev/null +++ b/src/plugins/realtimelogger/RealtimeLogger.cc @@ -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; + } +} + + diff --git a/src/plugins/realtimelogger/RealtimeLogger.hpp b/src/plugins/realtimelogger/RealtimeLogger.hpp new file mode 100644 index 00000000..50942f5c --- /dev/null +++ b/src/plugins/realtimelogger/RealtimeLogger.hpp @@ -0,0 +1,50 @@ +#ifndef __REALTIMELOGGER_HPP__ + #define __REALTIMELOGGER_HPP__ + +#include +#include +#include "efw/ExperimentFlow.hpp" +#include "config/FailConfig.hpp" +#include "util/Logger.hpp" +#include +#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__