summaryrefslogtreecommitdiff
path: root/source/core/slang-performance-profiler.h
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2024-06-04 18:24:12 -0700
committerGitHub <noreply@github.com>2024-06-04 18:24:12 -0700
commitbacf73cc68af8b7654cc920b07635f926b785b84 (patch)
tree23b466be471d1c188ce893f4ce2b934e7f6a2b77 /source/core/slang-performance-profiler.h
parent1141b8243c4ff00c59e927b0c33dbffaea29db4c (diff)
Add APIs to get profile of compile time (#4242)
* Add APIs to get profile of compile time Add serial time measurement Add profiler to measure lots of stages in slang compilation, and it can accumulate the time spent in each thread in multi-threads case and finally report a serial timing info. * Add invocation times to the profiler * Simplify the profiler and provide a 'clear' option Change the profiler design to only return the thread_local profiler to user. We create a ISlangProfiler interface to carry the thread_local variable PerformanceProfilerImpl profiler to user. In addition, we provide a new option in the input parameter to control whether or not user want to clear the previous profile data. So spGetCompileProfile() can always returns a fresh new profiling data. * Change to use slang container List Stop using std::vector, instead use slang's container List. Generate a UUID for ISlangProfiler
Diffstat (limited to 'source/core/slang-performance-profiler.h')
-rw-r--r--source/core/slang-performance-profiler.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/source/core/slang-performance-profiler.h b/source/core/slang-performance-profiler.h
index 323940ade..f7c62bb45 100644
--- a/source/core/slang-performance-profiler.h
+++ b/source/core/slang-performance-profiler.h
@@ -3,10 +3,19 @@
#include "slang-string.h"
#include <chrono>
+#include <vector>
+#include "../../slang-com-helper.h"
+#include "../core/slang-list.h"
namespace Slang
{
+struct FuncProfileInfo
+{
+ int invocationCount = 0;
+ std::chrono::nanoseconds duration = std::chrono::nanoseconds::zero();
+};
+
struct FuncProfileContext
{
const char* funcName = nullptr;
@@ -19,6 +28,7 @@ public:
virtual FuncProfileContext enterFunction(const char* funcName) = 0;
virtual void exitFunction(FuncProfileContext context) = 0;
virtual void getResult(StringBuilder& out) = 0;
+ virtual void clear() = 0;
public:
static PerformanceProfiler* getProfiler();
};
@@ -36,6 +46,27 @@ struct PerformanceProfilerFuncRAIIContext
}
};
+struct SlangProfiler: public ISlangProfiler, public RefObject
+{
+public:
+ SLANG_REF_OBJECT_IUNKNOWN_ALL
+ struct ProfileInfo
+ {
+ char funcName[256] = {0};
+ int invocationCount = 0;
+ std::chrono::nanoseconds duration = std::chrono::nanoseconds::zero();
+ };
+ SlangProfiler(PerformanceProfiler * profiler);
+ ISlangUnknown* getInterface(const Guid& guid);
+
+ virtual SLANG_NO_THROW size_t SLANG_MCALL getEntryCount() override;
+ virtual SLANG_NO_THROW const char* SLANG_MCALL getEntryName(uint32_t index) override;
+ virtual SLANG_NO_THROW long SLANG_MCALL getEntryTimeMS(uint32_t index) override;
+ virtual SLANG_NO_THROW uint32_t SLANG_MCALL getEntryInvocationTimes(uint32_t index) override;
+private:
+ List<ProfileInfo> m_profilEntries;
+};
+
#define SLANG_PROFILE PerformanceProfilerFuncRAIIContext _profileContext(__func__)
}