Add more improvements to usability of memory profiler

This commit is contained in:
Wojtek Figat
2025-06-06 22:40:43 +02:00
parent e8b60060ab
commit 091f76bbf2
8 changed files with 63 additions and 20 deletions

View File

@@ -21,6 +21,7 @@
#define USE_TRACY_MEMORY_PLOTS (defined(TRACY_ENABLE))
static_assert(GROUPS_COUNT <= MAX_uint8, "Fix memory profiler groups to fit a single byte.");
static_assert(sizeof(ProfilerMemory::Groups) == sizeof(uint8), "Fix memory profiler groups to fit a single byte.");
// Compact name storage.
struct GroupNameBuffer
@@ -32,17 +33,17 @@ struct GroupNameBuffer
void Set(const T* str, bool autoFormat = false)
{
int32 max = StringUtils::Length(str), dst = 0;
char prev = 0;
T prev = 0;
for (int32 i = 0; i < max && dst < ARRAY_COUNT(Buffer) - 2; i++)
{
char cur = (char)str[i];
T cur = (T)str[i];
if (autoFormat && StringUtils::IsUpper(cur) && StringUtils::IsLower(prev))
{
Ansi[dst] = '/';
Buffer[dst++] = '/';
}
Ansi[dst] = cur;
Buffer[dst++] = cur;
Ansi[dst] = (char)cur;
Buffer[dst++] = (Char)cur;
prev = cur;
}
Buffer[dst] = 0;
@@ -257,6 +258,8 @@ void InitProfilerMemory(const Char* cmdLine, int32 stage)
INIT_PARENT(Animations, AnimationsData);
INIT_PARENT(Content, ContentAssets);
INIT_PARENT(Content, ContentFiles);
INIT_PARENT(Level, LevelFoliage);
INIT_PARENT(Level, LevelTerrain);
INIT_PARENT(Scripting, ScriptingVisual);
INIT_PARENT(Scripting, ScriptingCSharp);
INIT_PARENT(ScriptingCSharp, ScriptingCSharpGCCommitted);
@@ -403,10 +406,10 @@ ProfilerMemory::GroupsArray ProfilerMemory::GetGroups(int32 mode)
void ProfilerMemory::Dump(const StringView& options)
{
#if LOG_ENABLE
bool file = options.Contains(TEXT("file"));
bool file = options.Contains(TEXT("file"), StringSearchCase::IgnoreCase);
StringBuilder output;
int32 maxCount = 20;
if (file || options.Contains(TEXT("all")))
if (file || options.Contains(TEXT("all"), StringSearchCase::IgnoreCase))
maxCount = MAX_int32;
::Dump(output, maxCount);
if (file)
@@ -476,10 +479,10 @@ void ProfilerMemory::OnMemoryFree(void* ptr)
stack.SkipRecursion = false;
}
void ProfilerMemory::OnGroupUpdate(Groups group, int64 sizeDelta, int64 countDetla)
void ProfilerMemory::OnGroupUpdate(Groups group, int64 sizeDelta, int64 countDelta)
{
Platform::InterlockedAdd(&GroupMemory[(int32)group], sizeDelta);
Platform::InterlockedAdd(&GroupMemoryCount[(int32)group], countDetla);
Platform::InterlockedAdd(&GroupMemoryCount[(int32)group], countDelta);
UPDATE_PEEK(group);
}

View File

@@ -61,7 +61,7 @@ public:
GraphicsVertexBuffers,
// Total index buffers memory usage.
GraphicsIndexBuffers,
// Total meshes memory usage (vertex and idnex buffers allocated by models).
// Total meshes memory usage (vertex and index buffers allocated by models).
GraphicsMeshes,
// Totoal shaders memory usage (shaders bytecode, PSOs data).
GraphicsShaders,
@@ -78,7 +78,7 @@ public:
// Total animation data memory usage (curves, events, keyframes, graphs, etc.).
AnimationsData,
// Total autio system memory.
// Total audio system memory.
Audio,
// Total content system memory usage.
@@ -90,11 +90,15 @@ public:
// Total memory used by content streaming system (internals).
ContentStreaming,
// Total memory allocated by input system.
Input,
// Total memory allocated by scene objects.
Level,
// Total memory allocated by the foliage system (quad-tree, foliage instances data). Excluding foliage models data.
LevelFoliage,
// Total memory allocated by the terrain system (patches).
LevelTerrain,
// Total memory allocated by input system.
Input,
// Total localization system memory.
Localization,
@@ -148,7 +152,7 @@ public:
CustomGame8,
// Custom game-specific memory tracking.
CustomGame9,
// Custom plugin-specific memory tracking.
CustomPlugin0,
// Custom plugin-specific memory tracking.
@@ -186,7 +190,7 @@ public:
};
/// <summary>
/// The memory groups array wraper to avoid dynamic memory allocation.
/// The memory groups array wrapper to avoid dynamic memory allocation.
/// </summary>
API_STRUCT(NoDefault) struct GroupsArray
{
@@ -254,7 +258,7 @@ public:
static void OnMemoryAlloc(void* ptr, uint64 size);
static void OnMemoryFree(void* ptr);
static void OnGroupUpdate(Groups group, int64 sizeDelta, int64 countDetla);
static void OnGroupUpdate(Groups group, int64 sizeDelta, int64 countDelta);
public:
/// <summary>