BsProfilingManager.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsModule.h"
  4. #include "BsProfilerCPU.h"
  5. namespace BansheeEngine
  6. {
  7. /** @cond INTERNAL */
  8. /** @addtogroup Profiling
  9. * @{
  10. */
  11. /** Contains data about a profiling session. */
  12. struct ProfilerReport
  13. {
  14. CPUProfilerReport cpuReport;
  15. };
  16. /** Type of thread used by the profiler. */
  17. enum class ProfiledThread
  18. {
  19. Sim,
  20. Core
  21. };
  22. /**
  23. * Tracks CPU profiling information with each frame for sim and core threads.
  24. *
  25. * @note Sim thread only unless specified otherwise.
  26. */
  27. class BS_CORE_EXPORT ProfilingManager : public Module<ProfilingManager>
  28. {
  29. public:
  30. ProfilingManager();
  31. ~ProfilingManager();
  32. /** Called every frame. */
  33. void _update();
  34. /**
  35. * Called every frame from the core thread.
  36. *
  37. * @note Core thread only.
  38. */
  39. void _updateCore();
  40. /**
  41. * Returns a profiler report for the specified frame, for the specified thread.
  42. *
  43. * @param[in] Profiler report index, ranging [0, NUM_SAVED_FRAMES]. 0 always returns the latest report.
  44. * Increasing indexes return reports for older and older frames. Out of range indexes will be clamped.
  45. *
  46. * @note
  47. * Profiler reports get updated every frame. Oldest reports that no longer fit in the saved reports buffer are
  48. * discarded.
  49. */
  50. const ProfilerReport& getReport(ProfiledThread thread, UINT32 idx = 0) const;
  51. private:
  52. static const UINT32 NUM_SAVED_FRAMES;
  53. ProfilerReport* mSavedSimReports;
  54. UINT32 mNextSimReportIdx;
  55. ProfilerReport* mSavedCoreReports;
  56. UINT32 mNextCoreReportIdx;
  57. BS_MUTEX(mSync);
  58. };
  59. /** Easy way to access ProfilingManager. */
  60. BS_CORE_EXPORT ProfilingManager& gProfiler();
  61. /** @} */
  62. /** @endcond */
  63. }