BsProfilingManager.h 2.0 KB

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