BsProfilingManager.h 2.0 KB

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