BsProfilingManager.h 1.7 KB

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