summaryrefslogtreecommitdiffstats
path: root/source/core/slang-performance-profiler.cpp
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.cpp
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.cpp')
-rw-r--r--source/core/slang-performance-profiler.cpp75
1 files changed, 69 insertions, 6 deletions
diff --git a/source/core/slang-performance-profiler.cpp b/source/core/slang-performance-profiler.cpp
index 7ca33f615..f8e934491 100644
--- a/source/core/slang-performance-profiler.cpp
+++ b/source/core/slang-performance-profiler.cpp
@@ -3,11 +3,6 @@
namespace Slang
{
- struct FuncProfileInfo
- {
- int invocationCount = 0;
- std::chrono::nanoseconds duration = std::chrono::nanoseconds::zero();
- };
class PerformanceProfilerImpl : public PerformanceProfiler
{
public:
@@ -39,9 +34,14 @@ namespace Slang
for (auto func : data)
{
out << func.key << ": \t";
- out << func.value.invocationCount << "\t" << func.value.duration.count() / 1000000.0f << "\n";
+ auto milliseconds = std::chrono::duration_cast< std::chrono::milliseconds >(func.value.duration);
+ out << func.value.invocationCount << "\t" << milliseconds.count() << "ms\n";
}
}
+ virtual void clear() override
+ {
+ data.clear();
+ }
};
PerformanceProfiler* Slang::PerformanceProfiler::getProfiler()
@@ -49,4 +49,67 @@ namespace Slang
thread_local static PerformanceProfilerImpl profiler = PerformanceProfilerImpl();
return &profiler;
}
+
+ SlangProfiler::SlangProfiler(PerformanceProfiler* profiler)
+ {
+ PerformanceProfilerImpl* profilerImpl = static_cast<PerformanceProfilerImpl*>(profiler);
+ size_t entryCount = profilerImpl->data.getCount();
+
+ m_profilEntries.reserve(entryCount);
+
+ int index = 0;
+ for (auto func : profilerImpl->data)
+ {
+ ProfileInfo profileEntry {};
+ size_t strSize = std::min(sizeof(profileEntry.funcName) - 1, strlen(func.key));
+
+ if (strSize > 0)
+ {
+ strncpy_s(profileEntry.funcName, strSize, func.key, strSize);
+ }
+ profileEntry.invocationCount = func.value.invocationCount;
+ profileEntry.duration = func.value.duration;
+
+ m_profilEntries.insert(index, profileEntry);
+ index++;
+ }
+ }
+
+ ISlangUnknown* SlangProfiler::getInterface(const Guid& guid)
+ {
+ if(guid == SlangProfiler::getTypeGuid())
+ return static_cast<ISlangUnknown*>(this);
+ else
+ return nullptr;
+ }
+
+ size_t SlangProfiler::getEntryCount()
+ {
+ return m_profilEntries.getCount();
+ }
+
+ const char* SlangProfiler::getEntryName(uint32_t index)
+ {
+ if (index >= (uint32_t)m_profilEntries.getCount())
+ return nullptr;
+
+ return m_profilEntries[index].funcName;
+ }
+
+ long SlangProfiler::getEntryTimeMS(uint32_t index)
+ {
+ if (index >= (uint32_t)m_profilEntries.getCount())
+ return 0;
+
+ auto milliseconds = std::chrono::duration_cast< std::chrono::milliseconds >(m_profilEntries[index].duration);
+ return (long)milliseconds.count();
+ }
+
+ uint32_t SlangProfiler::getEntryInvocationTimes(uint32_t index)
+ {
+ if (index >= (uint32_t)m_profilEntries.getCount())
+ return 0;
+
+ return m_profilEntries[index].invocationCount;
+ }
}