Skip to content

Commit

Permalink
Add sys dumpallocators console command (#16864)
Browse files Browse the repository at this point in the history
* add sys_DumpAllocators console command

sys_DumpAllocators prints a summary list of allocator names and stats

Signed-off-by: Alex Peterson <[email protected]>

* add more descriptive RTTI names for allocators

added a few custom allocators with descriptive RTTI names to make it easier to tell allocators apart when using the sys_DumpAllocators command

Signed-off-by: Alex Peterson <[email protected]>

---------

Signed-off-by: Alex Peterson <[email protected]>
  • Loading branch information
AMZN-alexpete authored Oct 9, 2023
1 parent c323ef4 commit eb38872
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Code/Framework/AzCore/AzCore/Console/IConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static constexpr AZ::ThreadSafety ConsoleThreadSafety<_TYPE, std::enable_if_t<st
extern CVarDataWrapperType##_NAME _NAME;

//! Implements a console functor for a class member function.
//! @param _CLASS the that the function gets invoked on
//! @param _CLASS the class that the function gets invoked on
//! @param _FUNCTION the method to invoke
//! You have no guarantees as to what thread will invoke the function
//! It is the responsibility of the implementor of the console function to ensure thread safety
Expand Down
7 changes: 7 additions & 0 deletions Code/Framework/AzCore/AzCore/Memory/AllocatorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*
*/

#include <AzCore/Console/IConsole.h>
#include <AzCore/Math/Crc.h>
#include <AzCore/Memory/AllocatorManager.h>
#include <AzCore/Memory/Memory.h>
Expand All @@ -21,6 +22,12 @@
namespace AZ
{

static void sys_DumpAllocators([[maybe_unused]] const AZ::ConsoleCommandContainer& arguments)
{
AllocatorManager::Instance().DumpAllocators();
}
AZ_CONSOLEFREEFUNC(sys_DumpAllocators, AZ::ConsoleFunctorFlags::Null, "Print memory allocator statistics.");

static EnvironmentVariable<AllocatorManager>& GetAllocatorManagerEnvVar()
{
static EnvironmentVariable<AllocatorManager> s_allocManager;
Expand Down
11 changes: 10 additions & 1 deletion Gems/Atom/RHI/Code/Include/Atom/RHI/PoolAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@

namespace AZ::RHI
{
//! This custom allocator class is used to provide runtime type information
//! so we can differentiate this allocator from other SystemAllocators
class RHISystemAllocator final
: public AZ::SystemAllocator
{
public:
AZ_RTTI(RHISystemAllocator, "{C5F84DB9-AD7E-4846-AC4D-409F61F7DA84}", AZ::SystemAllocator);
};

//! This class can be used to efficiently allocate small chunks of memory from an externally
//! managed source (DMA / Gpu memory). It will recycle freed blocks by deferring for a configurable
//! number of ticks. If the memory is being used as GPU local memory, its common for the CPU to write
Expand All @@ -30,7 +39,7 @@ namespace AZ::RHI
uint32_t m_elementSize = 0;
};

AZ_CLASS_ALLOCATOR(PoolAllocator, AZ::SystemAllocator);
AZ_CLASS_ALLOCATOR(PoolAllocator, RHISystemAllocator);

PoolAllocator() = default;

Expand Down
2 changes: 1 addition & 1 deletion Gems/EMotionFX/Code/EMotionFX/Source/Allocators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace AZ::Internal
{
// Add implementation of PoolAllocatorHelper base class template RTTI functions
// needed by the derived EMotionFX Pool allocators
AZ_TYPE_INFO_TEMPLATE_WITH_NAME_IMPL(PoolAllocatorHelper, "PoolAllocatorHelper", PoolAllocatorHelperTemplateId, AZ_TYPE_INFO_CLASS);
AZ_TYPE_INFO_TEMPLATE_WITH_NAME_IMPL(PoolAllocatorHelper, "EMotionFX::PoolAllocatorHelper", PoolAllocatorHelperTemplateId, AZ_TYPE_INFO_CLASS);
AZ_RTTI_NO_TYPE_INFO_IMPL((PoolAllocatorHelper, AZ_TYPE_INFO_CLASS), Base);

// Explicitly instantite the PoolAllocator schemas for the EMotionFX Allocators
Expand Down
6 changes: 5 additions & 1 deletion Gems/EMotionFX/Code/EMotionFX/Source/Allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ namespace EMotionFX
public: \
AZ_TYPE_INFO(EMOTIONFX_ALLOCATOR_SEQ_GET_NAME(ALLOCATOR_SEQUENCE), EMOTIONFX_ALLOCATOR_SEQ_GET_UUID(ALLOCATOR_SEQUENCE)); \
using Base = EMOTIONFX_ALLOCATOR_SEQ_GET_TYPE(ALLOCATOR_SEQUENCE); \
};
AZ_RTTI_NO_TYPE_INFO_DECL(); \
};\
\
AZ_RTTI_NO_TYPE_INFO_IMPL_INLINE( \
EMOTIONFX_ALLOCATOR_SEQ_GET_NAME(ALLOCATOR_SEQUENCE), EMOTIONFX_ALLOCATOR_SEQ_GET_NAME(ALLOCATOR_SEQUENCE)::Base);

// Here we create all the classes for all the items in the above table (Step 1)
AZ_SEQ_FOR_EACH(EMOTIONFX_ALLOCATOR_DECL, EMOTIONFX_ALLOCATORS)
Expand Down
5 changes: 4 additions & 1 deletion Gems/EMotionFX/Code/MCore/Source/AttributeAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ namespace MCore
{
friend class AZ::AllocatorInstance<AZ::PoolAllocator>;
public:
AZ_TYPE_INFO(AttributeAllocator, "{005003CF-87D1-4DAD-A159-59217F67886B}");
AZ_TYPE_INFO_WITH_NAME(AttributeAllocator, "EMotionFX::AttributeAllocator", "{005003CF-87D1-4DAD-A159-59217F67886B}");
AZ_RTTI_NO_TYPE_INFO_DECL();
};

AZ_RTTI_NO_TYPE_INFO_IMPL_INLINE(AttributeAllocator);
}
15 changes: 12 additions & 3 deletions Gems/LyShine/Code/Source/RenderGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,21 @@ namespace LyShine
RenderNodeType m_type;
};

