| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #pragma once
- #include "CmPrerequisites.h"
- #include "CmModule.h"
- #include "CmCPUProfiler.h"
- namespace CamelotFramework
- {
- #define PROFILE_CALL(call, name) \
- CamelotFramework::gProfiler().beginSample(##name##); \
- call; \
- CamelotFramework::gProfiler().endSample(##name##);
- struct ProfilerReport
- {
- CPUProfilerReport cpuReport;
- };
- enum class ProfiledThread
- {
- Sim,
- Core
- };
- class CM_EXPORT Profiler : public Module<Profiler>
- {
- public:
- Profiler();
- ~Profiler();
- /**
- * @copydoc CPUProfiler::beginThread
- */
- void beginThread(const ProfilerString& name)
- {
- #if CM_PROFILING_ENABLED
- mCPUProfiler->beginThread(name);
- #endif
- }
- /**
- * @copydoc CPUProfiler::endThread
- */
- void endThread()
- {
- #if CM_PROFILING_ENABLED
- mCPUProfiler->endThread();
- #endif
- }
- /**
- * @copydoc CPUProfiler::beginSample
- */
- void beginSample(const ProfilerString& name)
- {
- #if CM_PROFILING_ENABLED
- mCPUProfiler->beginSample(name);
- #endif
- }
- /**
- * @copydoc CPUProfiler::endSample
- */
- void endSample(const ProfilerString& name)
- {
- #if CM_PROFILING_ENABLED
- mCPUProfiler->endSample(name);
- #endif
- }
- /**
- * @copydoc CPUProfiler::beginSamplePrecise
- */
- void beginSamplePrecise(const ProfilerString& name)
- {
- #if CM_PROFILING_ENABLED
- mCPUProfiler->beginSamplePrecise(name);
- #endif
- }
- /**
- * @copydoc CPUProfiler::endSamplePrecise
- */
- void endSamplePrecise(const ProfilerString& name)
- {
- #if CM_PROFILING_ENABLED
- mCPUProfiler->endSamplePrecise(name);
- #endif
- }
- /**
- * @brief Called every frame. Internal method.
- */
- void update();
- /**
- * @brief Called every frame from the core thread. Internal method.
- *
- * @note Only call from core thread.
- */
- void updateCore();
- /**
- * @brief Returns a profiler report for the specified frame, for the specified thread.
- *
- * @param Profiler report index, ranging [0, NUM_SAVED_FRAMES]. 0 always returns the latest
- * report. Increasing indexes return reports for older and older frames. Out of range
- * indexes will be clamped.
- *
- * @note Profiler reports get updated every frame. Oldest reports that no longer fit in the saved reports buffer
- * are discarded.
- */
- const ProfilerReport& getReport(ProfiledThread thread, UINT32 idx = 0) const;
- private:
- static const UINT32 NUM_SAVED_FRAMES;
- ProfilerReport* mSavedSimReports;
- UINT32 mNextSimReportIdx;
- ProfilerReport* mSavedCoreReports;
- UINT32 mNextCoreReportIdx;
- CPUProfiler* mCPUProfiler;
- CM_MUTEX(mSync);
- };
- CM_EXPORT Profiler& gProfiler();
- }
|