MemReport

MemReport

#Overview

name: MemReport

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of MemReport is to provide memory usage information for Niagara systems in Unreal Engine 5. It is primarily used for debugging and performance monitoring of particle effects created with the Niagara visual effects system.

Based on the callsites provided, the MemReport variable is primarily utilized within the Niagara Editor module, specifically in the FNiagaraSystemViewportClient class. This suggests that it’s a part of the Niagara plugin, which is an advanced visual effects system in Unreal Engine 5.

The value of this variable is set and updated in the FNiagaraSystemViewportClient::DrawMemoryInfo function. It’s generated using the FNiagaraSystemMemReport::GenerateReport method, which creates a basic report of the Niagara system’s memory usage.

The MemReport variable interacts with other variables and functions within the FNiagaraSystemViewportClient class, such as MemReportLastCheckedTime, which is used to determine when to update the report.

Developers should be aware that this variable is used for debugging and performance monitoring purposes. It’s not meant to be modified directly but rather used as a tool for analyzing memory usage of Niagara systems.

Best practices when using this variable include:

  1. Regularly checking the memory report during development to ensure efficient memory usage.
  2. Using the information provided by MemReport to optimize Niagara systems that are consuming excessive memory.
  3. Being aware that generating the memory report may have some performance overhead, so it should be used judiciously in production builds.
  4. Understanding that the memory report includes various aspects of the Niagara system, including data interface memory, which is separately reported but included in the overall system memory.

Additionally, it’s worth noting that there’s a console command “MemReport” available in the engine, which suggests that memory reporting functionality exists beyond just the Niagara system and can be invoked for general engine memory analysis.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Plugins/FX/Niagara/Source/NiagaraEditor/Private/Widgets/SNiagaraSystemViewport.cpp:89

Scope (from outer to inner):

file
class        class FNiagaraSystemViewportClient : public FEditorViewportClient, public TSharedFromThis<FNiagaraSystemViewportClient>

Source code excerpt:

	bool bUpdateViewportFocus = false;

	FNiagaraSystemMemReport	MemReport;
	double					MemReportLastCheckedTime = 0.0;
};

FNiagaraSystemViewportClient::FNiagaraSystemViewportClient(FAdvancedPreviewScene& InPreviewScene, const TSharedRef<SNiagaraSystemViewport>& InNiagaraEditorViewport, FOnScreenShotCaptured InOnScreenShotCaptured)
	: FEditorViewportClient(nullptr, &InPreviewScene, StaticCastSharedRef<SEditorViewport>(InNiagaraEditorViewport))
	, AdvancedPreviewScene(&InPreviewScene)

#Loc: <Workspace>/Engine/Plugins/FX/Niagara/Source/NiagaraEditor/Private/Widgets/SNiagaraSystemViewport.cpp:498

Scope (from outer to inner):

file
function     void FNiagaraSystemViewportClient::DrawMemoryInfo

Source code excerpt:

	{
		MemReportLastCheckedTime = CurrentTime;
		MemReport.GenerateReport(FNiagaraSystemMemReport::EReportType::Basic, Component->GetAsset());
	}

	FResourceSizeEx ComponentResSize = FResourceSizeEx(EResourceSizeMode::EstimatedTotal);
	Component->GetResourceSizeEx(ComponentResSize);
	const uint64 MemComponentCost = ComponentResSize.GetTotalMemoryBytes();

#Loc: <Workspace>/Engine/Plugins/FX/Niagara/Source/NiagaraEditor/Private/Widgets/SNiagaraSystemViewport.cpp:511

Scope (from outer to inner):

file
function     void FNiagaraSystemViewportClient::DrawMemoryInfo

Source code excerpt:


	// System Mem Information
	for (const FNiagaraSystemMemReport::FNode& Node : MemReport.GetNodes())
	{
		Canvas->DrawShadowedString(
			CurrentX + (Node.Depth * 8.0f), CurrentY,
			*FString::Printf(TEXT("- %s %s = %skb (%s bytes)"), *Node.ObjectClass.ToString(), *Node.ObjectName.ToString(), *FString::FormatAsNumber(FMath::DivideAndRoundUp(uint32(Node.InclusiveSizeBytes), 1024u)), *FString::FormatAsNumber(Node.InclusiveSizeBytes)),
			Font, FLinearColor::White
		);

#Loc: <Workspace>/Engine/Plugins/FX/Niagara/Source/NiagaraEditor/Private/Widgets/SNiagaraSystemViewport.cpp:522

Scope (from outer to inner):

file
function     void FNiagaraSystemViewportClient::DrawMemoryInfo

Source code excerpt:


	// Data Interface Mem
	const uint32 DIMemory = uint32(MemReport.GetDataInterfaceSizeBytes());
	Canvas->DrawShadowedString(
		CurrentX, CurrentY,
		*FString::Printf(TEXT("- DataInterface = %skb (%s bytes) - Included In NiagaraSystem Mem"), *FString::FormatAsNumber(FMath::DivideAndRoundUp(DIMemory, 1024u)), *FString::FormatAsNumber(DIMemory)),
		Font, FLinearColor::White
	);
	CurrentY += FontHeight;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UnrealEngine.cpp:5123

Scope: file

Source code excerpt:

		return HandleListSpawnedActorsCommand( Cmd, Ar, InWorld );
	}
	else if( FParse::Command( &Cmd, TEXT("MemReport") ) )
	{
		return HandleMemReportCommand( Cmd, Ar, InWorld );
	}
	else if( FParse::Command( &Cmd, TEXT("MemReportDeferred") ) )
	{
		return HandleMemReportDeferredCommand( Cmd, Ar, InWorld );