yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1#ifndef SLANG_CORE_PERFORMANCE_PROFILER_H 2#define SLANG_CORE_PERFORMANCE_PROFILER_H 3 4#include "../core/slang-list.h" 5#include "slang-com-helper.h" 6#include "slang-string.h" 7 8#include <chrono> 9#include <vector> 10 11namespace Slang 12{ 13 14struct FuncProfileInfo 15{ 16int invocationCount = 0 ; 17std ::chrono ::nanoseconds duration = std ::chrono ::nanoseconds ::zero (); 18}; 19 20struct FuncProfileContext 21{ 22const char * funcName = nullptr; 23std ::chrono ::time_point < std ::chrono ::high_resolution_clock > startTime ; 24}; 25 26class PerformanceProfiler 27{ 28public : 29virtual FuncProfileContext enterFunction (const char * funcName )= 0 ; 30virtual void exitFunction (FuncProfileContext context )= 0 ; 31virtual void getResult (StringBuilder & out )= 0 ; 32virtual void clear ()= 0 ; 33virtual void dispose ()= 0 ; 34 35public : 36static PerformanceProfiler * getProfiler (); 37}; 38 39struct PerformanceProfilerFuncRAIIContext 40{ 41FuncProfileContext context ; 42PerformanceProfilerFuncRAIIContext (const char * funcName ) 43 { 44context = PerformanceProfiler ::getProfiler ()-> enterFunction (funcName ); 45 } 46 ~PerformanceProfilerFuncRAIIContext () 47 { 48PerformanceProfiler ::getProfiler ()-> exitFunction (context ); 49 } 50}; 51 52struct SlangProfiler :public ISlangProfiler ,public RefObject 53{ 54public : 55SLANG_REF_OBJECT_IUNKNOWN_ALL 56struct ProfileInfo 57 { 58char funcName [256 ]= {0 }; 59int invocationCount = 0 ; 60std ::chrono ::nanoseconds duration = std ::chrono ::nanoseconds ::zero (); 61 }; 62SlangProfiler (PerformanceProfiler * profiler ); 63ISlangUnknown * getInterface (const Guid & guid ); 64 65virtual SLANG_NO_THROW size_t SLANG_MCALL getEntryCount ()override ; 66virtual SLANG_NO_THROW const char * SLANG_MCALL getEntryName ( uint32_t index) override; 67virtual SLANG_NO_THROW long SLANG_MCALL getEntryTimeMS ( uint32_t index) override; 68virtual SLANG_NO_THROW uint32_t SLANG_MCALL getEntryInvocationTimes ( uint32_t index) override; 69 70private: 71List < ProfileInfo > m_profilEntries; 72}; 73 74#define SLANG_PROFILE PerformanceProfilerFuncRAIIContext _profileContext( __func__ ) 75#define SLANG_PROFILE_SECTION ( s ) PerformanceProfilerFuncRAIIContext _profileContext# #s (#s) 76 77} // namespace Slang 78 79#endif