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

Command Line Logger. More...

#include <ITTLogger.h>

Collaboration diagram for tarch::logging::ITTLogger:

Public Member Functions

 ~ITTLogger ()
 
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)
 https://www.intel.com/content/www/us/en/docs/vtune-profiler/user-guide/2023-0/event-api.html
 
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 ()
 
void suspendTrace ()
 
void continueTrace ()
 

Static Public Member Functions

static ITTLoggergetInstance ()
 

Private Member Functions

ITTLoggeroperator= (const CommandLineLogger &)=delete
 Declared private since assignment does not make sense for an output class (output information mismatch).
 
 ITTLogger (const ITTLogger &)=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.
 
 ITTLogger ()
 It's a singleton.
 
std::string getTimeStampHumanReadable (long int timestampNanoseconds) const
 

Private Attributes

tarch::multicore::BooleanSemaphore _semaphore
 
bool _firstTraceWritten
 

Static Private Attributes

static Log _log
 
static ITTLogger _singleton
 

Detailed Description

Command Line Logger.

Details on this can be found on Intel's collection control pages.

Standard log output device. Implements the LogHandle. Usually there's only one instance of this class, as the Log type (which is implicitly used by all log and trace macros) forwards all data to a singleton.

Error and warnings

All error and warning messages are dumped to \texttt{cerr}. The logger automatically aborts the application if it encounters an error, once the error message is written and \texttt{cerr} is flushed.

Info and debugging

Debug information is piped to \texttt{cout}. The same happens with writes to the \texttt{info} log level.

Thread safety

All logs are protected by a semaphore to avoid race conditions.

Author
Tobias Weinzierl, Wolfgang Eckhardt

Definition at line 58 of file ITTLogger.h.

Constructor & Destructor Documentation

◆ ITTLogger() [1/2]

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

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

◆ ITTLogger() [2/2]

tarch::logging::ITTLogger::ITTLogger ( )
private

It's a singleton.

According to Intel's documentation, ITAC is automatically initialised by MPI_Init(). However, if we have no MPI, then we have to initialise manually.

Definition at line 25 of file ITTLogger.cpp.

◆ ~ITTLogger()

tarch::logging::ITTLogger::~ITTLogger ( )

Definition at line 35 of file ITTLogger.cpp.

Member Function Documentation

◆ close()

void tarch::logging::ITTLogger::close ( )

Definition at line 195 of file ITTLogger.cpp.

◆ constructMessageString()

std::string tarch::logging::ITTLogger::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 87 of file ITTLogger.cpp.

◆ continueTrace()

void tarch::logging::ITTLogger::continueTrace ( )

Definition at line 47 of file ITTLogger.cpp.

◆ debug()

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

Definition at line 106 of file ITTLogger.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::ITTLogger::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 144 of file ITTLogger.cpp.

References tarch::mpi::Rank::abort().

Here is the call graph for this function:

◆ getInstance()

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

Definition at line 30 of file ITTLogger.cpp.

◆ getLogMachineName()

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

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

◆ getLogThreadName()

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

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

◆ getLogTimeStamp()

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

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

◆ getLogTrace()

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

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

◆ getTimeStampHumanReadable()

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

Definition at line 57 of file ITTLogger.cpp.

◆ indent()

void tarch::logging::ITTLogger::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 54 of file ITTLogger.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::ITTLogger::info ( long int timestampNanoseconds,
int rank,
int threadId,
const std::string & trace,
const std::string & message )

◆ operator=()

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

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

◆ suspendTrace()

void tarch::logging::ITTLogger::suspendTrace ( )

Definition at line 40 of file ITTLogger.cpp.

◆ traceIn()

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

◆ traceOut()

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

Definition at line 183 of file ITTLogger.cpp.

◆ warning()

void tarch::logging::ITTLogger::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 132 of file ITTLogger.cpp.

Field Documentation

◆ _firstTraceWritten

bool tarch::logging::ITTLogger::_firstTraceWritten
private

Definition at line 70 of file ITTLogger.h.

◆ _log

tarch::logging::Log tarch::logging::ITTLogger::_log
staticprivate

Definition at line 60 of file ITTLogger.h.

◆ _semaphore

tarch::multicore::BooleanSemaphore tarch::logging::ITTLogger::_semaphore
private

Definition at line 64 of file ITTLogger.h.

◆ _singleton

tarch::logging::ITTLogger tarch::logging::ITTLogger::_singleton
staticprivate

Definition at line 62 of file ITTLogger.h.


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