Add Emscripten heap memory size and max limit stats to profiler

This commit is contained in:
Wojtek Figat
2026-03-16 22:29:19 +01:00
parent e10d784e83
commit 3949cba83c
5 changed files with 24 additions and 0 deletions

View File

@@ -175,6 +175,7 @@ void SDLPlatform::LogInfo()
void SDLPlatform::Tick()
{
SDLPlatformBase::Tick();
SDLInput::Update();
PreHandleEvents();

View File

@@ -14,6 +14,7 @@
#include "Engine/Platform/MemoryStats.h"
#include "Engine/Platform/MessageBox.h"
#include "Engine/Profiler/ProfilerCPU.h"
#include "Engine/Profiler/ProfilerMemory.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Engine/Web/WebGame.h"
#include "Engine/Utilities/StringConverter.h"
@@ -219,6 +220,12 @@ bool WebPlatform::Init()
if (PlatformBase::Init())
return true;
#if COMPILE_WITH_PROFILER
// Setup platform-specific memory profiler tags
ProfilerMemory::RenameGroup(ProfilerMemory::Groups::WEB_MEM_TAG_HEAP_SIZE, TEXT("Emscripten/HeapSize"));
ProfilerMemory::RenameGroup(ProfilerMemory::Groups::WEB_MEM_TAG_HEAP_MAX, TEXT("Emscripten/HeapMax"));
#endif
// Set info about the CPU
Platform::MemoryClear(&Cpu, sizeof(Cpu));
Cpu.ProcessorPackageCount = 1;
@@ -249,6 +256,10 @@ void WebPlatform::LogInfo()
void WebPlatform::Tick()
{
#if COMPILE_WITH_PROFILER
ProfilerMemory::OnGroupSet(ProfilerMemory::Groups::WEB_MEM_TAG_HEAP_SIZE, (int64)emscripten_get_heap_size(), 1);
ProfilerMemory::OnGroupSet(ProfilerMemory::Groups::WEB_MEM_TAG_HEAP_MAX, (int64)emscripten_get_heap_max(), 1);
#endif
}
void WebPlatform::Exit()

View File

@@ -9,6 +9,10 @@
#include <pthread.h>
#endif
// Platform memory profiler categories mapping
#define WEB_MEM_TAG_HEAP_SIZE CustomPlatform0
#define WEB_MEM_TAG_HEAP_MAX CustomPlatform1
/// <summary>
/// The Web platform implementation and application management utilities.
/// </summary>

View File

@@ -489,4 +489,11 @@ void ProfilerMemory::OnGroupUpdate(Groups group, int64 sizeDelta, int64 countDel
UPDATE_PEEK(group);
}
void ProfilerMemory::OnGroupSet(Groups group, int64 size, int64 count)
{
Platform::AtomicStore(&GroupMemory[(int32)group], size);
Platform::AtomicStore(&GroupMemoryCount[(int32)group], count);
UPDATE_PEEK(group);
}
#endif

View File

@@ -265,6 +265,7 @@ public:
static void OnMemoryAlloc(void* ptr, uint64 size);
static void OnMemoryFree(void* ptr);
static void OnGroupUpdate(Groups group, int64 sizeDelta, int64 countDelta);
static void OnGroupSet(Groups group, int64 size, int64 count);
public:
/// <summary>