LogGameThreadMallocChurn.StackIgnore

LogGameThreadMallocChurn.StackIgnore

#Overview

name: LogGameThreadMallocChurn.StackIgnore

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of LogGameThreadMallocChurn.StackIgnore is to control the number of items to discard from the top of a stack frame when logging game thread memory allocation churn. This setting is part of Unreal Engine’s memory profiling and debugging system.

This setting variable is primarily used in the engine’s core runtime, specifically in the LaunchEngineLoop module. It’s part of a broader system that tracks and logs memory allocation patterns on the game thread.

The value of this variable is set using a TAutoConsoleVariable, which means it can be adjusted at runtime through console commands. Its default value is 2, indicating that by default, the top two items of each stack frame are ignored when capturing stack traces for memory churn analysis.

This variable interacts closely with other related variables such as CVarLogGameThreadMallocChurn_RemoveAliases and CVarLogGameThreadMallocChurn_StackLen. Together, these variables control various aspects of the memory churn logging system.

Developers should be aware that adjusting this value affects the granularity of the stack traces captured during memory churn analysis. A higher value will ignore more of the top-level function calls, which might be useful for focusing on deeper, more specific parts of the call stack. However, setting it too high might obscure important information.

Best practices when using this variable include:

  1. Keeping the value low (1-3) for most debugging scenarios to capture a comprehensive view of the call stack.
  2. Increasing the value if you’re getting too much noise from high-level engine functions and want to focus on game-specific code.
  3. Using it in conjunction with other LogGameThreadMallocChurn variables for a complete picture of memory allocation patterns.

Regarding the associated variable CVarLogGameThreadMallocChurn_StackIgnore, it’s important to note that this is actually the same variable. The CVarLogGameThreadMallocChurn_StackIgnore is the C++ variable that controls the console variable LogGameThreadMallocChurn.StackIgnore. They are two representations of the same setting - one for internal C++ use and one for console command use.

This variable is used in the CollectSample function to determine how many items to ignore when capturing stack traces. It’s retrieved using the GetValueOnGameThread() method, ensuring that the most up-to-date value is used even if it’s changed at runtime.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5412

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn_StackIgnore(
	TEXT("LogGameThreadMallocChurn.StackIgnore"),
	2,
	TEXT("Number of items to discard from the top of a stack frame."));

static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn_RemoveAliases(
	TEXT("LogGameThreadMallocChurn.RemoveAliases"),
	1,

#Associated Variable and Callsites

This variable is associated with another variable named CVarLogGameThreadMallocChurn_StackIgnore. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Launch/Private/LaunchEngineLoop.cpp:5411

Scope: file

Source code excerpt:

	TEXT("Number of allocs to skip between samples. This is used to prevent churn sampling from slowing the game down too much."));

static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn_StackIgnore(
	TEXT("LogGameThreadMallocChurn.StackIgnore"),
	2,
	TEXT("Number of items to discard from the top of a stack frame."));

static TAutoConsoleVariable<int32> CVarLogGameThreadMallocChurn_RemoveAliases(
	TEXT("LogGameThreadMallocChurn.RemoveAliases"),

#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());