diff options
| author | Yong He <yonghe@outlook.com> | 2023-07-11 09:29:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-11 09:29:27 -0700 |
| commit | d0901aa7933ac31b0bf7648a31ec5c13de864457 (patch) | |
| tree | 298db796f1200013e841ed03db7ca24e2890c00a /source/core/slang-performance-profiler.h | |
| parent | d9c57e613f2dacd221d9c46c10395cf373a8fcaf (diff) | |
Add perf benchmark utility. (#2977)
* Add perf benchmark utility.
* Update documentation.
* Fix.
* Fix doc.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/core/slang-performance-profiler.h')
| -rw-r--r-- | source/core/slang-performance-profiler.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source/core/slang-performance-profiler.h b/source/core/slang-performance-profiler.h new file mode 100644 index 000000000..323940ade --- /dev/null +++ b/source/core/slang-performance-profiler.h @@ -0,0 +1,42 @@ +#ifndef SLANG_CORE_PERFORMANCE_PROFILER_H +#define SLANG_CORE_PERFORMANCE_PROFILER_H + +#include "slang-string.h" +#include <chrono> + +namespace Slang +{ + +struct FuncProfileContext +{ + const char* funcName = nullptr; + std::chrono::time_point<std::chrono::high_resolution_clock> startTime; +}; + +class PerformanceProfiler +{ +public: + virtual FuncProfileContext enterFunction(const char* funcName) = 0; + virtual void exitFunction(FuncProfileContext context) = 0; + virtual void getResult(StringBuilder& out) = 0; +public: + static PerformanceProfiler* getProfiler(); +}; + +struct PerformanceProfilerFuncRAIIContext +{ + FuncProfileContext context; + PerformanceProfilerFuncRAIIContext(const char* funcName) + { + context = PerformanceProfiler::getProfiler()->enterFunction(funcName); + } + ~PerformanceProfilerFuncRAIIContext() + { + PerformanceProfiler::getProfiler()->exitFunction(context); + } +}; + +#define SLANG_PROFILE PerformanceProfilerFuncRAIIContext _profileContext(__func__) +} + +#endif |
