1 #include <MTScheduler.h> 2 #include "Profiler.h" 3 4 5 #ifdef MT_INSTRUMENTED_BUILD 6 7 8 void PushPerfMarker(const char* name, MT::Color::Type color) 9 { 10 MT_UNUSED(name); 11 MT_UNUSED(color); 12 } 13 14 void PopPerfMarker(const char* name) 15 { 16 MT_UNUSED(name); 17 } 18 19 20 21 void PushPerfEvent(const char* name) 22 { 23 PushPerfMarker(name, MT::Color::Red); 24 } 25 26 void PopPerfEvent(const char* name) 27 { 28 PopPerfMarker(name); 29 } 30 31 32 class Microprofile : public MT::IProfilerEventListener 33 { 34 public: 35 36 Microprofile() 37 { 38 } 39 40 ~Microprofile() 41 { 42 } 43 44 virtual void OnThreadCreated(uint32 workerIndex) override 45 { 46 MT_UNUSED(workerIndex); 47 } 48 49 virtual void OnThreadStarted(uint32 workerIndex) override 50 { 51 MT_UNUSED(workerIndex); 52 } 53 54 virtual void OnThreadStoped(uint32 workerIndex) override 55 { 56 MT_UNUSED(workerIndex); 57 } 58 59 virtual void OnThreadIdleStarted(uint32 workerIndex) override 60 { 61 MT_UNUSED(workerIndex); 62 PushPerfMarker("ThreadIdle", MT::Color::Red); 63 } 64 65 virtual void OnThreadIdleFinished(uint32 workerIndex) override 66 { 67 MT_UNUSED(workerIndex); 68 PopPerfMarker("ThreadIdle"); 69 } 70 71 virtual void OnThreadWaitStarted() override 72 { 73 PushPerfMarker("ThreadWait", MT::Color::Red); 74 } 75 76 virtual void OnThreadWaitFinished() override 77 { 78 PopPerfMarker("ThreadWait"); 79 } 80 81 virtual void NotifyTaskExecuteStateChanged(MT::Color::Type debugColor, const mt_char* debugID, MT::TaskExecuteState::Type type) override 82 { 83 switch(type) 84 { 85 case MT::TaskExecuteState::START: 86 case MT::TaskExecuteState::RESUME: 87 PushPerfMarker(debugID, debugColor); 88 break; 89 case MT::TaskExecuteState::STOP: 90 case MT::TaskExecuteState::SUSPEND: 91 PopPerfMarker(debugID); 92 break; 93 } 94 } 95 }; 96 97 98 #endif 99 100 101 MT::IProfilerEventListener* GetProfiler() 102 { 103 #ifdef MT_INSTRUMENTED_BUILD 104 static Microprofile profile; 105 return &profile; 106 #else 107 return nullptr; 108 #endif 109 110 111 } 112