Peano
Loading...
Searching...
No Matches
tarch::logging::NVTXLogger Class Reference

Command Line Logger. More...

#include <NVTXLogger.h>

Collaboration diagram for tarch::logging::NVTXLogger:

Public Member Functions

 ~NVTXLogger ()
 
bool getLogMachineName () const
 Is public as some analysis frameworks check explicitly whether these features are switched on.
 
bool getLogThreadName () const
 Is public as some analysis frameworks check explicitly whether these features are switched on.
 
bool getLogTrace () const
 Is public as some analysis frameworks check explicitly whether these features are switched on.
 
bool getLogTimeStamp () const
 Is public as some analysis frameworks check explicitly whether these features are switched on.
 
void debug (long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
 
void info (long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
 
void warning (long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
 Write Warning.
 
void error (long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
 Write Error.
 
void traceIn (long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
 
void traceOut (long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
 
void indent (bool indent, const std::string &trace, const std::string &message)
 Tells the logger to increment/decrement the indent.
 
void close ()
 

Static Public Member Functions

static NVTXLoggergetInstance ()
 

Private Member Functions

NVTXLoggeroperator= (const CommandLineLogger &)=delete
 Declared private since assignment does not make sense for an output class (output information mismatch).
 
 NVTXLogger (const NVTXLogger &)=delete
 Declared private since copying does not make sense for an output class (output information mismatch).
 
std::string constructMessageString (std::string messageType, long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
 Construct message string.
 
 NVTXLogger ()
 It's a singleton.
 
std::string getTimeStampHumanReadable (long int timestampNanoseconds) const
 

Private Attributes

tarch::multicore::BooleanSemaphore _semaphore
 

Static Private Attributes

static Log _log
 
static NVTXLogger _singleton
 

Detailed Description

Command Line Logger.

Standard log output device. Implements the LogHandle. Usually there's only one instance of this class for only the Log type aggregates it in a static way. For a detailed description of this compiler flags please browse through the static consts of the class or the howto page.

An interesting issue is the behaviour of the command line logger in the parallel mode if debug is switched on. In this case the number of messages soon becomes unreadable for any human. Thus, the command line logger internally creates one output file rank.log for each rank and writes all the information into this file. info, warnings and errors are written (in short form) to std::cout / std::cerr, too.

If the debug mode is not set, all information is written to std::cout.

Note, that if multithreading is switched on (TBB-flag), the access to std::cout or the logfile respectively is synchronized. The other methods are not thread-safe and should be called only in safe context for defined behaviour.

Version
Revision
1.19
Author
Tobias Weinzierl, Wolfgang Eckhardt

Definition at line 48 of file NVTXLogger.h.

Constructor & Destructor Documentation

◆ NVTXLogger() [1/2]

tarch::logging::NVTXLogger::NVTXLogger ( const NVTXLogger & )
privatedelete

Declared private since copying does not make sense for an output class (output information mismatch).

◆ NVTXLogger() [2/2]

tarch::logging::NVTXLogger::NVTXLogger ( )
private

It's a singleton.

Definition at line 26 of file NVTXLogger.cpp.

◆ ~NVTXLogger()

tarch::logging::NVTXLogger::~NVTXLogger ( )

Definition at line 32 of file NVTXLogger.cpp.

Member Function Documentation

◆ close()

void tarch::logging::NVTXLogger::close ( )

Definition at line 164 of file NVTXLogger.cpp.

◆ constructMessageString()

std::string tarch::logging::NVTXLogger::constructMessageString ( std::string messageType,
long int timestampNanoseconds,
int rank,
int threadId,
const std::string & trace,
const std::string & message )
private

Construct message string.

!!! Thread Safety

The message string relies on the global field _indent. This one might change throughout the execution of this method. However, I accept such a behavior: Changing _indent throughout the message execution makes the method add the wrong number of whitespaces in front of the message. That is a 'bug' we can accept.

To satisfy Intel Inspector et al at least slightly, I copy over _indent before I actually construct the message string. So the indent can't change while we add the spaces/tabs to the output.

Definition at line 67 of file NVTXLogger.cpp.

◆ debug()

void tarch::logging::NVTXLogger::debug ( long int timestampNanoseconds,
int rank,
int threadId,
const std::string & trace,
const std::string & message )

Definition at line 86 of file NVTXLogger.cpp.

References assertion, and tarch::logging::LogFilter::FilterListEntry::TargetDebug.

Referenced by kernel_impl.impl::alloc(), kernel_impl.impl::loop(), and kernel_impl.impl::stencil().

Here is the caller graph for this function:

◆ error()

void tarch::logging::NVTXLogger::error ( long int timestampNanoseconds,
int rank,
int threadId,
const std::string & trace,
const std::string & message )

Write Error.

In the implementation, I call a flush on cout before I write to cerr. Otherwise, the cerr messages might overtake cout. Before the operation returns, it does a flush on cerr, too. Otherwise, the message might not occur, i.e. the application might shut down before the message is flushed to the terminal.

Definition at line 124 of file NVTXLogger.cpp.

◆ getInstance()

tarch::logging::NVTXLogger & tarch::logging::NVTXLogger::getInstance ( )
static

Definition at line 28 of file NVTXLogger.cpp.

◆ getLogMachineName()

bool tarch::logging::NVTXLogger::getLogMachineName ( ) const

Is public as some analysis frameworks check explicitly whether these features are switched on.

◆ getLogThreadName()

bool tarch::logging::NVTXLogger::getLogThreadName ( ) const

Is public as some analysis frameworks check explicitly whether these features are switched on.

◆ getLogTimeStamp()

bool tarch::logging::NVTXLogger::getLogTimeStamp ( ) const

Is public as some analysis frameworks check explicitly whether these features are switched on.

◆ getLogTrace()

bool tarch::logging::NVTXLogger::getLogTrace ( ) const

Is public as some analysis frameworks check explicitly whether these features are switched on.

◆ getTimeStampHumanReadable()

std::string tarch::logging::NVTXLogger::getTimeStampHumanReadable ( long int timestampNanoseconds) const
private

Definition at line 38 of file NVTXLogger.cpp.

◆ indent()

void tarch::logging::NVTXLogger::indent ( bool indent,
const std::string & trace,
const std::string & message )

Tells the logger to increment/decrement the indent.

!!! Thread Safety

_indent is a global static field shared by all threads. If we increment or decrement it, this is first of all a read followed by a write. Consequently data races could occur and the counter could become smaller than zero. This ain't possible in the sequential code as each increment is accompanied by a decrement. The following table illustrates the race:

|| value of _indent || Thread 1 || Thread 2 | 2 | initial condition | initial condition | | enter indent(false) | enter indent(true) | | fetch indent into register | fetch indent into register | | register value -= 2 | register value += 2 | 4 | is a little bit slower | write back new value of indent | 0 | write back new value of indent |

To avoid this data race, I introduced a semaphore. This one could also be implemented with TBB's atomic construct, e.g., but I prefer the semaphor / critical section technique.

Parameters
traceNeeded in debug mode to be able to find out who called indent(false) without an indent(true)
messageNeeded in debug mode to be able to find out who called indent(false) without an indent(true)

Definition at line 36 of file NVTXLogger.cpp.

Referenced by printers.cpp_printer::alloc(), kernel_impl.impl::alloc(), printers.cpp_printer::loop(), kernel_impl.impl::loop(), and kernel_impl.impl::stencil().

Here is the caller graph for this function:

◆ info()

void tarch::logging::NVTXLogger::info ( long int timestampNanoseconds,
int rank,
int threadId,
const std::string & trace,
const std::string & message )

◆ operator=()

NVTXLogger & tarch::logging::NVTXLogger::operator= ( const CommandLineLogger & )
privatedelete

Declared private since assignment does not make sense for an output class (output information mismatch).

◆ traceIn()

void tarch::logging::NVTXLogger::traceIn ( long int timestampNanoseconds,
int rank,
int threadId,
const std::string & trace,
const std::string & message )

Definition at line 138 of file NVTXLogger.cpp.

◆ traceOut()

void tarch::logging::NVTXLogger::traceOut ( long int timestampNanoseconds,
int rank,
int threadId,
const std::string & trace,
const std::string & message )

Definition at line 151 of file NVTXLogger.cpp.

◆ warning()

void tarch::logging::NVTXLogger::warning ( long int timestampNanoseconds,
int rank,
int threadId,
const std::string & trace,
const std::string & message )

Write Warning.

In the implementation, I call a flush on cout before I write to cerr. Otherwise, the cerr messages might overtake cout. Before the operation returns, it does a flush on cerr, too. Otherwise, the message might not occur, i.e. the application might shut down before the message is flushed to the terminal.

Definition at line 112 of file NVTXLogger.cpp.

Field Documentation

◆ _log

tarch::logging::Log tarch::logging::NVTXLogger::_log
staticprivate

Definition at line 50 of file NVTXLogger.h.

◆ _semaphore

tarch::multicore::BooleanSemaphore tarch::logging::NVTXLogger::_semaphore
private

Definition at line 54 of file NVTXLogger.h.

◆ _singleton

tarch::logging::NVTXLogger tarch::logging::NVTXLogger::_singleton
staticprivate

Definition at line 52 of file NVTXLogger.h.


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