LogGameThreadMallocChurn.Enable
LogGameThreadMallocChurn.Enable
#Overview
name: LogGameThreadMallocChurn.Enable
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If > 0, then collect sample game thread malloc, realloc and free, periodically print a report of the worst offenders.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of LogGameThreadMallocChurn.Enable is to enable logging and analysis of memory allocation churn on the game thread. It is used to identify and track memory allocation, reallocation, and deallocation operations that may be causing performance issues or excessive memory usage.
This setting variable is primarily used in the Unreal Engine’s core runtime system, specifically in the LaunchEngineLoop module. It is part of the engine’s performance profiling and debugging toolkit.
The value of this variable is set through the console variable system. It is defined as a TAutoConsoleVariable with a default value of 0, which means it is disabled by default. Developers can enable it by setting it to a value greater than 0 through the console or configuration files.
The associated variable CVarLogGameThreadMallocChurn directly interacts with LogGameThreadMallocChurn.Enable. They share the same value and purpose. CVarLogGameThreadMallocChurn is used in the code to check if the feature is enabled and to control the behavior of the FScopedSampleMallocChurn class.
Developers must be aware that enabling this feature may have a performance impact, as it involves sampling and logging memory operations. It should primarily be used for debugging and profiling purposes, not in production builds.
Best practices when using this variable include:
- Enable it only when investigating memory-related issues or performance problems.
- Use it in conjunction with other memory profiling tools for a comprehensive analysis.
- Be mindful of the potential performance overhead when enabled.
- Adjust the related CVarLogGameThreadMallocChurn_PrintFrequency and CVarLogGameThreadMallocChurn_SampleFrequency variables to fine-tune the logging behavior.
Regarding the associated variable CVarLogGameThreadMallocChurn:
- Its purpose is the same as LogGameThreadMallocChurn.Enable, serving as the actual console variable that controls the feature.
- It is used directly in the engine code to check if the memory churn logging is enabled.
- The value is set through the console variable system, initialized with the same parameters as LogGameThreadMallocChurn.Enable.
- It interacts with other related variables like CVarLogGameThreadMallocChurn_PrintFrequency and CVarLogGameThreadMallocChurn_SampleFrequency to control the behavior of the memory churn logging feature.
- Developers should treat it as the primary control point for this feature, using it to enable or disable the memory churn logging as needed.
- Best practices for CVarLogGameThreadMallocChurn are the same as those for LogGameThreadMallocChurn.Enable, as they are essentially the same variable with different access methods.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5392
Scope: file
Source code excerpt:
#include "Containers/StackTracker.h"
static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn(
TEXT("LogGameThreadMallocChurn.Enable"),
0,
TEXT("If > 0, then collect sample game thread malloc, realloc and free, periodically print a report of the worst offenders."));
static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn_PrintFrequency(
TEXT("LogGameThreadMallocChurn.PrintFrequency"),
300,
#Associated Variable and Callsites
This variable is associated with another variable named CVarLogGameThreadMallocChurn
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5391
Scope: file
Source code excerpt:
#include "Containers/StackTracker.h"
static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn(
TEXT("LogGameThreadMallocChurn.Enable"),
0,
TEXT("If > 0, then collect sample game thread malloc, realloc and free, periodically print a report of the worst offenders."));
static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn_PrintFrequency(
TEXT("LogGameThreadMallocChurn.PrintFrequency"),
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5439
Scope (from outer to inner):
file
function FScopedSampleMallocChurn
Source code excerpt:
FScopedSampleMallocChurn()
: bEnabled(CVarLogGameThreadMallocChurn.GetValueOnGameThread() > 0)
, CountDown(CVarLogGameThreadMallocChurn_SampleFrequency.GetValueOnGameThread())
, Hook(
[this](int32 Index)
{
if (--CountDown <= 0)
{