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. /** @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] thread Thread for which to retrieve the profiler report.
  45. * @param[in] idx 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
  47. * clamped.
  48. *
  49. * @note
  50. * Profiler reports get updated every frame. Oldest reports that no longer fit in the saved reports buffer are
  51. * discarded.
  52. */
  53. const ProfilerReport& getReport(ProfiledThread thread, UINT32 idx = 0) const;
  54. private:
  55. static const UINT32 NUM_SAVED_FRAMES;
  56. ProfilerReport* mSavedSimReports;
  57. UINT32 mNextSimReportIdx;
  58. ProfilerReport* mSavedCoreReports;
  59. UINT32 mNextCoreReportIdx;
  60. mutable Mutex mSync;
  61. };
  62. /** Easy way to access ProfilingManager. */
  63. BS_CORE_EXPORT ProfilingManager& gProfiler();
  64. /** @} */
  65. }