Profiler.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include <time.h>
  4. #include <map>
  5. #include <utils/Logger.h>
  6. #include <HyperionConfig.h>
  7. /*
  8. The performance (real time) of any function can be tested with the help of profiler.
  9. The determined times are determined using clock cycles.
  10. To do this, compile with the cmake option: -DENABLE_PROFILER=ON
  11. This header file (utils/Profiler.h) must be included in the respective file that contains the function to be measured
  12. The start time is set in a function with the following instructions:
  13. PROFILER_TIMER_START("test_performance")
  14. The end point is set as follows:
  15. PROFILER_TIMER_GET("test_performance")
  16. For more profiler function see the macros listed below
  17. */
  18. #ifndef ENABLE_PROFILER
  19. #error "Profiler is not for production code, enable it via cmake or remove header include"
  20. #endif
  21. // profiler
  22. #define PROFILER_BLOCK_EXECUTION_TIME Profiler DEBUG_PROFILE__BLOCK__EXECUTION__TIME_messure_object(__FILE__, __FUNCTION__, __LINE__ );
  23. #define PROFILER_TIMER_START(stopWatchName) Profiler::TimerStart(stopWatchName, __FILE__, __FUNCTION__, __LINE__);
  24. #define PROFILER_TIMER_GET(stopWatchName) Profiler::TimerGetTime(stopWatchName, __FILE__, __FUNCTION__, __LINE__);
  25. #define PROFILER_TIMER_GET_IF(condition, stopWatchName) { if (condition) {Profiler::TimerGetTime(stopWatchName, __FILE__, __FUNCTION__, __LINE__);} }
  26. class Profiler
  27. {
  28. public:
  29. Profiler(const char* sourceFile, const char* func, unsigned int line);
  30. ~Profiler();
  31. static void TimerStart(const QString& stopWatchName, const char* sourceFile, const char* func, unsigned int line);
  32. static void TimerGetTime(const QString& stopWatchName, const char* sourceFile, const char* func, unsigned int line);
  33. private:
  34. static void initLogger();
  35. static Logger* _logger;
  36. const char* _file;
  37. const char* _func;
  38. unsigned int _line;
  39. unsigned int _blockId;
  40. clock_t _startTime;
  41. };