Peano 4
Loading...
Searching...
No Matches
ITTLogger.cpp
Go to the documentation of this file.
2
3#include "tarch/Assertions.h"
4
7
8#include "LogFilter.h"
9
10#include <sstream>
11#include <stdlib.h>
12#include <chrono>
13
14#include "../mpi/Rank.h"
15
16#include "config.h"
17
18
19tarch::logging::Log tarch::logging::ITTLogger::_log( "tarch::logging::ITTLogger" );
20
21
23
24
26 _firstTraceWritten(false) {
27}
28
29
33
34
38
39
41 #ifdef UseITT
42 __itt_pause();
43 #endif
44}
45
46
48 #ifdef UseITT
49 __itt_resume();
50 #endif
51}
52
53
54void tarch::logging::ITTLogger::indent( bool, const std::string&, const std::string& ) {}
55
56
57std::string tarch::logging::ITTLogger::getTimeStampHumanReadable( long int timestampNanoseconds ) const {
58 long int timestampSeconds = timestampNanoseconds / 1000 / 1000 / 1000;
59 const int HourScaling = 60 * 60;
60 long int hours = timestampSeconds / HourScaling;
61 timestampSeconds = timestampSeconds - HourScaling * hours;
62
63 const int MinutesScaling = 60;
64 long int minutes = timestampSeconds / MinutesScaling;
65 timestampSeconds = timestampSeconds - MinutesScaling * minutes;
66
67 const int SecondsScaling = 1;
68 long int seconds = timestampSeconds / SecondsScaling;
69
70 std::stringstream result;
71 if (hours<10) {
72 result << "0";
73 }
74 result << hours << ":";
75 if (minutes<10) {
76 result << "0";
77 }
78 result << minutes << ":";
79 if (seconds<10) {
80 result << "0";
81 }
82 result << seconds;
83 return result.str();
84}
85
86
88 [[maybe_unused]] std::string messageType,
89 [[maybe_unused]] long int timestampNanoseconds,
90 [[maybe_unused]] int rank,
91 [[maybe_unused]] int threadId,
92 [[maybe_unused]] const std::string& trace,
93 [[maybe_unused]] const std::string& message
94) {
95 std::ostringstream result;
96 result << getTimeStampHumanReadable(timestampNanoseconds)
97 << "\trank:" << rank
98 << "\t" << trace
99 << "\t" << messageType
100 << "\t" << message
101 << "\n";
102 return result.str();
103}
104
105
106void tarch::logging::ITTLogger::debug(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
107 #if !defined(PeanoDebug) || PeanoDebug<1
108 assertion(false);
109 #endif
110
111 std::string outputMessage = constructMessageString(
113 timestampNanoseconds, rank, threadId, trace, message
114 );
115
116 tarch::multicore::Lock lockCout( _semaphore );
117 std::cout << outputMessage;
118}
119
120
121void tarch::logging::ITTLogger::info(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
122 std::string outputMessage = constructMessageString(
124 timestampNanoseconds, rank, threadId, trace, message
125 );
126
127 tarch::multicore::Lock lockCout( _semaphore );
128 std::cout << outputMessage;
129}
130
131
132void tarch::logging::ITTLogger::warning(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
133 std::string outputMessage = constructMessageString(
134 "warning",
135 timestampNanoseconds, rank, threadId, trace, message
136 );
137
138 tarch::multicore::Lock lockCout( _semaphore );
139 std::cerr << outputMessage;
140 std::cerr.flush();
141}
142
143
144void tarch::logging::ITTLogger::error(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
145 std::string outputMessage = constructMessageString(
146 "error",
147 timestampNanoseconds, rank, threadId, trace, message
148 );
149
150 tarch::multicore::Lock lockCout( _semaphore );
151 std::cerr << outputMessage;
152 std::cerr.flush();
153
154 close();
156}
157
158
160 [[maybe_unused]] long int timestampNanoseconds,
161 [[maybe_unused]] int rank,
162 [[maybe_unused]] int threadId,
163 [[maybe_unused]] const std::string& trace,
164 [[maybe_unused]] const std::string& message
165) {
166 #ifdef UseITT
167 if (not _firstTraceWritten) {
168 _firstTraceWritten = true;
169 continueTrace();
170 }
171
172 tarch::multicore::Lock lock(_semaphore);
173
174 if (_ittHandles.count(trace)==0) {
175 __itt_event event = __itt_event_create(trace.c_str(), trace.size() );
176 _ittHandles.insert( std::pair<std::string, __itt_event>(trace,event) );
177 }
178
179 __itt_event_start(_ittHandles[trace.c_str()]);
180 #endif
181}
182
184 [[maybe_unused]] long int timestampNanoseconds,
185 [[maybe_unused]] int rank,
186 [[maybe_unused]] int threadId,
187 [[maybe_unused]] const std::string& trace,
188 [[maybe_unused]] const std::string& message
189) {
190 #ifdef UseITT
191 __itt_event_end(_ittHandles[trace.c_str()]);
192 #endif
193}
194
196 std::cout.flush();
197 std::cerr.flush();
198}
#define assertion(expr)
Command Line Logger.
Definition ITTLogger.h:58
std::string getTimeStampHumanReadable(long int timestampNanoseconds) const
Definition ITTLogger.cpp:57
static ITTLogger _singleton
Definition ITTLogger.h:62
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.
Definition ITTLogger.cpp:54
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.
ITTLogger()
It's a singleton.
Definition ITTLogger.cpp:25
void info(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
std::string constructMessageString(std::string messageType, long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Construct message string.
Definition ITTLogger.cpp:87
void debug(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
static ITTLogger & getInstance()
Definition ITTLogger.cpp:30
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....
Log Device.
Definition Log.h:516
static void abort(int errorCode)
A proper abort in an MPI context has to use MPI_Abort.
Definition Rank.cpp:591
Create a lock around a boolean semaphore region.
Definition Lock.h:19
static const std::string TargetDebug
Definition LogFilter.h:35
static const std::string TargetInfo
Definition LogFilter.h:34