From 3949cba83cfc5df023da83057a52857497d699c4 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 16 Mar 2026 22:29:19 +0100 Subject: [PATCH] Add Emscripten heap memory size and max limit stats to profiler --- Source/Engine/Platform/SDL/SDLPlatform.cpp | 1 + Source/Engine/Platform/Web/WebPlatform.cpp | 11 +++++++++++ Source/Engine/Platform/Web/WebPlatform.h | 4 ++++ Source/Engine/Profiler/ProfilerMemory.cpp | 7 +++++++ Source/Engine/Profiler/ProfilerMemory.h | 1 + 5 files changed, 24 insertions(+) diff --git a/Source/Engine/Platform/SDL/SDLPlatform.cpp b/Source/Engine/Platform/SDL/SDLPlatform.cpp index 3517fe7e7..9d21be1fa 100644 --- a/Source/Engine/Platform/SDL/SDLPlatform.cpp +++ b/Source/Engine/Platform/SDL/SDLPlatform.cpp @@ -175,6 +175,7 @@ void SDLPlatform::LogInfo() void SDLPlatform::Tick() { + SDLPlatformBase::Tick(); SDLInput::Update(); PreHandleEvents(); diff --git a/Source/Engine/Platform/Web/WebPlatform.cpp b/Source/Engine/Platform/Web/WebPlatform.cpp index 9967dd93f..cd814af9c 100644 --- a/Source/Engine/Platform/Web/WebPlatform.cpp +++ b/Source/Engine/Platform/Web/WebPlatform.cpp @@ -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() diff --git a/Source/Engine/Platform/Web/WebPlatform.h b/Source/Engine/Platform/Web/WebPlatform.h index 4a6b85ac9..a0d17510a 100644 --- a/Source/Engine/Platform/Web/WebPlatform.h +++ b/Source/Engine/Platform/Web/WebPlatform.h @@ -9,6 +9,10 @@ #include #endif +// Platform memory profiler categories mapping +#define WEB_MEM_TAG_HEAP_SIZE CustomPlatform0 +#define WEB_MEM_TAG_HEAP_MAX CustomPlatform1 + /// /// The Web platform implementation and application management utilities. /// diff --git a/Source/Engine/Profiler/ProfilerMemory.cpp b/Source/Engine/Profiler/ProfilerMemory.cpp index 6b8f18ce3..3f9bb95d3 100644 --- a/Source/Engine/Profiler/ProfilerMemory.cpp +++ b/Source/Engine/Profiler/ProfilerMemory.cpp @@ -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 diff --git a/Source/Engine/Profiler/ProfilerMemory.h b/Source/Engine/Profiler/ProfilerMemory.h index 9177ae6e7..0f38d0802 100644 --- a/Source/Engine/Profiler/ProfilerMemory.h +++ b/Source/Engine/Profiler/ProfilerMemory.h @@ -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: ///