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 OnFibersCreated(uint32 fibersCount) override 45 { 46 MT_UNUSED(fibersCount); 47 } 48 49 virtual void OnThreadsCreated(uint32 threadsCount) override 50 { 51 MT_UNUSED(threadsCount); 52 } 53 54 virtual void OnThreadCreated(uint32 workerIndex) override 55 { 56 MT_UNUSED(workerIndex); 57 } 58 59 virtual void OnThreadStarted(uint32 workerIndex) override 60 { 61 MT_UNUSED(workerIndex); 62 } 63 64 virtual void OnThreadStoped(uint32 workerIndex) override 65 { 66 MT_UNUSED(workerIndex); 67 } 68 69 virtual void OnThreadIdleStarted(uint32 workerIndex) override 70 { 71 MT_UNUSED(workerIndex); 72 PushPerfMarker("ThreadIdle", MT::Color::Red); 73 } 74 75 virtual void OnThreadIdleFinished(uint32 workerIndex) override 76 { 77 MT_UNUSED(workerIndex); 78 PopPerfMarker("ThreadIdle"); 79 } 80 81 virtual void OnThreadWaitStarted() override 82 { 83 PushPerfMarker("ThreadWait", MT::Color::Red); 84 } 85 86 virtual void OnThreadWaitFinished() override 87 { 88 PopPerfMarker("ThreadWait"); 89 } 90 91 virtual void OnTemporaryWorkerThreadJoin() override 92 { 93 } 94 95 virtual void OnTemporaryWorkerThreadLeave() override 96 { 97 } 98 99 virtual void OnTaskExecuteStateChanged(MT::Color::Type debugColor, const mt_char* debugID, MT::TaskExecuteState::Type type, int32 fiberIndex) override 100 { 101 MT_UNUSED(fiberIndex); 102 103 switch(type) 104 { 105 case MT::TaskExecuteState::START: 106 case MT::TaskExecuteState::RESUME: 107 PushPerfMarker(debugID, debugColor); 108 break; 109 case MT::TaskExecuteState::STOP: 110 case MT::TaskExecuteState::SUSPEND: 111 PopPerfMarker(debugID); 112 break; 113 } 114 } 115 }; 116 117 118 #endif 119 120 121 MT::IProfilerEventListener* GetProfiler() 122 { 123 #ifdef MT_INSTRUMENTED_BUILD 124 static Microprofile profile; 125 return &profile; 126 #else 127 return nullptr; 128 #endif 129 130 131 } 132