Tomographer  v1.0a
Tomographer C++ Framework Documentation
Tomographer::MultiProc::OMP::ThreadSanitizerLogger< BaseLogger > Class Template Reference

Wrapper logger to call non-thread-safe loggers from a multithreaded environment. More...

#include <tomographer/multiprocomp.h>

+ Inheritance diagram for Tomographer::MultiProc::OMP::ThreadSanitizerLogger< BaseLogger >:
+ Collaboration diagram for Tomographer::MultiProc::OMP::ThreadSanitizerLogger< BaseLogger >:

Public Member Functions

template<typename... MoreArgs>
 ThreadSanitizerLogger (BaseLogger &logger, MoreArgs...)
 
void emit_log (int level, const char *origin, const std::string &msg)
 
template<bool dummy = true>
std::enable_if< dummy &&Logger::LoggerTraits< BaseLogger >::HasFilterByOrigin, bool >::type filter_by_origin (int level, const char *origin) const
 
- Public Member Functions inherited from Tomographer::Logger::LoggerBase< ThreadSanitizerLogger< BaseLogger > >
 LoggerBase (int level_=INFO)
 Construct the base logger object. More...
 
void error (const char *origin, const char *fmt,...)
 emit an error message More...
 
void error (const char *origin, const std::string &msg)
 emit an error message More...
 
void error (const char *origin, Fn f)
 emit an error message More...
 
void warning (const char *origin, const char *fmt,...)
 emit a warning message More...
 
void warning (const char *origin, const std::string &msg)
 emit a warning message More...
 
void warning (const char *origin, Fn f)
 emit a warning message More...
 
void info (const char *origin, const char *fmt,...)
 emit an information/notice message More...
 
void info (const char *origin, const std::string &msg)
 emit an information/notice message More...
 
void info (const char *origin, Fn f)
 emit an information/notice message More...
 
void debug (const char *origin, const char *fmt,...)
 emit an debug message More...
 
void debug (const char *origin, const std::string &msg)
 emit an debug message More...
 
void debug (const char *origin, Fn f)
 emit an debug message More...
 
void longdebug (const char *origin, const char *fmt,...)
 emit a very verbose debugging message More...
 
void longdebug (const char *origin, const std::string &msg)
 emit a very verbose debugging message More...
 
void longdebug (const char *origin, Fn f)
 emit a very verbose debugging message More...
 
void log (int level, const char *origin, const char *fmt,...)
 emit a log message at the given log level. More...
 
void log (int level, const char *origin, const std::string &msg)
 emit a log message at the given log level. More...
 
void log (int level, const char *origin, Fn f)
 emit a log message at the given log level. More...
 
void log (const char *origin, const char *fmt,...)
 emit a log message at the given log level. More...
 
void log (const char *origin, const char *fmt, va_list ap)
 emit a log message at the given log level. More...
 
void log (const char *origin, const std::string &msg)
 emit a log message at the given log level. More...
 
void log (const char *origin, Fn f)
 emit a log message at the given log level. More...
 
bool enabled_for (int level_) const
 Check whether messages at the given log level are enabled. More...
 
int level () const
 Get the log level set for this logger. More...
 

Additional Inherited Members

- Public Types inherited from Tomographer::Logger::LoggerBase< ThreadSanitizerLogger< BaseLogger > >
enum  
 Shortcuts to properties defined in the traits class.
 
- Static Public Member Functions inherited from Tomographer::Logger::LoggerBase< ThreadSanitizerLogger< BaseLogger > >
static bool statically_enabled_for (int level)
 Check whether the logger is statically disabled for some levels. More...
 
static bool statically_enabled_for ()
 Static version of statically_enabled_for() More...
 
- Protected Member Functions inherited from Tomographer::Logger::LoggerBase< ThreadSanitizerLogger< BaseLogger > >
int getLevel () const
 
int getLevel () const
 
ThreadSanitizerLogger< BaseLogger > * derived ()
 
const ThreadSanitizerLogger< BaseLogger > * derived () const
 
void setLogLevel (int level)
 Store a new run-time log level. More...
 

Detailed Description

template<typename BaseLogger>
class Tomographer::MultiProc::OMP::ThreadSanitizerLogger< BaseLogger >

Wrapper logger to call non-thread-safe loggers from a multithreaded environment.

Wraps calls to emit log messages into a OpenMP

#pragma omp critical

sections, which ensure thread-safety of the logging. Of course don't log too often, as this will drastically slow down the execution of your program!!

Note
If the base logger is already thread-safe (as defined by LoggerTraits::IsThreadSafe), then the call to emit the log is not wrapped in a critical section, but directly called.
Todo:
Buffer log entries here to optimize performance and to limit the number of #pragma omp critical blocks.
Warning
The runtime level of this logger is fixed to the level of the base logger at the moment of instanciation. Any changes to the level of the base logger afterwards will not be reflected here. This is for thread-safety/consistency reasons.
If your base logger has a filter_by_origin() mechanism and is not thread-safe, this might be very slow because a OMP critical section is opened on each log message which needs to be tested for its origin.

Example usage:

SomeLogger logger;
#pragma omp parallel ...
{
... // parallel code
// it may not be safe to log to `logger`, because it might not be
// thread-safe. So create a ThreadSanitizerLogger to which we can
// safely log and pass to sub-routines that want a logger.
ThreadSanitizerLogger<SomeLogger> threadsafelogger(logger);
threadsafelogger.longdebug( ... ); // safe
// the logger may be passed to subtasks
FidelityHistogramStatsCollector<MatrQ, double, ThreadSanitizerLogger<SomeLogger> >
fidelityhistogramcollector(..., threadsafelogger);
... // more parallel code
}

Definition at line 167 of file multiprocomp.h.


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