From f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 14:49:26 +0800 Subject: format * format * Minor test fixes * enable checking cpp format in ci --- source/core/slang-performance-profiler.cpp | 190 ++++++++++++++--------------- 1 file changed, 94 insertions(+), 96 deletions(-) (limited to 'source/core/slang-performance-profiler.cpp') diff --git a/source/core/slang-performance-profiler.cpp b/source/core/slang-performance-profiler.cpp index b272c9e17..9bc532680 100644 --- a/source/core/slang-performance-profiler.cpp +++ b/source/core/slang-performance-profiler.cpp @@ -1,122 +1,120 @@ #include "slang-performance-profiler.h" + #include "slang-dictionary.h" namespace Slang { - class PerformanceProfilerImpl : public PerformanceProfiler - { - public: - OrderedDictionary data; +class PerformanceProfilerImpl : public PerformanceProfiler +{ +public: + OrderedDictionary data; - virtual FuncProfileContext enterFunction(const char* funcName) override - { - auto entry = data.tryGetValue(funcName); - if (!entry) - { - data.add(funcName, FuncProfileInfo()); - entry = data.tryGetValue(funcName); - } - entry->invocationCount++; - FuncProfileContext ctx; - ctx.funcName = funcName; - ctx.startTime = std::chrono::high_resolution_clock::now(); - return ctx; - } - virtual void exitFunction(FuncProfileContext ctx) override - { - auto endTime = std::chrono::high_resolution_clock::now(); - auto duration = endTime - ctx.startTime; - auto entry = data.tryGetValue(ctx.funcName); - entry->duration += duration; - } - virtual void getResult(StringBuilder& out) override - { - char buffer[512]; - for (const auto& func : data) - { - memset(buffer, 0, sizeof(buffer)); - snprintf(buffer, sizeof(buffer), "[*] %30s", func.key); - out << buffer << " \t"; - auto milliseconds = std::chrono::duration_cast< std::chrono::milliseconds >(func.value.duration); - out << func.value.invocationCount << " \t" << static_cast(milliseconds.count()) << "ms\n"; - } - } - virtual void clear() override + virtual FuncProfileContext enterFunction(const char* funcName) override + { + auto entry = data.tryGetValue(funcName); + if (!entry) { - data.clear(); + data.add(funcName, FuncProfileInfo()); + entry = data.tryGetValue(funcName); } - virtual void dispose() override + entry->invocationCount++; + FuncProfileContext ctx; + ctx.funcName = funcName; + ctx.startTime = std::chrono::high_resolution_clock::now(); + return ctx; + } + virtual void exitFunction(FuncProfileContext ctx) override + { + auto endTime = std::chrono::high_resolution_clock::now(); + auto duration = endTime - ctx.startTime; + auto entry = data.tryGetValue(ctx.funcName); + entry->duration += duration; + } + virtual void getResult(StringBuilder& out) override + { + char buffer[512]; + for (const auto& func : data) { - data = decltype(data)(); + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, sizeof(buffer), "[*] %30s", func.key); + out << buffer << " \t"; + auto milliseconds = + std::chrono::duration_cast(func.value.duration); + out << func.value.invocationCount << " \t" + << static_cast(milliseconds.count()) << "ms\n"; } - }; - - PerformanceProfiler* Slang::PerformanceProfiler::getProfiler() - { - thread_local static PerformanceProfilerImpl profiler = PerformanceProfilerImpl(); - return &profiler; } + virtual void clear() override { data.clear(); } + virtual void dispose() override { data = decltype(data)(); } +}; - SlangProfiler::SlangProfiler(PerformanceProfiler* profiler) - { - PerformanceProfilerImpl* profilerImpl = static_cast(profiler); - size_t entryCount = profilerImpl->data.getCount(); +PerformanceProfiler* Slang::PerformanceProfiler::getProfiler() +{ + thread_local static PerformanceProfilerImpl profiler = PerformanceProfilerImpl(); + return &profiler; +} + +SlangProfiler::SlangProfiler(PerformanceProfiler* profiler) +{ + PerformanceProfilerImpl* profilerImpl = static_cast(profiler); + size_t entryCount = profilerImpl->data.getCount(); + + m_profilEntries.reserve(entryCount); - 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)); - int index = 0; - for (auto func : profilerImpl->data) + if (strSize > 0) { - ProfileInfo profileEntry {}; - size_t strSize = std::min(sizeof(profileEntry.funcName) - 1, strlen(func.key)); - - if (strSize > 0) - { - memcpy(profileEntry.funcName, func.key, strSize); - } - profileEntry.invocationCount = func.value.invocationCount; - profileEntry.duration = func.value.duration; - - m_profilEntries.insert(index, profileEntry); - index++; + memcpy(profileEntry.funcName, func.key, strSize); } - } + profileEntry.invocationCount = func.value.invocationCount; + profileEntry.duration = func.value.duration; - ISlangUnknown* SlangProfiler::getInterface(const Guid& guid) - { - if(guid == SlangProfiler::getTypeGuid()) - return static_cast(this); - else - return nullptr; + m_profilEntries.insert(index, profileEntry); + index++; } +} - size_t SlangProfiler::getEntryCount() - { - return m_profilEntries.getCount(); - } +ISlangUnknown* SlangProfiler::getInterface(const Guid& guid) +{ + if (guid == SlangProfiler::getTypeGuid()) + return static_cast(this); + else + return nullptr; +} - const char* SlangProfiler::getEntryName(uint32_t index) - { - if (index >= (uint32_t)m_profilEntries.getCount()) - return nullptr; +size_t SlangProfiler::getEntryCount() +{ + return m_profilEntries.getCount(); +} - return m_profilEntries[index].funcName; - } +const char* SlangProfiler::getEntryName(uint32_t index) +{ + if (index >= (uint32_t)m_profilEntries.getCount()) + return nullptr; - long SlangProfiler::getEntryTimeMS(uint32_t index) - { - if (index >= (uint32_t)m_profilEntries.getCount()) - return 0; + return m_profilEntries[index].funcName; +} - auto milliseconds = std::chrono::duration_cast< std::chrono::milliseconds >(m_profilEntries[index].duration); - return (long)milliseconds.count(); - } +long SlangProfiler::getEntryTimeMS(uint32_t index) +{ + if (index >= (uint32_t)m_profilEntries.getCount()) + return 0; - uint32_t SlangProfiler::getEntryInvocationTimes(uint32_t index) - { - if (index >= (uint32_t)m_profilEntries.getCount()) - return 0; + auto milliseconds = + std::chrono::duration_cast(m_profilEntries[index].duration); + return (long)milliseconds.count(); +} - return m_profilEntries[index].invocationCount; - } +uint32_t SlangProfiler::getEntryInvocationTimes(uint32_t index) +{ + if (index >= (uint32_t)m_profilEntries.getCount()) + return 0; + + return m_profilEntries[index].invocationCount; } +} // namespace Slang -- cgit v1.2.3