40 template <
class vartype,
class ratio>
43 return std::chrono::duration_cast<SimulationTime>(std::chrono::duration<vartype, ratio>(time));
57 template <
class vartype,
class ratio>
60 return std::chrono::duration_cast<std::chrono::duration<vartype, ratio>>(time).count();
88 #define _CONCAT_(x,y) x ## y
89 #define CONCAT(x,y) _CONCAT_(x,y)
90 #define ANONYMOUS_VAR CONCAT(_anonymous, __LINE__)
95 #define NRP_LOG_TIME_SET_START TimeProfiler::setStartTime()
100 #define NRP_LOG_TIME(filename) TimeProfiler::recordTimePoint(filename)
101 #define NRP_LOG_TIME_WITH_COMMENT(filename, comment) TimeProfiler::recordTimePoint(filename, comment)
106 #define NRP_LOG_TIME_BLOCK(filename) auto ANONYMOUS_VAR = BlockProfiler(filename)
107 #define NRP_LOG_TIME_BLOCK_WITH_COMMENT(filename, comment) auto ANONYMOUS_VAR = BlockProfiler(filename, comment)
112 struct TimeProfiler {
114 static std::map<std::string, std::ofstream> files;
115 static std::chrono::time_point<std::chrono::high_resolution_clock> start;
116 static std::string timeLogsDir;
121 static void setStartTime();
130 static void recordTimePoint(
const std::string& filename,
const std::string& comment =
"",
bool newLine =
true);
139 static void recordDuration(
const std::string& filename,
const std::chrono::microseconds& duration,
const std::string& comment =
"",
bool newLine =
true);
145 struct BlockProfiler {
146 BlockProfiler() =
delete;
154 BlockProfiler(
const std::string& filename,
const std::string& comment=
"");
158 std::chrono::time_point<std::chrono::high_resolution_clock> _start;
159 std::string _filename;
160 std::string _comment;
164 #define NRP_LOG_TIME_SET_START
165 #define NRP_LOG_TIME(filename)
166 #define NRP_LOG_TIME_WITH_COMMENT(filename, comment)
167 #define NRP_LOG_TIME_BLOCK(filename)
168 #define NRP_LOG_TIME_BLOCK_WITH_COMMENT(filename, comment)
171 #endif // TIME_UTILS_H