LogGameThreadMallocChurn.StackLen
LogGameThreadMallocChurn.StackLen
#Overview
name: LogGameThreadMallocChurn.StackLen
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Maximum number of stack frame items to keep. This improves aggregation because calls that originate from multiple places but end up in the same place will be accounted together.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of LogGameThreadMallocChurn.StackLen is to control the maximum number of stack frame items to keep when tracking memory allocations (malloc churn) on the game thread. This setting is primarily used for performance profiling and debugging memory-related issues in Unreal Engine.
This setting variable is part of the core engine’s memory profiling system, specifically focusing on the game thread’s memory allocation patterns. It is used in the LaunchEngineLoop module, which is a critical part of the engine’s startup and main loop processes.
The value of this variable is set through a console variable (CVar) system, which allows it to be changed at runtime. It’s initialized with a default value of 3, but can be modified through console commands or configuration files.
The associated variable CVarLogGameThreadMallocChurn_StackLen directly interacts with LogGameThreadMallocChurn.StackLen. They share the same value and purpose.
Developers should be aware that:
- Increasing this value will provide more detailed stack traces but may increase memory overhead and potentially impact performance during profiling.
- Decreasing this value will reduce the granularity of the stack traces but may improve performance and reduce memory usage during profiling.
Best practices when using this variable include:
- Adjust the value based on the level of detail needed for debugging. Start with the default value and increase if more detailed stack traces are required.
- Be mindful of performance implications when setting this to a high value, especially in performance-critical scenarios.
- Use in conjunction with other LogGameThreadMallocChurn settings for comprehensive memory churn analysis.
Regarding the associated variable CVarLogGameThreadMallocChurn_StackLen:
- It serves the same purpose as LogGameThreadMallocChurn.StackLen.
- It’s used directly in the code to control the stack trace depth when capturing malloc churn data.
- It’s accessed using the GetValueOnGameThread() method, indicating that its value should only be read from the game thread for thread safety.
- Developers should use this variable name when accessing the setting programmatically within the engine code.
Both variables work together to provide a flexible way to control the depth of stack traces in memory churn analysis, allowing developers to balance between detailed profiling information and performance overhead.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5422
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn_StackLen(
TEXT("LogGameThreadMallocChurn.StackLen"),
3,
TEXT("Maximum number of stack frame items to keep. This improves aggregation because calls that originate from multiple places but end up in the same place will be accounted together."));
extern CORE_API TFunction<void(int32)>* GGameThreadMallocHook;
#Associated Variable and Callsites
This variable is associated with another variable named CVarLogGameThreadMallocChurn_StackLen
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5421
Scope: file
Source code excerpt:
TEXT("If > 0 then remove aliases from the counting process. This essentialy merges addresses that have the same human readable string. It is slower."));
static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn_StackLen(
TEXT("LogGameThreadMallocChurn.StackLen"),
3,
TEXT("Maximum number of stack frame items to keep. This improves aggregation because calls that originate from multiple places but end up in the same place will be accounted together."));
extern CORE_API TFunction<void(int32)>* GGameThreadMallocHook;
#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5494
Scope (from outer to inner):
file
function void CollectSample
Source code excerpt:
{
check(IsInGameThread());
GGameThreadMallocChurnTracker.CaptureStackTrace(CVarLogGameThreadMallocChurn_StackIgnore.GetValueOnGameThread(), nullptr, CVarLogGameThreadMallocChurn_StackLen.GetValueOnGameThread(), CVarLogGameThreadMallocChurn_RemoveAliases.GetValueOnGameThread() > 0);
}
void PrintResultsAndReset()
{
DumpFrame = GFrameCounter + CVarLogGameThreadMallocChurn_PrintFrequency.GetValueOnGameThread();
FOutputDeviceRedirector* Log = FOutputDeviceRedirector::Get();
float SampleAndFrameCorrection = float(CVarLogGameThreadMallocChurn_SampleFrequency.GetValueOnGameThread()) / float(CVarLogGameThreadMallocChurn_PrintFrequency.GetValueOnGameThread());