Peano
Loading...
Searching...
No Matches
ScorePLogger.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 UseScoreP
19#include <scorep/SCOREP_User.h>
20#endif
21
22tarch::logging::Log tarch::logging::ScorePLogger::_log( "tarch::logging::ScorePLogger" );
23
25
27
31
35
36void tarch::logging::ScorePLogger::indent( bool, const std::string&, const std::string& ) {}
37
38std::string tarch::logging::ScorePLogger::getTimeStampHumanReadable( long int timestampNanoseconds ) const {
39 long int timestampSeconds = timestampNanoseconds / 1000 / 1000 / 1000;
40 const int HourScaling = 60 * 60;
41 long int hours = timestampSeconds / HourScaling;
42 timestampSeconds = timestampSeconds - HourScaling * hours;
43
44 const int MinutesScaling = 60;
45 long int minutes = timestampSeconds / MinutesScaling;
46 timestampSeconds = timestampSeconds - MinutesScaling * minutes;
47
48 const int SecondsScaling = 1;
49 long int seconds = timestampSeconds / SecondsScaling;
50
51 std::stringstream result;
52 if (hours<10) {
53 result << "0";
54 }
55 result << hours << ":";
56 if (minutes<10) {
57 result << "0";
58 }
59 result << minutes << ":";
60 if (seconds<10) {
61 result << "0";
62 }
63 result << seconds;
64 return result.str();
65}
66
68 [[maybe_unused]] std::string messageType,
69 [[maybe_unused]] long int timestampNanoseconds,
70 [[maybe_unused]] int rank,
71 [[maybe_unused]] int threadId,
72 [[maybe_unused]] const std::string& trace,
73 [[maybe_unused]] const std::string& message
74) {
75 std::ostringstream result;
76 result << getTimeStampHumanReadable(timestampNanoseconds)
77 << "\trank:" << rank
78 << "\t" << trace
79 << "\t" << messageType
80 << "\t" << message
81 << "\n";
82 return result.str();
83}
84
85void tarch::logging::ScorePLogger::debug(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
86 #if !defined(PeanoDebug) || PeanoDebug<1
87 assertion(false);
88 #endif
89
90 std::string outputMessage = constructMessageString(
92 timestampNanoseconds, rank, threadId, trace, message
93 );
94
95 tarch::multicore::Lock lockCout( _semaphore );
96 std::cout << outputMessage;
97}
98
99void tarch::logging::ScorePLogger::info(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
100 std::string outputMessage = constructMessageString(
102 timestampNanoseconds, rank, threadId, trace, message
103 );
104
105 tarch::multicore::Lock lockCout( _semaphore );
106 std::cout << outputMessage;
107}
108
109void tarch::logging::ScorePLogger::warning(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
110 std::string outputMessage = constructMessageString(
111 "warning",
112 timestampNanoseconds, rank, threadId, trace, message
113 );
114
115 tarch::multicore::Lock lockCout( _semaphore );
116 std::cerr << outputMessage;
117 std::cerr.flush();
118}
119
120void tarch::logging::ScorePLogger::error(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
121 std::string outputMessage = constructMessageString(
122 "error",
123 timestampNanoseconds, rank, threadId, trace, message
124 );
125
126 tarch::multicore::Lock lockCout( _semaphore );
127 std::cerr << outputMessage;
128 std::cerr.flush();
129
130 close();
132}
133
135 [[maybe_unused]] long int timestampNanoseconds,
136 [[maybe_unused]] int rank,
137 [[maybe_unused]] int threadId,
138 [[maybe_unused]] const std::string& trace,
139 [[maybe_unused]] const std::string& message
140) {
141 #ifdef UseScoreP
142 tarch::multicore::Lock lock(_semaphore);
143
144 if (_scorePHandles.count(trace)==0) {
145 _scorePHandles.insert( std::pair<std::string, int>(trace,SCOREP_USER_INVALID_REGION) );
146 }
147
148 SCOREP_USER_REGION_ENTER(_scorePHandles[trace]);
149 #endif
150}
151
153 [[maybe_unused]] long int timestampNanoseconds,
154 [[maybe_unused]] int rank,
155 [[maybe_unused]] int threadId,
156 [[maybe_unused]] const std::string& trace,
157 [[maybe_unused]] const std::string& message
158) {
159 #ifdef UseScoreP
160 SCOREP_USER_REGION_LEAVE(_scorePHandles[trace]);
161 #endif
162}
163
165 std::cout.flush();
166 std::cerr.flush();
167}
#define assertion(expr)
Log Device.
Definition Log.h:516
Command Line Logger.
void debug(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)
static ScorePLogger & getInstance()
void traceIn(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
ScorePLogger()
It's a singleton.
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 getTimeStampHumanReadable(long int timestampNanoseconds) const
void info(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.
std::string constructMessageString(std::string messageType, long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Construct message string.
static ScorePLogger _singleton
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