iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::EventLog Class Reference

#include <nrt/Core/Debugging/EventLog.H>

A simple event logger.

Use to log point as well as extended events, recording event times and also a simple string message for each event. The log of events can be either streamed online to an std::ostream or saved to a text file for later ofline analysis.

Point events (which have no duration) are logged by calling nrt::EventLog::checkpoint(). These are typically used to log the time at which critical steps, branching points, decision points, or checkpoints in a program are reached.

Extended events (which have a duration) are logged by creating an nrt::Event object by calling nrt::EventLog::event(); the time at which the Event object is constructed represents the start time of the extended event, while the destruction time of the Event object will mark the end time of the extended event.

EventLog can always operate in offline mode, in which case a call to nrt::EventLog::save() is necessary to save the log to an std::ostream for later offline analysis. Or it can additionally operate in online mode if nrt::EventLog::setOnlineStream() is called with a valid std::ostream.

See Also

Definition at line 166 of file EventLog.H.

Inheritance diagram for nrt::EventLog:

Public Member Functions

void checkpoint (std::string const &msg)
 Log a point event (no duration)
void checkpoint (char const *msg)
 Log a point event (no duration), faster version for literal strings.
Event event (std::string const &msg)
 Start logging an extended event. More...
Event event (char const *msg)
 Start logging an extended event, faster version for literal strings.
void save (std::ostream &os) const
 Save entire log to a stream.
void summary (EventLogSummary &s) const
 Save a summary of the entire log.
void setOnlineOstream (std::ostream *os=nullptr)
 Set the ostream to use when logging online (i.e. writing each log entry as it is created) More...

Member Function Documentation

Event nrt::EventLog::event ( std::string const &  msg)

Start logging an extended event.

The start time point is now(), and the end time point will be filled when the Event object is destroyed. Example usage is as follows:

EventLog evl;
while(true) {
Event e = evl.event("Body of while loop"); // start time is now
// ... do things during the event. If we throw here, e will be destroyed and the event properly stopped
} // event destroyed, stop time is set now
void nrt::EventLog::setOnlineOstream ( std::ostream *  os = nullptr)

Set the ostream to use when logging online (i.e. writing each log entry as it is created)

Setting to nullptr will disable online logging, requiring you to explicitly call save() to write out logs.

The documentation for this class was generated from the following file: