Peano
Loading...
Searching...
No Matches
ITACLogger.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#ifdef UseITAC
19#include <VT.h>
20#endif
21
22
23tarch::logging::Log tarch::logging::ITACLogger::_log( "tarch::logging::ITACLogger" );
24
25
27
28
30 _firstTraceWritten(false) {
31 #ifdef UseITAC
32 #if !defined(Parallel)
33 VT_initialize();
34 #endif
35 #endif
36}
37
38
42
43
45 close();
46 #ifdef UseITAC
47 #if !defined(Parallel)
48 VT_finalize();
49 #endif
50 #endif
51}
52
53
55 #ifdef UseITAC
56 VT_traceoff();
57 #endif
58}
59
60
62 #ifdef UseITAC
63 VT_traceon();
64 #endif
65}
66
67
68void tarch::logging::ITACLogger::indent( bool, const std::string&, const std::string& ) {}
69
70
71std::string tarch::logging::ITACLogger::getTimeStampHumanReadable( long int timestampNanoseconds ) const {
72 long int timestampSeconds = timestampNanoseconds / 1000 / 1000 / 1000;
73 const int HourScaling = 60 * 60;
74 long int hours = timestampSeconds / HourScaling;
75 timestampSeconds = timestampSeconds - HourScaling * hours;
76
77 const int MinutesScaling = 60;
78 long int minutes = timestampSeconds / MinutesScaling;
79 timestampSeconds = timestampSeconds - MinutesScaling * minutes;
80
81 const int SecondsScaling = 1;
82 long int seconds = timestampSeconds / SecondsScaling;
83
84 std::stringstream result;
85 if (hours<10) {
86 result << "0";
87 }
88 result << hours << ":";
89 if (minutes<10) {
90 result << "0";
91 }
92 result << minutes << ":";
93 if (seconds<10) {
94 result << "0";
95 }
96 result << seconds;
97 return result.str();
98}
99
100
102 [[maybe_unused]] std::string messageType,
103 [[maybe_unused]] long int timestampNanoseconds,
104 [[maybe_unused]] int rank,
105 [[maybe_unused]] int threadId,
106 [[maybe_unused]] const std::string& trace,
107 [[maybe_unused]] const std::string& message
108) {
109 std::ostringstream result;
110 result << getTimeStampHumanReadable(timestampNanoseconds)
111 << "\trank:" << rank
112 << "\t" << trace
113 << "\t" << messageType
114 << "\t" << message
115 << "\n";
116 return result.str();
117}
118
119
120void tarch::logging::ITACLogger::debug(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
121 #if !defined(PeanoDebug) || PeanoDebug<1
122 assertion(false);
123 #endif
124
125 std::string outputMessage = constructMessageString(
127 timestampNanoseconds, rank, threadId, trace, message
128 );
129
130 tarch::multicore::Lock lockCout( _semaphore );
131 std::cout << outputMessage;
132}
133
134
135void tarch::logging::ITACLogger::info(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
136 std::string outputMessage = constructMessageString(
138 timestampNanoseconds, rank, threadId, trace, message
139 );
140
141 tarch::multicore::Lock lockCout( _semaphore );
142 std::cout << outputMessage;
143}
144
145
146void tarch::logging::ITACLogger::warning(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
147 std::string outputMessage = constructMessageString(
148 "warning",
149 timestampNanoseconds, rank, threadId, trace, message
150 );
151
152 tarch::multicore::Lock lockCout( _semaphore );
153 std::cerr << outputMessage;
154 std::cerr.flush();
155}
156
157
158void tarch::logging::ITACLogger::error(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
159 std::string outputMessage = constructMessageString(
160 "error",
161 timestampNanoseconds, rank, threadId, trace, message
162 );
163
164 tarch::multicore::Lock lockCout( _semaphore );
165 std::cerr << outputMessage;
166 std::cerr.flush();
167
168 close();
170}
171
172
174 [[maybe_unused]] long int timestampNanoseconds,
175 [[maybe_unused]] int rank,
176 [[maybe_unused]] int threadId,
177 [[maybe_unused]] const std::string& trace,
178 [[maybe_unused]] const std::string& message
179) {
180 #ifdef UseITAC
181 if (not _firstTraceWritten) {
182 _firstTraceWritten = true;
183 continueTrace();
184 }
185
186 tarch::multicore::Lock lock(_semaphore);
187
188 if (_itacHandles.count(trace)==0) {
189 int newHandle;
190 VT_funcdef( trace.c_str() , VT_NOCLASS, &newHandle );
191 _itacHandles.insert( std::pair<std::string, int>(trace,newHandle) );
192 }
193
194 VT_begin(_itacHandles[trace.c_str()]);
195 #endif
196}
197
198
200 [[maybe_unused]] long int timestampNanoseconds,
201 [[maybe_unused]] int rank,
202 [[maybe_unused]] int threadId,
203 [[maybe_unused]] const std::string& trace,
204 [[maybe_unused]] const std::string& message
205) {
206 #ifdef UseITAC
207 VT_end(_itacHandles[trace.c_str()]);
208 #endif
209}
210
211
213 std::cout.flush();
214 std::cerr.flush();
215}
#define assertion(expr)
Command Line Logger.
Definition ITACLogger.h:51
void info(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
void traceIn(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.
static ITACLogger _singleton
Definition ITACLogger.h:55
std::string getTimeStampHumanReadable(long int timestampNanoseconds) const
void traceOut(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
void error(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Write Error.
void warning(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Write Warning.
std::string constructMessageString(std::string messageType, long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Construct message string.
void debug(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
ITACLogger()
It's a singleton.
static ITACLogger & getInstance()
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:592
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