BsProfilingManager.h 2.0 KB

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