From 1e4faca332e0fc5eb1f512c6807ba0876728ea36 Mon Sep 17 00:00:00 2001 From: Scott Romero <24445312+AMZN-ScottR@users.noreply.github.com> Date: Mon, 4 Oct 2021 14:49:16 -0700 Subject: [PATCH] [development] Revived the statistical profiler (#4378) - Removed unused RunningStatisticsManager.cpp - Updated stats profiler proxy to use budgets - Fixed and re-enabled stats profiler tests - Enabled StatisticalProfilerProxySystemComponent in runtime Signed-off-by: AMZN-ScottR 24445312+AMZN-ScottR@users.noreply.github.com --- Code/Framework/AzCore/AzCore/AzCoreModule.cpp | 9 ++ Code/Framework/AzCore/AzCore/Debug/Budget.cpp | 8 +- Code/Framework/AzCore/AzCore/Debug/Profiler.h | 6 +- .../Statistics/RunningStatisticsManager.cpp | 106 ------------------ .../AzCore/Statistics/StatisticalProfiler.h | 4 +- .../Statistics/StatisticalProfilerProxy.h | 64 ++++++----- .../AzCore/Tests/StatisticalProfiler.cpp | 95 ++++++++-------- .../AzCore/Tests/azcoretests_files.cmake | 1 + 8 files changed, 107 insertions(+), 186 deletions(-) delete mode 100644 Code/Framework/AzCore/AzCore/Statistics/RunningStatisticsManager.cpp diff --git a/Code/Framework/AzCore/AzCore/AzCoreModule.cpp b/Code/Framework/AzCore/AzCore/AzCoreModule.cpp index ec45335f95..67123ed826 100644 --- a/Code/Framework/AzCore/AzCore/AzCoreModule.cpp +++ b/Code/Framework/AzCore/AzCore/AzCoreModule.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace AZ { @@ -44,6 +45,10 @@ namespace AZ EventSchedulerSystemComponent::CreateDescriptor(), TaskGraphSystemComponent::CreateDescriptor(), +#if !defined(_RELEASE) + Statistics::StatisticalProfilerProxySystemComponent::CreateDescriptor(), +#endif + #if !defined(AZCORE_EXCLUDE_LUA) ScriptSystemComponent::CreateDescriptor(), #endif // #if !defined(AZCORE_EXCLUDE_LUA) @@ -58,6 +63,10 @@ namespace AZ azrtti_typeid(), azrtti_typeid(), azrtti_typeid(), + +#if !defined(_RELEASE) + azrtti_typeid(), +#endif }; } } diff --git a/Code/Framework/AzCore/AzCore/Debug/Budget.cpp b/Code/Framework/AzCore/AzCore/Debug/Budget.cpp index f9fe7e462a..4a6f3ed114 100644 --- a/Code/Framework/AzCore/AzCore/Debug/Budget.cpp +++ b/Code/Framework/AzCore/AzCore/Debug/Budget.cpp @@ -11,6 +11,7 @@ #include #include #include +#include AZ_DEFINE_BUDGET(Animation); AZ_DEFINE_BUDGET(Audio); @@ -30,8 +31,7 @@ namespace AZ::Debug }; Budget::Budget(const char* name) - : m_name{ name } - , m_crc{ Crc32(name) } + : Budget( name, Crc32(name) ) { } @@ -40,6 +40,10 @@ namespace AZ::Debug , m_crc{ crc } { m_impl = aznew BudgetImpl; + if (auto statsProfiler = Interface::Get(); statsProfiler) + { + statsProfiler->RegisterProfilerId(m_crc); + } } Budget::~Budget() diff --git a/Code/Framework/AzCore/AzCore/Debug/Profiler.h b/Code/Framework/AzCore/AzCore/Debug/Profiler.h index 56103e8314..6e86de2e93 100644 --- a/Code/Framework/AzCore/AzCore/Debug/Profiler.h +++ b/Code/Framework/AzCore/AzCore/Debug/Profiler.h @@ -8,6 +8,7 @@ #pragma once #include +#include #ifdef USE_PIX #include @@ -44,7 +45,10 @@ #define AZ_PROFILE_INTERVAL_START(...) #define AZ_PROFILE_INTERVAL_START_COLORED(...) #define AZ_PROFILE_INTERVAL_END(...) -#define AZ_PROFILE_INTERVAL_SCOPED(...) +#define AZ_PROFILE_INTERVAL_SCOPED(budget, scopeNameId, ...) \ + static constexpr AZ::Crc32 AZ_JOIN(blockId, __LINE__)(scopeNameId); \ + AZ::Statistics::StatisticalProfilerProxy::TimedScope AZ_JOIN(scope, __LINE__)(AZ_CRC_CE(#budget), AZ_JOIN(blockId, __LINE__)); + #endif #ifndef AZ_PROFILE_DATAPOINT diff --git a/Code/Framework/AzCore/AzCore/Statistics/RunningStatisticsManager.cpp b/Code/Framework/AzCore/AzCore/Statistics/RunningStatisticsManager.cpp deleted file mode 100644 index 52085d98e7..0000000000 --- a/Code/Framework/AzCore/AzCore/Statistics/RunningStatisticsManager.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) Contributors to the Open 3D Engine Project. - * For complete copyright and license terms please see the LICENSE at the root of this distribution. - * - * SPDX-License-Identifier: Apache-2.0 OR MIT - * - */ - -#include "RunningStatisticsManager.h" - -namespace AzFramework -{ - namespace Statistics - { - bool RunningStatisticsManager::ContainsStatistic(const AZStd::string& name) - { - auto iterator = m_statisticsNamesToIndexMap.find(name); - return iterator != m_statisticsNamesToIndexMap.end(); - } - - bool RunningStatisticsManager::AddStatistic(const AZStd::string& name, const AZStd::string& units) - { - if (ContainsStatistic(name)) - { - return false; - } - AddStatisticValidated(name, units); - return true; - } - - void RunningStatisticsManager::RemoveStatistic(const AZStd::string& name) - { - auto iterator = m_statisticsNamesToIndexMap.find(name); - if (iterator == m_statisticsNamesToIndexMap.end()) - { - return; - } - AZ::u32 itemIndex = iterator->second; - m_statistics.erase(m_statistics.begin() + itemIndex); - m_statisticsNamesToIndexMap.erase(iterator); - //Update the indices in m_statisticsNamesToIndexMap. - while (itemIndex < m_statistics.size()) - { - const AZStd::string& statName = m_statistics[itemIndex].GetName(); - m_statisticsNamesToIndexMap[statName] = itemIndex; - ++itemIndex; - } - } - - void RunningStatisticsManager::ResetStatistic(const AZStd::string& name) - { - NamedRunningStatistic* stat = GetStatistic(name); - if (!stat) - { - return; - } - stat->Reset(); - } - - void RunningStatisticsManager::ResetAllStatistics() - { - for (NamedRunningStatistic& stat : m_statistics) - { - stat.Reset(); - } - } - - void RunningStatisticsManager::PushSampleForStatistic(const AZStd::string& name, double value) - { - NamedRunningStatistic* stat = GetStatistic(name); - if (!stat) - { - return; - } - stat->PushSample(value); - } - - NamedRunningStatistic* RunningStatisticsManager::GetStatistic(const AZStd::string& name, AZ::u32* indexOut) - { - auto iterator = m_statisticsNamesToIndexMap.find(name); - if (iterator == m_statisticsNamesToIndexMap.end()) - { - return nullptr; - } - const AZ::u32 index = iterator->second; - if (indexOut) - { - *indexOut = index; - } - return &m_statistics[index]; - } - - const AZStd::vector& RunningStatisticsManager::GetAllStatistics() const - { - return m_statistics; - } - - void RunningStatisticsManager::AddStatisticValidated(const AZStd::string& name, const AZStd::string& units) - { - m_statistics.emplace_back(NamedRunningStatistic(name, units)); - const AZ::u32 itemIndex = static_cast(m_statistics.size() - 1); - m_statisticsNamesToIndexMap[name] = itemIndex; - } - - }//namespace Statistics -}//namespace AzFramework diff --git a/Code/Framework/AzCore/AzCore/Statistics/StatisticalProfiler.h b/Code/Framework/AzCore/AzCore/Statistics/StatisticalProfiler.h index 681635cd1c..876898f8ba 100644 --- a/Code/Framework/AzCore/AzCore/Statistics/StatisticalProfiler.h +++ b/Code/Framework/AzCore/AzCore/Statistics/StatisticalProfiler.h @@ -8,7 +8,6 @@ #pragma once #include //Just to get AZ::NullMutex -#include #include #include #include @@ -37,8 +36,7 @@ namespace AZ //! are some things to consider when working with the StatisticalProfilerProxy: //! The StatisticalProfilerProxy OWNS an array of StatisticalProfiler. //! You can "manage" one of those StatisticalProfiler by getting a reference to it and - //! add Running statistics etc. See The TerrainProfilers mentioned above to see concrete use - //! cases on how to work with the StatisticalProfilerProxy. + //! add Running statistics etc. template class StatisticalProfiler { diff --git a/Code/Framework/AzCore/AzCore/Statistics/StatisticalProfilerProxy.h b/Code/Framework/AzCore/AzCore/Statistics/StatisticalProfilerProxy.h index 33d835076f..278b2ecc98 100644 --- a/Code/Framework/AzCore/AzCore/Statistics/StatisticalProfilerProxy.h +++ b/Code/Framework/AzCore/AzCore/Statistics/StatisticalProfilerProxy.h @@ -7,28 +7,12 @@ */ #pragma once -#include -#include -#include -#include -#include #include #include -#include +#include +#include -#if defined(AZ_STATISTICAL_PROFILING_ENABLED) - -#if defined(AZ_PROFILE_SCOPE) -#undef AZ_PROFILE_SCOPE -#endif // #if defined(AZ_PROFILE_SCOPE) - -#define AZ_PROFILE_SCOPE(profiler, scopeNameId) \ - static const AZStd::string AZ_JOIN(blockName, __LINE__)(scopeNameId); \ - AZ::Statistics::StatisticalProfilerProxy::TimedScope AZ_JOIN(scope, __LINE__)(profiler, AZ_JOIN(blockName, __LINE__)); - -#endif //#if defined(AZ_STATISTICAL_PROFILING_ENABLED) - namespace AZ::Statistics { using StatisticalProfilerId = uint32_t; @@ -65,7 +49,7 @@ namespace AZ::Statistics public: AZ_TYPE_INFO(StatisticalProfilerProxy, "{1103D0EB-1C32-4854-B9D9-40A2D65BDBD2}"); - using StatIdType = AZStd::string; + using StatIdType = AZ::Crc32; using StatisticalProfilerType = StatisticalProfiler; //! A Convenience class used to measure time performance of scopes of code @@ -94,6 +78,7 @@ namespace AZ::Statistics } m_startTime = AZStd::chrono::high_resolution_clock::now(); } + ~TimedScope() { if (!m_profilerProxy) @@ -122,7 +107,6 @@ namespace AZ::Statistics StatisticalProfilerProxy() { - // TODO:BUDGETS Query available budgets at registration time and create an associated profiler per type AZ::Interface::Register(this); } @@ -135,30 +119,54 @@ namespace AZ::Statistics StatisticalProfilerProxy(StatisticalProfilerProxy&&) = delete; StatisticalProfilerProxy& operator=(StatisticalProfilerProxy&&) = delete; + void RegisterProfilerId(StatisticalProfilerId id) + { + m_profilers.try_emplace(id, ProfilerInfo()); + } + bool IsProfilerActive(StatisticalProfilerId id) const { - return m_activeProfilersFlag[static_cast(id)]; + auto iter = m_profilers.find(id); + return (iter != m_profilers.end()) ? iter->second.m_enabled : false; } StatisticalProfilerType& GetProfiler(StatisticalProfilerId id) { - return m_profilers[static_cast(id)]; + auto iter = m_profilers.try_emplace(id, ProfilerInfo()).first; + return iter->second.m_profiler; } - void ActivateProfiler(StatisticalProfilerId id, bool activate) + void ActivateProfiler(StatisticalProfilerId id, bool activate, bool autoCreate = true) { - m_activeProfilersFlag[static_cast(id)] = activate; + if (autoCreate) + { + auto iter = m_profilers.try_emplace(id, ProfilerInfo()).first; + iter->second.m_enabled = activate; + } + else if (auto iter = m_profilers.find(id); iter != m_profilers.end()) + { + iter->second.m_enabled = activate; + } } void PushSample(StatisticalProfilerId id, const StatIdType& statId, double value) { - m_profilers[static_cast(id)].PushSample(statId, value); + if (auto iter = m_profilers.find(id); iter != m_profilers.end()) + { + iter->second.m_profiler.PushSample(statId, value); + } } private: - // TODO:BUDGETS the number of bits allocated here must be based on the number of budgets available at profiler registration time - AZStd::bitset<128> m_activeProfilersFlag; - AZStd::vector m_profilers; + struct ProfilerInfo + { + StatisticalProfilerType m_profiler; + bool m_enabled{ false }; + }; + + using ProfilerMap = AZStd::unordered_map; + + ProfilerMap m_profilers; }; // class StatisticalProfilerProxy }; // namespace AZ::Statistics diff --git a/Code/Framework/AzCore/Tests/StatisticalProfiler.cpp b/Code/Framework/AzCore/Tests/StatisticalProfiler.cpp index 04e70d92a5..fc5fe66c4b 100644 --- a/Code/Framework/AzCore/Tests/StatisticalProfiler.cpp +++ b/Code/Framework/AzCore/Tests/StatisticalProfiler.cpp @@ -30,6 +30,8 @@ namespace UnitTest { + constexpr AZ::u32 ProfilerProxyGroup = AZ_CRC_CE("StatisticalProfilerProxyTests"); + class StatisticalProfilerTest : public AllocatorsFixture { @@ -98,10 +100,10 @@ namespace UnitTest AZ::Statistics::StatisticalProfiler profiler; - const AZ::Crc32 statIdPerformance = AZ_CRC("PerformanceResult", 0xc1f29a10); + constexpr AZ::Crc32 statIdPerformance = AZ_CRC_CE("PerformanceResult"); const AZStd::string statNamePerformance("PerformanceResult"); - const AZ::Crc32 statIdBlock = AZ_CRC("Block", 0x831b9722); + constexpr AZ::Crc32 statIdBlock = AZ_CRC_CE("Block"); const AZStd::string statNameBlock("Block"); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdPerformance, statNamePerformance, "us") != nullptr); @@ -175,10 +177,10 @@ namespace UnitTest AZ::Statistics::StatisticalProfiler profiler; - const AZ::Crc32 statIdPerformance = AZ_CRC("PerformanceResult", 0xc1f29a10); + constexpr AZ::Crc32 statIdPerformance = AZ_CRC_CE("PerformanceResult"); const AZStd::string statNamePerformance("PerformanceResult"); - const AZ::Crc32 statIdBlock = AZ_CRC("Block", 0x831b9722); + constexpr AZ::Crc32 statIdBlock = AZ_CRC_CE("Block"); const AZStd::string statNameBlock("Block"); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdPerformance, statNamePerformance, "us") != nullptr); @@ -317,26 +319,26 @@ namespace UnitTest AZ::Statistics::StatisticalProfilerProxy::TimedScope::ClearCachedProxy(); AZ::Statistics::StatisticalProfilerProxy profilerProxy; AZ::Statistics::StatisticalProfilerProxy* proxy = AZ::Interface::Get(); - AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(AZ::Debug::ProfileCategory::Terrain); + AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(ProfilerProxyGroup); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdPerformance = "PerformanceResult"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdPerformance("PerformanceResult"); const AZStd::string statNamePerformance("PerformanceResult"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdBlock = "Block"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdBlock("Block"); const AZStd::string statNameBlock("Block"); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdPerformance, statNamePerformance, "us") != nullptr); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdBlock, statNameBlock, "us") != nullptr); - proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, true); + proxy->ActivateProfiler(ProfilerProxyGroup, true); const int iter_count = 10; { - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, statIdPerformance) + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, statIdPerformance) int counter = 0; for (int i = 0; i < iter_count; i++) { - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, statIdBlock) + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, statIdBlock) counter++; } } @@ -348,7 +350,7 @@ namespace UnitTest EXPECT_EQ(profiler.GetStatistic(statIdBlock)->GetNumSamples(), iter_count); //Clean Up - proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, false); + proxy->ActivateProfiler(ProfilerProxyGroup, false); #undef CODE_PROFILER_PROXY_PUSH_TIME @@ -362,12 +364,12 @@ namespace UnitTest const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread1("simple_thread1"); const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread1_loop("simple_thread1_loop"); - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread1); + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, simple_thread1); static int counter = 0; for (int i = 0; i < loop_cnt; i++) { - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread1_loop); + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, simple_thread1_loop); counter++; } } @@ -377,12 +379,12 @@ namespace UnitTest const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread2("simple_thread2"); const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread2_loop("simple_thread2_loop"); - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread2); + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, simple_thread2); static int counter = 0; for (int i = 0; i < loop_cnt; i++) { - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread2_loop); + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, simple_thread2_loop); counter++; } } @@ -392,12 +394,13 @@ namespace UnitTest const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread3("simple_thread3"); const AZ::Statistics::StatisticalProfilerProxy::StatIdType simple_thread3_loop("simple_thread3_loop"); - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread3); + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, simple_thread3); static int counter = 0; for (int i = 0; i < loop_cnt; i++) { - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, simple_thread3_loop); + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, simple_thread3_loop); + counter++; } } @@ -408,21 +411,21 @@ namespace UnitTest AZ::Statistics::StatisticalProfilerProxy::TimedScope::ClearCachedProxy(); AZ::Statistics::StatisticalProfilerProxy profilerProxy; AZ::Statistics::StatisticalProfilerProxy* proxy = AZ::Interface::Get(); - AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(AZ::Debug::ProfileCategory::Terrain); + AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(ProfilerProxyGroup); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1 = "simple_thread1"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1("simple_thread1"); const AZStd::string statNameThread1("simple_thread1"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1Loop = "simple_thread1_loop"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1Loop("simple_thread1_loop"); const AZStd::string statNameThread1Loop("simple_thread1_loop"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread2 = "simple_thread2"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread2("simple_thread2"); const AZStd::string statNameThread2("simple_thread2"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread2Loop = "simple_thread2_loop"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread2Loop("simple_thread2_loop"); const AZStd::string statNameThread2Loop("simple_thread2_loop"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread3 = "simple_thread3"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread3("simple_thread3"); const AZStd::string statNameThread3("simple_thread3"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread3Loop = "simple_thread3_loop"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread3Loop("simple_thread3_loop"); const AZStd::string statNameThread3Loop("simple_thread3_loop"); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread1, statNameThread1, "us")); @@ -432,7 +435,7 @@ namespace UnitTest ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread3, statNameThread3, "us")); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread3Loop, statNameThread3Loop, "us")); - proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, true); + proxy->ActivateProfiler(ProfilerProxyGroup, true); //Let's kickoff the threads to see how much contention affects the profiler's performance. const int iter_count = 10; @@ -459,7 +462,7 @@ namespace UnitTest EXPECT_EQ(profiler.GetStatistic(statIdThread3Loop)->GetNumSamples(), iter_count); //Clean Up - proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, false); + proxy->ActivateProfiler(ProfilerProxyGroup, false); } /** Trace message handler to track messages during tests @@ -566,10 +569,10 @@ namespace UnitTest AZ::Statistics::StatisticalProfiler profiler; - const AZ::Crc32 statIdPerformance = AZ_CRC("PerformanceResult", 0xc1f29a10); + constexpr AZ::Crc32 statIdPerformance = AZ_CRC_CE("PerformanceResult"); const AZStd::string statNamePerformance("PerformanceResult"); - const AZ::Crc32 statIdBlock = AZ_CRC("Block", 0x831b9722); + constexpr AZ::Crc32 statIdBlock = AZ_CRC_CE("Block"); const AZStd::string statNameBlock("Block"); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdPerformance, statNamePerformance, "us") != nullptr); @@ -647,10 +650,10 @@ namespace UnitTest AZ::Statistics::StatisticalProfiler profiler; - const AZ::Crc32 statIdPerformance = AZ_CRC("PerformanceResult", 0xc1f29a10); + constexpr AZ::Crc32 statIdPerformance = AZ_CRC_CE("PerformanceResult"); const AZStd::string statNamePerformance("PerformanceResult"); - const AZ::Crc32 statIdBlock = AZ_CRC("Block", 0x831b9722); + constexpr AZ::Crc32 statIdBlock = AZ_CRC_CE("Block"); const AZStd::string statNameBlock("Block"); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdPerformance, statNamePerformance, "us") != nullptr); @@ -745,26 +748,26 @@ namespace UnitTest AZ::Statistics::StatisticalProfilerProxy::TimedScope::ClearCachedProxy(); AZ::Statistics::StatisticalProfilerProxy profilerProxy; AZ::Statistics::StatisticalProfilerProxy* proxy = AZ::Interface::Get(); - AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(AZ::Debug::ProfileCategory::Terrain); + AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(ProfilerProxyGroup); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdPerformance = "PerformanceResult"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdPerformance("PerformanceResult"); const AZStd::string statNamePerformance("PerformanceResult"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdBlock = "Block"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdBlock("Block"); const AZStd::string statNameBlock("Block"); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdPerformance, statNamePerformance, "us") != nullptr); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdBlock, statNameBlock, "us") != nullptr); - proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, true); + proxy->ActivateProfiler(ProfilerProxyGroup, true); const int iter_count = 1000000; { - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, statIdPerformance) + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, statIdPerformance) int counter = 0; for (int i = 0; i < iter_count; i++) { - CODE_PROFILER_PROXY_PUSH_TIME(AZ::Debug::ProfileCategory::Terrain, statIdBlock) + CODE_PROFILER_PROXY_PUSH_TIME(ProfilerProxyGroup, statIdBlock) counter++; } } @@ -778,7 +781,7 @@ namespace UnitTest profiler.LogAndResetStats("StatisticalProfilerProxy"); //Clean Up - proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, false); + proxy->ActivateProfiler(ProfilerProxyGroup, false); } #undef CODE_PROFILER_PROXY_PUSH_TIME @@ -788,21 +791,21 @@ namespace UnitTest AZ::Statistics::StatisticalProfilerProxy::TimedScope::ClearCachedProxy(); AZ::Statistics::StatisticalProfilerProxy profilerProxy; AZ::Statistics::StatisticalProfilerProxy* proxy = AZ::Interface::Get(); - AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(AZ::Debug::ProfileCategory::Terrain); + AZ::Statistics::StatisticalProfilerProxy::StatisticalProfilerType& profiler = proxy->GetProfiler(ProfilerProxyGroup); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1 = "simple_thread1"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1("simple_thread1"); const AZStd::string statNameThread1("simple_thread1"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1Loop = "simple_thread1_loop"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread1Loop("simple_thread1_loop"); const AZStd::string statNameThread1Loop("simple_thread1_loop"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread2 = "simple_thread2"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread2("simple_thread2"); const AZStd::string statNameThread2("simple_thread2"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread2Loop = "simple_thread2_loop"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread2Loop("simple_thread2_loop"); const AZStd::string statNameThread2Loop("simple_thread2_loop"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread3 = "simple_thread3"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread3("simple_thread3"); const AZStd::string statNameThread3("simple_thread3"); - const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread3Loop = "simple_thread3_loop"; + const AZ::Statistics::StatisticalProfilerProxy::StatIdType statIdThread3Loop("simple_thread3_loop"); const AZStd::string statNameThread3Loop("simple_thread3_loop"); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread1, statNameThread1, "us")); @@ -812,7 +815,7 @@ namespace UnitTest ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread3, statNameThread3, "us")); ASSERT_TRUE(profiler.GetStatsManager().AddStatistic(statIdThread3Loop, statNameThread3Loop, "us")); - proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, true); + proxy->ActivateProfiler(ProfilerProxyGroup, true); //Let's kickoff the threads to see how much contention affects the profiler's performance. const int iter_count = 1000000; @@ -841,7 +844,7 @@ namespace UnitTest profiler.LogAndResetStats("3_Threads_StatisticalProfilerProxy"); //Clean Up - proxy->ActivateProfiler(AZ::Debug::ProfileCategory::Terrain, false); + proxy->ActivateProfiler(ProfilerProxyGroup, false); } }//namespace UnitTest diff --git a/Code/Framework/AzCore/Tests/azcoretests_files.cmake b/Code/Framework/AzCore/Tests/azcoretests_files.cmake index a111af0353..e155594aa0 100644 --- a/Code/Framework/AzCore/Tests/azcoretests_files.cmake +++ b/Code/Framework/AzCore/Tests/azcoretests_files.cmake @@ -61,6 +61,7 @@ set(FILES Slice.cpp State.cpp Statistics.cpp + StatisticalProfiler.cpp StreamerTests.cpp StringFunc.cpp SystemFile.cpp