From 95ed1015a5ed4f86e6e10166aba0e1431de65ce2 Mon Sep 17 00:00:00 2001 From: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> Date: Wed, 1 Dec 2021 18:48:07 -0800 Subject: [PATCH] Removes the MemoryDriller Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> --- .../AzCore/Component/ComponentApplication.cpp | 1 - .../AzCore/AzCore/Memory/AllocatorBase.h | 2 +- .../AzCore/AzCore/Memory/IAllocator.h | 5 +- .../AzCore/AzCore/Memory/MemoryDriller.cpp | 291 ------------------ .../AzCore/AzCore/Memory/MemoryDriller.h | 71 ----- .../AzCore/AzCore/UnitTest/TestTypes.h | 2 - .../AzCore/AzCore/azcore_files.cmake | 2 - Code/Framework/AzCore/Tests/Memory.cpp | 2 - .../AzCore/Tests/Memory/LeakDetection.cpp | 1 - Code/Framework/GridMate/Tests/Tests.h | 2 - Gems/Atom/RHI/Code/Tests/RHITestFixture.h | 1 - .../Framework/ScriptCanvasTestFixture.h | 1 - 12 files changed, 2 insertions(+), 379 deletions(-) delete mode 100644 Code/Framework/AzCore/AzCore/Memory/MemoryDriller.cpp delete mode 100644 Code/Framework/AzCore/AzCore/Memory/MemoryDriller.h diff --git a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp index 830f70ab60..21405896a3 100644 --- a/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp +++ b/Code/Framework/AzCore/AzCore/Component/ComponentApplication.cpp @@ -49,7 +49,6 @@ #include #include -#include #include #include #include diff --git a/Code/Framework/AzCore/AzCore/Memory/AllocatorBase.h b/Code/Framework/AzCore/AzCore/Memory/AllocatorBase.h index ea9e2a492a..8f8a17e470 100644 --- a/Code/Framework/AzCore/AzCore/Memory/AllocatorBase.h +++ b/Code/Framework/AzCore/AzCore/Memory/AllocatorBase.h @@ -102,7 +102,7 @@ namespace AZ const char* m_name = nullptr; const char* m_desc = nullptr; - Debug::AllocationRecords* m_records = nullptr; // Cached pointer to allocation records. Works together with the MemoryDriller. + Debug::AllocationRecords* m_records = nullptr; // Cached pointer to allocation records size_t m_memoryGuardSize = 0; bool m_isLazilyCreated = false; bool m_isProfilingActive = false; diff --git a/Code/Framework/AzCore/AzCore/Memory/IAllocator.h b/Code/Framework/AzCore/AzCore/Memory/IAllocator.h index 1aa4cf70f5..532335e50b 100644 --- a/Code/Framework/AzCore/AzCore/Memory/IAllocator.h +++ b/Code/Framework/AzCore/AzCore/Memory/IAllocator.h @@ -14,7 +14,6 @@ namespace AZ namespace Debug { class AllocationRecords; - class MemoryDriller; } namespace AllocatorStorage @@ -83,7 +82,7 @@ namespace AZ /// Sets the number of entries to omit from the top of the callstack when recording stack traces. AllocatorDebugConfig& StackRecordLevels(int levels) { m_stackRecordLevels = levels; return *this; } - /// Set to true if this allocator should not have its records recorded and analyzed by systems like the MemoryDriller. + /// Set to true if this allocator should not have its records recorded and analyzed. AllocatorDebugConfig& ExcludeFromDebugging(bool exclude = true) { m_excludeFromDebugging = exclude; return *this; } /// Set to true if this allocator expands allocations with guard sections to detect overruns. @@ -207,8 +206,6 @@ namespace AZ template friend class AllocatorWrapper; - - friend class Debug::MemoryDriller; }; } diff --git a/Code/Framework/AzCore/AzCore/Memory/MemoryDriller.cpp b/Code/Framework/AzCore/AzCore/Memory/MemoryDriller.cpp deleted file mode 100644 index dc35c6322b..0000000000 --- a/Code/Framework/AzCore/AzCore/Memory/MemoryDriller.cpp +++ /dev/null @@ -1,291 +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 -#include - -#include -#include - -#include -#include - -namespace AZ::Debug -{ - //========================================================================= - // MemoryDriller - // [2/6/2013] - //========================================================================= - MemoryDriller::MemoryDriller(const Descriptor& desc) - { - (void)desc; - BusConnect(); - - AllocatorManager::Instance().EnterProfilingMode(); - - { - // Register all allocators that were created before the driller existed - auto allocatorLock = AllocatorManager::Instance().LockAllocators(); - - for (int i = 0; i < AllocatorManager::Instance().GetNumAllocators(); ++i) - { - IAllocator* allocator = AllocatorManager::Instance().GetAllocator(i); - RegisterAllocator(allocator); - } - } - } - - //========================================================================= - // ~MemoryDriller - // [2/6/2013] - //========================================================================= - MemoryDriller::~MemoryDriller() - { - BusDisconnect(); - AllocatorManager::Instance().ExitProfilingMode(); - } - - //========================================================================= - // Start - // [2/6/2013] - //========================================================================= - void MemoryDriller::Start(const Param* params, int numParams) - { - (void)params; - (void)numParams; - - // dump current allocations for all allocators with tracking - auto allocatorLock = AllocatorManager::Instance().LockAllocators(); - for (int i = 0; i < AllocatorManager::Instance().GetNumAllocators(); ++i) - { - IAllocator* allocator = AllocatorManager::Instance().GetAllocator(i); - if (auto records = allocator->GetRecords()) - { - RegisterAllocatorOutput(allocator); - const AllocationRecordsType& allocMap = records->GetMap(); - for (AllocationRecordsType::const_iterator allocIt = allocMap.begin(); allocIt != allocMap.end(); ++allocIt) - { - RegisterAllocationOutput(allocator, allocIt->first, &allocIt->second); - } - } - } - } - - //========================================================================= - // Stop - // [2/6/2013] - //========================================================================= - void MemoryDriller::Stop() - { - } - - //========================================================================= - // RegisterAllocator - // [2/6/2013] - //========================================================================= - void MemoryDriller::RegisterAllocator(IAllocator* allocator) - { - // Ignore if our allocator is already registered - if (allocator->GetRecords() != nullptr) - { - return; - } - - auto debugConfig = allocator->GetDebugConfig(); - - if (!debugConfig.m_excludeFromDebugging) - { - allocator->SetRecords(aznew Debug::AllocationRecords((unsigned char)debugConfig.m_stackRecordLevels, debugConfig.m_usesMemoryGuards, debugConfig.m_marksUnallocatedMemory, allocator->GetName())); - - m_allAllocatorRecords.push_back(allocator->GetRecords()); - - if (m_output == nullptr) - { - return; // we have no active output - } - RegisterAllocatorOutput(allocator); - } - } - //========================================================================= - // RegisterAllocatorOutput - // [2/6/2013] - //========================================================================= - void MemoryDriller::RegisterAllocatorOutput(IAllocator* allocator) - { - auto records = allocator->GetRecords(); - m_output->BeginTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - m_output->BeginTag(AZ_CRC("RegisterAllocator", 0x19f08114)); - m_output->Write(AZ_CRC("Name", 0x5e237e06), allocator->GetName()); - m_output->Write(AZ_CRC("Id", 0xbf396750), allocator); - m_output->Write(AZ_CRC("Capacity", 0xb5e8b174), allocator->GetAllocationSource()->Capacity()); - m_output->Write(AZ_CRC("RecordsId", 0x7caaca88), records); - if (records) - { - m_output->Write(AZ_CRC("RecordsMode", 0x764c147a), (char)records->GetMode()); - m_output->Write(AZ_CRC("NumStackLevels", 0xad9cff15), records->GetNumStackLevels()); - } - m_output->EndTag(AZ_CRC("RegisterAllocator", 0x19f08114)); - m_output->EndTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - } - - //========================================================================= - // UnregisterAllocator - // [2/6/2013] - //========================================================================= - void MemoryDriller::UnregisterAllocator(IAllocator* allocator) - { - auto allocatorRecords = allocator->GetRecords(); - AZ_Assert(allocatorRecords, "This allocator is not registered with the memory driller!"); - for (auto records : m_allAllocatorRecords) - { - if (records == allocatorRecords) - { - m_allAllocatorRecords.remove(records); - break; - } - } - delete allocatorRecords; - allocator->SetRecords(nullptr); - - if (m_output == nullptr) - { - return; // we have no active output - } - m_output->BeginTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - m_output->Write(AZ_CRC("UnregisterAllocator", 0xb2b54f93), allocator); - m_output->EndTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - } - - //========================================================================= - // RegisterAllocation - // [2/6/2013] - //========================================================================= - void MemoryDriller::RegisterAllocation(IAllocator* allocator, void* address, size_t byteSize, size_t alignment, const char* name, const char* fileName, int lineNum, unsigned int stackSuppressCount) - { - auto records = allocator->GetRecords(); - if (records) - { - const AllocationInfo* info = records->RegisterAllocation(address, byteSize, alignment, name, fileName, lineNum, stackSuppressCount + 1); - if (m_output == nullptr) - { - return; // we have no active output - } - RegisterAllocationOutput(allocator, address, info); - } - } - - //========================================================================= - // RegisterAllocationOutput - // [2/6/2013] - //========================================================================= - void MemoryDriller::RegisterAllocationOutput(IAllocator* allocator, void* address, const AllocationInfo* info) - { - auto records = allocator->GetRecords(); - m_output->BeginTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - m_output->BeginTag(AZ_CRC("RegisterAllocation", 0x992a9780)); - m_output->Write(AZ_CRC("RecordsId", 0x7caaca88), records); - m_output->Write(AZ_CRC("Address", 0x0d4e6f81), address); - if (info) - { - if (info->m_name) - { - m_output->Write(AZ_CRC("Name", 0x5e237e06), info->m_name); - } - m_output->Write(AZ_CRC("Alignment", 0x2cce1e5c), info->m_alignment); - m_output->Write(AZ_CRC("Size", 0xf7c0246a), info->m_byteSize); - if (info->m_fileName) - { - m_output->Write(AZ_CRC("FileName", 0x3c0be965), info->m_fileName); - m_output->Write(AZ_CRC("FileLine", 0xb33c2395), info->m_lineNum); - } - // copy the stack frames directly, resolving the stack should happen later as this is a SLOW procedure. - if (info->m_stackFrames) - { - m_output->Write(AZ_CRC("Stack", 0x41a87b6a), info->m_stackFrames, info->m_stackFrames + records->GetNumStackLevels()); - } - } - m_output->EndTag(AZ_CRC("RegisterAllocation", 0x992a9780)); - m_output->EndTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - } - - //========================================================================= - // UnRegisterAllocation - // [2/6/2013] - //========================================================================= - void MemoryDriller::UnregisterAllocation(IAllocator* allocator, void* address, size_t byteSize, size_t alignment, AllocationInfo* info) - { - auto records = allocator->GetRecords(); - if (records) - { - records->UnregisterAllocation(address, byteSize, alignment, info); - - if (m_output == nullptr) - { - return; // we have no active output - } - m_output->BeginTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - m_output->BeginTag(AZ_CRC("UnRegisterAllocation", 0xea5dc4cd)); - m_output->Write(AZ_CRC("RecordsId", 0x7caaca88), records); - m_output->Write(AZ_CRC("Address", 0x0d4e6f81), address); - m_output->EndTag(AZ_CRC("UnRegisterAllocation", 0xea5dc4cd)); - m_output->EndTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - } - } - - //========================================================================= - // ReallocateAllocation - // [10/1/2018] - //========================================================================= - void MemoryDriller::ReallocateAllocation(IAllocator* allocator, void* prevAddress, void* newAddress, size_t newByteSize, size_t newAlignment) - { - AllocationInfo info; - UnregisterAllocation(allocator, prevAddress, 0, 0, &info); - RegisterAllocation(allocator, newAddress, newByteSize, newAlignment, info.m_name, info.m_fileName, info.m_lineNum, 0); - } - - //========================================================================= - // ResizeAllocation - // [2/6/2013] - //========================================================================= - void MemoryDriller::ResizeAllocation(IAllocator* allocator, void* address, size_t newSize) - { - auto records = allocator->GetRecords(); - if (records) - { - records->ResizeAllocation(address, newSize); - - if (m_output == nullptr) - { - return; // we have no active output - } - m_output->BeginTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - m_output->BeginTag(AZ_CRC("ResizeAllocation", 0x8a9c78dc)); - m_output->Write(AZ_CRC("RecordsId", 0x7caaca88), records); - m_output->Write(AZ_CRC("Address", 0x0d4e6f81), address); - m_output->Write(AZ_CRC("Size", 0xf7c0246a), newSize); - m_output->EndTag(AZ_CRC("ResizeAllocation", 0x8a9c78dc)); - m_output->EndTag(AZ_CRC("MemoryDriller", 0x1b31269d)); - } - } - - void MemoryDriller::DumpAllAllocations() - { - // Create a copy so allocations done during the printing dont end up affecting the container - const AZStd::list allocationRecords = m_allAllocatorRecords; - - for (auto records : allocationRecords) - { - // Skip if we have had no allocations made - if (records->RequestedAllocs()) - { - records->EnumerateAllocations(AZ::Debug::PrintAllocationsCB(true, true)); - } - } - } - -} // namespace AZ::Debug diff --git a/Code/Framework/AzCore/AzCore/Memory/MemoryDriller.h b/Code/Framework/AzCore/AzCore/Memory/MemoryDriller.h deleted file mode 100644 index 9bcbc85217..0000000000 --- a/Code/Framework/AzCore/AzCore/Memory/MemoryDriller.h +++ /dev/null @@ -1,71 +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 - * - */ -#ifndef AZCORE_MEMORY_DRILLER_H -#define AZCORE_MEMORY_DRILLER_H 1 - -#include -#include - -namespace AZ -{ - namespace Debug - { - struct StackFrame; - - /** - * Trace messages driller class - */ - class MemoryDriller - : public Driller - , public MemoryDrillerBus::Handler - { - public: - AZ_CLASS_ALLOCATOR(MemoryDriller, OSAllocator, 0) - - // TODO: Centralized settings for memory tracking. - struct Descriptor - { - }; - - MemoryDriller(const Descriptor& desc = Descriptor()); - ~MemoryDriller(); - - protected: - ////////////////////////////////////////////////////////////////////////// - // Driller - const char* GroupName() const override { return "SystemDrillers"; } - const char* GetName() const override { return "MemoryDriller"; } - const char* GetDescription() const override { return "Reports all allocators and memory allocations."; } - void Start(const Param* params = NULL, int numParams = 0) override; - void Stop() override; - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // MemoryDrillerBus - void RegisterAllocator(IAllocator* allocator) override; - void UnregisterAllocator(IAllocator* allocator) override; - - void RegisterAllocation(IAllocator* allocator, void* address, size_t byteSize, size_t alignment, const char* name, const char* fileName, int lineNum, unsigned int stackSuppressCount) override; - void UnregisterAllocation(IAllocator* allocator, void* address, size_t byteSize, size_t alignment, AllocationInfo* info) override; - void ReallocateAllocation(IAllocator* allocator, void* prevAddress, void* newAddress, size_t newByteSize, size_t newAlignment) override; - void ResizeAllocation(IAllocator* allocator, void* address, size_t newSize) override; - - void DumpAllAllocations() override; - ////////////////////////////////////////////////////////////////////////// - - void RegisterAllocatorOutput(IAllocator* allocator); - void RegisterAllocationOutput(IAllocator* allocator, void* address, const AllocationInfo* info); - private: - // Store a list of all of our allocator records so we can dump them all without having to know about the allocators - AZStd::list m_allAllocatorRecords; - }; - } // namespace Debug -} // namespace AZ - -#endif // AZCORE_MEMORY_DRILLER_H -#pragma once diff --git a/Code/Framework/AzCore/AzCore/UnitTest/TestTypes.h b/Code/Framework/AzCore/AzCore/UnitTest/TestTypes.h index e5dcb32d9d..53065bf2ed 100644 --- a/Code/Framework/AzCore/AzCore/UnitTest/TestTypes.h +++ b/Code/Framework/AzCore/AzCore/UnitTest/TestTypes.h @@ -14,7 +14,6 @@ #include #include #include -#include #include #if defined(HAVE_BENCHMARK) @@ -48,7 +47,6 @@ namespace UnitTest void SetupAllocator(const AZ::SystemAllocator::Descriptor& allocatorDesc = {}) { m_drillerManager = AZ::Debug::DrillerManager::Create(); - m_drillerManager->Register(aznew AZ::Debug::MemoryDriller); AZ::AllocatorManager::Instance().SetDefaultTrackingMode(AZ::Debug::AllocationRecords::RECORD_FULL); // Only create the SystemAllocator if it s not ready diff --git a/Code/Framework/AzCore/AzCore/azcore_files.cmake b/Code/Framework/AzCore/AzCore/azcore_files.cmake index 067b12db3d..20d1644ae8 100644 --- a/Code/Framework/AzCore/AzCore/azcore_files.cmake +++ b/Code/Framework/AzCore/AzCore/azcore_files.cmake @@ -397,8 +397,6 @@ set(FILES Memory/Memory.h Memory/MemoryComponent.cpp Memory/MemoryComponent.h - Memory/MemoryDriller.cpp - Memory/MemoryDriller.h Memory/MemoryDrillerBus.h Memory/nedmalloc.inl Memory/NewAndDelete.inl diff --git a/Code/Framework/AzCore/Tests/Memory.cpp b/Code/Framework/AzCore/Tests/Memory.cpp index 5a483c1ed1..f4d58c4d8a 100644 --- a/Code/Framework/AzCore/Tests/Memory.cpp +++ b/Code/Framework/AzCore/Tests/Memory.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include #include @@ -45,7 +44,6 @@ namespace UnitTest { AZ::AllocatorManager::Instance().SetDefaultTrackingMode(AZ::Debug::AllocationRecords::RECORD_FULL); m_drillerManager = Debug::DrillerManager::Create(); - m_drillerManager->Register(aznew MemoryDriller); } void TearDown() override { diff --git a/Code/Framework/AzCore/Tests/Memory/LeakDetection.cpp b/Code/Framework/AzCore/Tests/Memory/LeakDetection.cpp index 09255ce16f..6e15507545 100644 --- a/Code/Framework/AzCore/Tests/Memory/LeakDetection.cpp +++ b/Code/Framework/AzCore/Tests/Memory/LeakDetection.cpp @@ -271,7 +271,6 @@ namespace UnitTest void SetUp() override { m_drillerManager = AZ::Debug::DrillerManager::Create(); - m_drillerManager->Register(aznew AZ::Debug::MemoryDriller); AZ::AllocatorManager::Instance().SetDefaultTrackingMode(AZ::Debug::AllocationRecords::RECORD_FULL); if (azrtti_typeid() != azrtti_typeid()) // simplifies instead of template specialization diff --git a/Code/Framework/GridMate/Tests/Tests.h b/Code/Framework/GridMate/Tests/Tests.h index 7e1638c5e5..88379ad5fb 100644 --- a/Code/Framework/GridMate/Tests/Tests.h +++ b/Code/Framework/GridMate/Tests/Tests.h @@ -19,7 +19,6 @@ #include #include -#include #include @@ -67,7 +66,6 @@ namespace UnitTest GridMate::GridMateDesc desc; #if GM_TEST_MEMORY_DRILLING m_drillerManager = AZ::Debug::DrillerManager::Create(); - m_drillerManager->Register(aznew AZ::Debug::MemoryDriller); desc.m_allocatorDesc.m_allocationRecords = true; #endif diff --git a/Gems/Atom/RHI/Code/Tests/RHITestFixture.h b/Gems/Atom/RHI/Code/Tests/RHITestFixture.h index 620fc03c6f..7bdd232a8b 100644 --- a/Gems/Atom/RHI/Code/Tests/RHITestFixture.h +++ b/Gems/Atom/RHI/Code/Tests/RHITestFixture.h @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/Gems/ScriptCanvasTesting/Code/Source/Framework/ScriptCanvasTestFixture.h b/Gems/ScriptCanvasTesting/Code/Source/Framework/ScriptCanvasTestFixture.h index 217b0ea695..41f23a44b4 100644 --- a/Gems/ScriptCanvasTesting/Code/Source/Framework/ScriptCanvasTestFixture.h +++ b/Gems/ScriptCanvasTesting/Code/Source/Framework/ScriptCanvasTestFixture.h @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include