Memory Profiling from C++

Looking to send some gameplay telemetry to an external service. One of the pieces of telemetry I want to gather is the client’s memory usage at runtime. Any advice on how to access that? Unreal has plenty of profiling functionality I’d love to tap into, but I need to do so from my C++ scripts.

When you say “C++ scripts,” do you mean that it’s a process that runs separately from the Unreal Engine game process?
If so, you will need to use the Windows WMI interface, or Process Management interfaces, both of which are part of the Win32 API.
Try for example GetProcessInformation() with the APP_MEMORY_INFORMATION structure.

On MacOS you’ll need to use the MachOS kernel interfaces, and on Linux you’ll need to use something like /proc or a wrapper library on top, which frequently needs root access.

not quite. This is a piece of c++ code running inside the game at runtime. I’m wondering if there is any way to avoid directly using OS specific APIs, since the game is multi-platform.

There’s LowLevelMemTracker.cpp.

As an example, it tracks the TaskGraphTasks:

DECLARE_LLM_MEMORY_STAT(TEXT("TaskGraph Misc Tasks"), STAT_TaskGraphTasksMiscLLM, STATGROUP_LLMFULL);

You can get access to the full tracker (where this stat, and many others live) using FLowLevelMemTracker::Get()

The functions you can call on it are declared in LowLevelMemTracker.h. For example, GetTrackedTags()

Would the built-in Memory Insights cover your use-case? You can remotely connect it to a process running on another device. Although this is mostly done for Development builds, are you perhaps instead trying to do this for shipping builds? Maybe FPlatformMemory is a better class for you to use.

1 Like

I am indeed trying to log things in a shipping build. FPlatformMemory looks very promising, but I can’t seem to find examples of how to use it. How do I get an FPlatformMemory object that has the info I need?

Most of its methods are static, you can just call them directly: FPlatformMemory::GetPhysicalGBRam();

1 Like

yes! don’t know how I missed that, thanks