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