20 #ifndef MIRTK_Profiling_H 21 #define MIRTK_Profiling_H 23 #include "mirtk/CommonExport.h" 25 #include "mirtk/Stream.h" 26 #include "mirtk/String.h" 33 # define MIRTK_UNDEF_NOMINMAX 35 # include <tbb/tick_count.h> 36 # ifdef MIRTK_UNDEF_NOMINMAX 37 # undef MIRTK_UNDEF_NOMINMAX 108 int w = 0,
char c =
' ',
bool left =
false);
122 #ifdef MIRTK_WITH_PROFILING 124 # define MIRTK_START_TIMING() tbb::tick_count t_start = tbb::tick_count::now() 126 # define MIRTK_START_TIMING() clock_t t_start = clock() 129 # define MIRTK_START_TIMING() do {} while (false) 147 #ifdef MIRTK_WITH_PROFILING 149 # define MIRTK_RESET_TIMING() t_start = tbb::tick_count::now() 151 # define MIRTK_RESET_TIMING() t_start = clock() 154 # define MIRTK_RESET_TIMING() do {} while (false) 173 #ifdef MIRTK_WITH_PROFILING 175 # define MIRTK_END_TIMING(section) \ 179 PrintElapsedTime(oss.str().c_str(), \ 180 (tbb::tick_count::now() - t_start).seconds()); \ 183 # define MIRTK_END_TIMING(section) \ 187 PrintElapsedTime(oss.str().c_str(), \ 188 static_cast<double>(clock() - t_start) \ 189 / static_cast<double>(CLOCKS_PER_SEC)); \ 193 # define MIRTK_END_TIMING(section) do {} while (false) 225 #ifdef MIRTK_WITH_PROFILING 227 # define MIRTK_DEBUG_TIMING(level, section) \ 229 if (debug_time >= level) { \ 232 PrintElapsedTime(oss.str().c_str(), \ 233 (tbb::tick_count::now() - t_start).seconds()); \ 237 # define MIRTK_DEBUG_TIMING(level, section) \ 239 if (debug_time >= level) { \ 242 PrintElapsedTime(oss.str().c_str(), \ 243 static_cast<double>(clock() - t_start) \ 244 / static_cast<double>(CLOCKS_PER_SEC)); \ 249 # define MIRTK_DEBUG_TIMING(level, section) do {} while (false) 268 #ifdef MIRTK_WITH_PROFILING 269 # define MIRTKCU_START_TIMING() \ 270 cudaEvent_t e_start, e_stop; \ 271 CudaSafeCall( cudaEventCreate(&e_start) ); \ 272 CudaSafeCall( cudaEventCreate(&e_stop) ); \ 273 CudaSafeCall( cudaEventRecord(e_start, 0) ) 275 # define MIRTKCU_START_TIMING() do {} while (false) 293 #ifdef MIRTK_WITH_PROFILING 294 # define MIRTKCU_RESET_TIMING() CudaSafeCall( cudaEventRecord(e_start, 0) ) 296 # define MIRTKCU_RESET_TIMING() do {} while (false) 317 #ifdef MIRTK_WITH_PROFILING 318 # define MIRTKCU_INTERIM_TIMING(section) \ 321 CudaSafeCall( cudaEventRecord(e_stop, 0) ); \ 322 CudaSafeCall( cudaEventSynchronize(e_stop) ); \ 323 CudaSafeCall( cudaEventElapsedTime(&t_elapsed, e_start, e_stop) ); \ 325 oss << section << " [interim]"; \ 326 PrintElapsedTime(oss.str().c_str(), t_elapsed, TIME_IN_MILLISECONDS); \ 329 # define MIRTKCU_INTERIM_TIMING(section) do {} while (false) 348 #ifdef MIRTK_WITH_PROFILING 349 # define MIRTKCU_END_TIMING(section) \ 352 CudaSafeCall( cudaEventRecord(e_stop, 0) ); \ 353 CudaSafeCall( cudaEventSynchronize(e_stop) ); \ 354 CudaSafeCall( cudaEventElapsedTime(&t_elapsed, e_start, e_stop) ); \ 355 CudaSafeCall( cudaEventDestroy(e_start) ); \ 356 CudaSafeCall( cudaEventDestroy(e_stop) ); \ 358 oss << section << " [GPU]"; \ 359 PrintElapsedTime(oss.str().c_str(), t_elapsed, TIME_IN_MILLISECONDS); \ 362 # define MIRTKCU_END_TIMING(section) do {} while (false) 388 #ifdef MIRTK_WITH_PROFILING 389 # define MIRTKCU_DEBUG_INTERIM_TIMING(level, section) \ 390 if (debug_time >= level) IRTKCU_INTERIM_TIMING(section) 392 # define MIRTKCU_DEBUG_INTERIM_TIMING(level, section) do {} while (false) 418 #ifdef MIRTK_WITH_PROFILING 419 # define MIRTKCU_DEBUG_TIMING(level, section) \ 420 if (debug_time >= level) MIRTKCU_END_TIMING(section); \ 422 CudaSafeCall( cudaEventDestroy(e_start) ); \ 423 CudaSafeCall( cudaEventDestroy(e_stop) ); \ 426 # define MIRTKCU_DEBUG_TIMING(level, section) do {} while (false) 432 #endif // MIRTK_Profiling_H void PrintElapsedTime(const char *, double, TimeUnit=TIME_IN_SECONDS)
Print elapsed time for profiled section.
string ElapsedTimeToString(double t, TimeUnit units=TIME_IN_SECONDS, TimeFormat fmt=TIME_FORMAT_HHMMSS, int w=0, char c=' ', bool left=false)
MIRTK_Common_EXPORT int debug_time
Print elapsed time with format "[H h] [M min] [S sec]".
bool IsProfilingOption(const char *)
Check if given option is a profiling option.
MIRTK_Common_EXPORT TimeUnit debug_time_unit
Time unit to use for output of time measurements.
void ParseProfilingOption(int &, int &, char *[])
Parse profiling option.
Print elapsed time using time units.
Print elapsed time with format "HH:MM:SS".
void PrintProfilingOptions(ostream &)
Print profiling command-line options.
Print elapsed time with format "[M min] [S sec]".