You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
1.9 KiB

1 year ago
  1. #pragma once
  2. #include "tsdk/TrackEngineTypes.h"
  3. #include <chrono>
  4. namespace tsdk {
  5. namespace profiler {
  6. struct ProfilerImpl;
  7. /** @brief Profiler class - storage for all ScopeTimers and statistics.
  8. */
  9. struct Profiler {
  10. static Profiler& getInstance() {
  11. static Profiler profiler;
  12. return profiler;
  13. }
  14. bool isEnabled() const;
  15. void setEnabled(bool enable);
  16. void pushTimer(const char *timerName);
  17. void profileTime(const char *timerName, size_t duration);
  18. void outputProfileData();
  19. void outputBuffersState(const char *filename);
  20. void storeBufferState(const char *bufferName, tsdk::FrameId frame, size_t bufferSize);
  21. private:
  22. Profiler();
  23. ~Profiler();
  24. ProfilerImpl *m_pimpl;
  25. };
  26. struct BufferLog {
  27. /** @brief saves state of buffer for given frame number
  28. * @param bufferName to save info for it
  29. * @param frame to which save info
  30. * @param bufferSize current number of items in buffer
  31. */
  32. static void logBufferState(const char *bufferName, tsdk::FrameId frame, size_t bufferSize);
  33. /** @brief saves info about buffers to json file with given filename
  34. * @param filename
  35. */
  36. static void outputState(const char *filename);
  37. };
  38. /** @brief ScopedTimer class with nesting and storing statistics
  39. */
  40. struct ScopedTimer {
  41. /** @brief Constructor
  42. * @param name name for timing interval
  43. */
  44. TRACK_ENGINE_API explicit ScopedTimer(const char *name);
  45. TRACK_ENGINE_API ~ScopedTimer();
  46. ScopedTimer(ScopedTimer &) = delete;
  47. ScopedTimer(ScopedTimer &&) = delete;
  48. ScopedTimer &operator=(ScopedTimer &) = delete;
  49. ScopedTimer &operator=(ScopedTimer &&) = delete;
  50. /** @brief output timing storage data to log
  51. */
  52. static void outputProfileData();
  53. private:
  54. using clock = std::chrono::high_resolution_clock;
  55. using time_point_type = std::chrono::high_resolution_clock::time_point;
  56. char m_name[1024];
  57. time_point_type m_start;
  58. };
  59. }
  60. }