//! This custom allocator class is used to provide runtime type information
//! so we can differentiate this allocator from other PoolAllocators
class LyShinePoolAllocator final
: public AZ::PoolAllocator
{
public:
AZ_RTTI(LyShinePoolAllocator, "{0FFA2FE4-498A-4FF6-A58A-F49F0E8575EE}", AZ::PoolAllocator);
};

// As we build the render graph we allocate a render node for each change in render state
class PrimitiveListRenderNode : public RenderNode
{
public: // functions
// We use a pool allocator to keep these allocations fast.
AZ_CLASS_ALLOCATOR(PrimitiveListRenderNode, AZ::PoolAllocator);
AZ_CLASS_ALLOCATOR(PrimitiveListRenderNode, LyShinePoolAllocator);

PrimitiveListRenderNode(const AZ::Data::Instance<AZ::RPI::Image>& texture, bool isClampTextureMode, bool isTextureSRGB, bool preMultiplyAlpha, const AZ::RHI::TargetBlendState& blendModeState);
PrimitiveListRenderNode(const AZ::Data::Instance<AZ::RPI::Image>& texture, const AZ::Data::Instance<AZ::RPI::Image>& maskTexture,
Expand Down Expand Up @@ -130,7 +139,7 @@ namespace LyShine
{
public: // functions
// We use a pool allocator to keep these allocations fast.
AZ_CLASS_ALLOCATOR(MaskRenderNode, AZ::PoolAllocator);
AZ_CLASS_ALLOCATOR(MaskRenderNode, LyShinePoolAllocator);

MaskRenderNode(MaskRenderNode* parentMask, bool isMaskingEnabled, bool useAlphaTest, bool drawBehind, bool drawInFront);
~MaskRenderNode() override;
Expand Down Expand Up @@ -186,7 +195,7 @@ namespace LyShine
{
public: // functions
// We use a pool allocator to keep these allocations fast.
AZ_CLASS_ALLOCATOR(RenderTargetRenderNode, AZ::PoolAllocator);
AZ_CLASS_ALLOCATOR(RenderTargetRenderNode, LyShinePoolAllocator);

RenderTargetRenderNode(RenderTargetRenderNode* parentRenderTarget,
AZ::Data::Instance<AZ::RPI::AttachmentImage> attachmentImage,
Expand Down

0 comments on commit eb38872

Please sign in to comment.