LogGameThreadMallocChurn.Enable

LogGameThreadMallocChurn.Enable

#Overview

name: LogGameThreadMallocChurn.Enable

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.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:

  1. Enable it only when investigating memory-related issues or performance problems.
  2. Use it in conjunction with other memory profiling tools for a comprehensive analysis.
  3. Be mindful of the potential performance overhead when enabled.
  4. Adjust the related CVarLogGameThreadMallocChurn_PrintFrequency and CVarLogGameThreadMallocChurn_SampleFrequency variables to fine-tune the logging behavior.

Regarding the associated variable CVarLogGameThreadMallocChurn:

#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)
		{