From a9b4ad3486dae98adddb2fde30705fe3d54eb17a Mon Sep 17 00:00:00 2001 From: Jeremy Ong Date: Tue, 24 Aug 2021 15:06:56 -0600 Subject: [PATCH] Compile out tracker in release mode Signed-off-by: Jeremy Ong --- .../AzCore/Component/ComponentApplication.cpp | 4 +++ .../AzCore/Component/ComponentApplication.h | 2 ++ Code/Framework/AzCore/AzCore/Debug/Budget.cpp | 6 +++++ Code/Framework/AzCore/AzCore/Debug/Budget.h | 25 +++++++++---------- .../TerrainFeatureProcessor.cpp | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp index e9e5738bd1..383da71653 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp @@ -545,7 +545,9 @@ namespace AZ m_entityActivatedEvent.DisconnectAllHandlers(); m_entityDeactivatedEvent.DisconnectAllHandlers(); +#if !defined(_RELEASE) m_budgetTracker.Reset(); +#endif DestroyAllocator(); } @@ -595,7 +597,9 @@ namespace AZ CreateOSAllocator(); CreateSystemAllocator(); +#if !defined(_RELEASE) m_budgetTracker.Init(); +#endif // This can be moved to the ComponentApplication constructor if need be // This is reading the *.setreg files using SystemFile and merging the settings diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h index b2a1f0324b..3768a75d83 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.h @@ -395,7 +395,9 @@ namespace AZ // from the m_console member when it goes out of scope AZ::SettingsRegistryConsoleUtils::ConsoleFunctorHandle m_settingsRegistryConsoleFunctors; +#if !defined(_RELEASE) Debug::BudgetTracker m_budgetTracker; +#endif // this is used when no argV/ArgC is supplied. // in order to have the same memory semantics (writable, non-const) diff --git a/Code/Framework/AzCore/AzCore/Debug/Budget.cpp b/Code/Framework/AzCore/AzCore/Debug/Budget.cpp index 9790257ded..f9fe7e462a 100644 --- a/Code/Framework/AzCore/AzCore/Debug/Budget.cpp +++ b/Code/Framework/AzCore/AzCore/Debug/Budget.cpp @@ -29,6 +29,12 @@ namespace AZ::Debug // TODO: Budget implementation for tracking budget wall time per-core, memory, etc. }; + Budget::Budget(const char* name) + : m_name{ name } + , m_crc{ Crc32(name) } + { + } + Budget::Budget(const char* name, uint32_t crc) : m_name{ name } , m_crc{ crc } diff --git a/Code/Framework/AzCore/AzCore/Debug/Budget.h b/Code/Framework/AzCore/AzCore/Debug/Budget.h index 376bf4cc4a..d051ba860b 100644 --- a/Code/Framework/AzCore/AzCore/Debug/Budget.h +++ b/Code/Framework/AzCore/AzCore/Debug/Budget.h @@ -9,7 +9,6 @@ #include #include -#include namespace AZ::Debug { @@ -17,6 +16,7 @@ namespace AZ::Debug class Budget final { public: + explicit Budget(const char* name); Budget(const char* name, uint32_t crc); ~Budget(); @@ -38,7 +38,7 @@ namespace AZ::Debug private: const char* m_name; - uint32_t m_crc; + const uint32_t m_crc; struct BudgetImpl* m_impl = nullptr; }; } // namespace AZ::Debug @@ -49,6 +49,13 @@ namespace AZ::Debug // for usage. #define AZ_BUDGET_GETTER(name) GetAzBudget##name +#if defined(_RELEASE) +#define AZ_DEFINE_BUDGET(name) \ + ::AZ::Debug::Budget* AZ_BUDGET_GETTER(name)() \ + { \ + return nullptr; \ + } +#else // Usage example: // In a single C++ source file: // AZ_DEFINE_BUDGET(AzCore); @@ -59,18 +66,10 @@ namespace AZ::Debug ::AZ::Debug::Budget* AZ_BUDGET_GETTER(name)() \ { \ constexpr static uint32_t crc = AZ_CRC_CE(#name); \ - static ::AZStd::atomic<::AZ::Debug::Budget*> budget; \ - ::AZ::Debug::Budget* out = budget.load(AZStd::memory_order_acquire); \ - if (out) \ - { \ - return out; \ - } \ - else \ - { \ - budget.store(::AZ::Debug::BudgetTracker::GetBudgetFromEnvironment(#name, crc), AZStd::memory_order_release); \ - return budget; \ - } \ + static ::AZ::Debug::Budget* budget = ::AZ::Debug::BudgetTracker::GetBudgetFromEnvironment(#name, crc); \ + return budget; \ } +#endif // If using a budget defined in a different C++ source file, add AZ_DECLARE_BUDGET(yourBudget); somewhere in your source file at namespace // scope Alternatively, AZ_DECLARE_BUDGET can be used in a header to declare the budget for use across any users of the header diff --git a/Gems/Terrain/Code/Source/TerrainRenderer/TerrainFeatureProcessor.cpp b/Gems/Terrain/Code/Source/TerrainRenderer/TerrainFeatureProcessor.cpp index 5af3fd58b9..812ed3f0da 100644 --- a/Gems/Terrain/Code/Source/TerrainRenderer/TerrainFeatureProcessor.cpp +++ b/Gems/Terrain/Code/Source/TerrainRenderer/TerrainFeatureProcessor.cpp @@ -269,7 +269,7 @@ namespace Terrain void TerrainFeatureProcessor::ProcessSurfaces(const FeatureProcessor::RenderPacket& process) { - AZ_PROFILE_FUNCTION(AZ::Debug::ProfileCategory::AzRender); + AZ_PROFILE_FUNCTION(AzRender); if (m_drawListTag.IsNull()) {