blob: 323940ade663d74eea6870e5be46133fcafd1213 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
|