CmProfiler.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmModule.h"
  4. #include "CmCPUProfiler.h"
  5. namespace CamelotFramework
  6. {
  7. struct ProfilerReport
  8. {
  9. CPUProfilerReport cpuReport;
  10. };
  11. class CM_EXPORT Profiler : public Module<Profiler>
  12. {
  13. public:
  14. Profiler();
  15. ~Profiler();
  16. /**
  17. * @copydoc CPUProfiler::beginThread
  18. */
  19. void beginThread(const String& name)
  20. {
  21. #if CM_PROFILING_ENABLED
  22. mCPUProfiler->beginThread(name);
  23. #endif
  24. }
  25. /**
  26. * @copydoc CPUProfiler::endThread
  27. */
  28. void endThread()
  29. {
  30. #if CM_PROFILING_ENABLED
  31. mCPUProfiler->endThread();
  32. #endif
  33. }
  34. /**
  35. * @copydoc CPUProfiler::beginSample
  36. */
  37. void beginSample(const String& name)
  38. {
  39. #if CM_PROFILING_ENABLED
  40. mCPUProfiler->beginSample(name);
  41. #endif
  42. }
  43. /**
  44. * @copydoc CPUProfiler::endSample
  45. */
  46. void endSample(const String& name)
  47. {
  48. #if CM_PROFILING_ENABLED
  49. mCPUProfiler->endSample(name);
  50. #endif
  51. }
  52. /**
  53. * @copydoc CPUProfiler::beginSamplePrecise
  54. */
  55. void beginSamplePrecise(const String& name)
  56. {
  57. #if CM_PROFILING_ENABLED
  58. mCPUProfiler->beginSamplePrecise(name);
  59. #endif
  60. }
  61. /**
  62. * @copydoc CPUProfiler::endSamplePrecise
  63. */
  64. void endSamplePrecise(const String& name)
  65. {
  66. #if CM_PROFILING_ENABLED
  67. mCPUProfiler->endSamplePrecise(name);
  68. #endif
  69. }
  70. /**
  71. * @brief Called every frame. Internal method.
  72. */
  73. void update();
  74. /**
  75. * @brief Returns a profiler report for the specified frame.
  76. *
  77. * @param Profiler report index, ranging [0, NUM_SAVED_FRAMES]. 0 always returns the latest
  78. * report. Increasing indexes return reports for older and older frames. Out of range
  79. * indexes will be clamped.
  80. *
  81. * @note Profiler reports get updated every frame. Oldest reports that no longer fit in the saved reports buffer
  82. * are discarded.
  83. */
  84. const ProfilerReport& getReport(UINT32 idx = 0) const;
  85. private:
  86. static const UINT32 NUM_SAVED_FRAMES;
  87. ProfilerReport* mSavedReports;
  88. UINT32 mNextReportIdx;
  89. CPUProfiler* mCPUProfiler;
  90. };
  91. CM_EXPORT Profiler& gProfiler();
  92. }