Peano
Loading...
Searching...
No Matches
NVTXLogger.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 UseNVIDIA
19#include <nvtx3/nvToolsExt.h>
20#endif
21
22tarch::logging::Log tarch::logging::NVTXLogger::_log( "tarch::logging::NVTXLogger" );
23
25
27
31
35
36void tarch::logging::NVTXLogger::indent( bool, const std::string&, const std::string& ) {}
37
38std::string tarch::logging::NVTXLogger::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
85
86void tarch::logging::NVTXLogger::debug(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
87 #if !defined(PeanoDebug) || PeanoDebug<1
88 assertion(false);
89 #endif
90
91 std::string outputMessage = constructMessageString(
93 timestampNanoseconds, rank, threadId, trace, message
94 );
95
96 tarch::multicore::Lock lockCout( _semaphore );
97 std::cout << outputMessage;
98}
99
100
101void tarch::logging::NVTXLogger::info(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
102 std::string outputMessage = constructMessageString(
104 timestampNanoseconds, rank, threadId, trace, message
105 );
106
107 tarch::multicore::Lock lockCout( _semaphore );
108 std::cout << outputMessage;
109}
110
111
112void tarch::logging::NVTXLogger::warning(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
113 std::string outputMessage = constructMessageString(
114 "warning",
115 timestampNanoseconds, rank, threadId, trace, message
116 );
117
118 tarch::multicore::Lock lockCout( _semaphore );
119 std::cerr << outputMessage;
120 std::cerr.flush();
121}
122
123
124void tarch::logging::NVTXLogger::error(long int timestampNanoseconds, int rank, int threadId, const std::string& trace, const std::string& message) {
125 std::string outputMessage = constructMessageString(
126 "error",
127 timestampNanoseconds, rank, threadId, trace, message
128 );
129
130 tarch::multicore::Lock lockCout( _semaphore );
131 std::cerr << outputMessage;
132 std::cerr.flush();
133
134 close();
135}
136
137
139 [[maybe_unused]] long int timestampNanoseconds,
140 [[maybe_unused]] int rank,
141 [[maybe_unused]] int threadId,
142 [[maybe_unused]] const std::string& trace,
143 [[maybe_unused]] const std::string& message
144) {
145 #ifdef UseNVIDIA
146 nvtxRangePush(trace.c_str());
147 #endif
148}
149
150
152 [[maybe_unused]] long int timestampNanoseconds,
153 [[maybe_unused]] int rank,
154 [[maybe_unused]] int threadId,
155 [[maybe_unused]] const std::string& trace,
156 [[maybe_unused]] const std::string& message
157) {
158 #ifdef UseNVIDIA
159 nvtxRangePop();
160 #endif
161}
162
163
165 std::cout.flush();
166 std::cerr.flush();
167}
#define assertion(expr)
Log Device.
Definition Log.h:516
Command Line Logger.
Definition NVTXLogger.h:48
void indent(bool indent, const std::string &trace, const std::string &message)
Tells the logger to increment/decrement the indent.
static NVTXLogger _singleton
Definition NVTXLogger.h:52
void traceIn(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)
NVTXLogger()
It's a singleton.
static NVTXLogger & getInstance()
void warning(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Write Warning.
void traceOut(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
std::string getTimeStampHumanReadable(long int timestampNanoseconds) const
void error(long int timestampNanoseconds, int rank, int threadId, const std::string &trace, const std::string &message)
Write Error.
void debug(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.
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