![]() |
Peano
|
Command Line Logger. More...
#include <ITTLogger.h>
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 ITTLogger & | getInstance () |
Private Member Functions | |
ITTLogger & | operator= (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 |
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.
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.
Debug information is piped to \texttt{cout}. The same happens with writes to the \texttt{info} log level.
All logs are protected by a semaphore to avoid race conditions.
Definition at line 58 of file ITTLogger.h.
|
privatedelete |
Declared private since copying does not make sense for an output class (output information mismatch).
|
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.
tarch::logging::ITTLogger::~ITTLogger | ( | ) |
Definition at line 35 of file ITTLogger.cpp.
void tarch::logging::ITTLogger::close | ( | ) |
Definition at line 195 of file ITTLogger.cpp.
|
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.
void tarch::logging::ITTLogger::continueTrace | ( | ) |
Definition at line 47 of file ITTLogger.cpp.
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().
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().
|
static |
Definition at line 30 of file ITTLogger.cpp.
bool tarch::logging::ITTLogger::getLogMachineName | ( | ) | const |
Is public as some analysis frameworks check explicitly whether these features are switched on.
bool tarch::logging::ITTLogger::getLogThreadName | ( | ) | const |
Is public as some analysis frameworks check explicitly whether these features are switched on.
bool tarch::logging::ITTLogger::getLogTimeStamp | ( | ) | const |
Is public as some analysis frameworks check explicitly whether these features are switched on.
bool tarch::logging::ITTLogger::getLogTrace | ( | ) | const |
Is public as some analysis frameworks check explicitly whether these features are switched on.
|
private |
Definition at line 57 of file ITTLogger.cpp.
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.
trace | Needed in debug mode to be able to find out who called indent(false) without an indent(true) |
message | Needed 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().
void tarch::logging::ITTLogger::info | ( | long int | timestampNanoseconds, |
int | rank, | ||
int | threadId, | ||
const std::string & | trace, | ||
const std::string & | message ) |
Definition at line 121 of file ITTLogger.cpp.
References tarch::logging::LogFilter::FilterListEntry::TargetInfo.
|
privatedelete |
Declared private since assignment does not make sense for an output class (output information mismatch).
void tarch::logging::ITTLogger::suspendTrace | ( | ) |
Definition at line 40 of file ITTLogger.cpp.
void tarch::logging::ITTLogger::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
Definition at line 159 of file ITTLogger.cpp.
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.
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.
|
private |
Definition at line 70 of file ITTLogger.h.
|
staticprivate |
Definition at line 60 of file ITTLogger.h.
|
private |
Definition at line 64 of file ITTLogger.h.
|
staticprivate |
Definition at line 62 of file ITTLogger.h.