vm.DetailedVMScriptStats

vm.DetailedVMScriptStats

#Overview

name: vm.DetailedVMScriptStats

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

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of vm.DetailedVMScriptStats is to control the emission of detailed statistics for internal module calls in the Vector VM (Virtual Machine) component of Unreal Engine 5. This setting variable is primarily used for performance monitoring and debugging of vector computations within the engine.

This setting variable is primarily utilized by the Vector VM subsystem and the Niagara plugin, which is part of Unreal Engine’s visual effects system. Based on the callsites, it’s clear that both the core engine (VectorVM) and the Niagara plugin rely on this variable for performance tracking and debugging purposes.

The value of this variable is set through the console variable system in Unreal Engine. It’s defined as an FAutoConsoleVariableRef, which means it can be changed at runtime through console commands or configuration files.

This variable interacts with other parts of the system, particularly within the Niagara plugin. For example, it’s used in the UNiagaraScript::GenerateStatIDs() function to determine whether to generate detailed statistics for VM script execution.

Developers should be aware that enabling this variable (setting it to a value greater than 0) will cause the Vector VM to emit more detailed statistics, which can be useful for debugging and performance analysis but may also incur some overhead. Therefore, it should be used judiciously, primarily in development and debugging scenarios rather than in production builds.

Best practices when using this variable include:

  1. Enable it only when needed for performance analysis or debugging of vector computations.
  2. Be mindful of the potential performance impact when enabled in complex scenes or on target hardware with limited resources.
  3. Use it in conjunction with other Niagara and Vector VM debugging tools for comprehensive analysis.
  4. Remember to disable it when not actively debugging to avoid unnecessary overhead in regular development or runtime scenarios.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/VectorVM/Private/VectorVM.cpp:190

Scope: file

Source code excerpt:

static int32 GbDetailedVMScriptStats = 0;
static FAutoConsoleVariableRef CVarDetailedVMScriptStats(
	TEXT("vm.DetailedVMScriptStats"),
	GbDetailedVMScriptStats,
	TEXT("If > 0 the vector VM will emit stats for it's internal module calls. \n"),
	ECVF_Default
);

static int32 GParallelVVMInstancesPerChunk = 128;

#Loc: <Workspace>/Engine/Plugins/FX/Niagara/Source/Niagara/Private/NiagaraScript.cpp:2503

Scope (from outer to inner):

file
function     void UNiagaraScript::GenerateStatIDs

Source code excerpt:

	StatNamedEvents.Empty();

	static const IConsoleVariable* CVarOptimizeVMDetailedStats = IConsoleManager::Get().FindConsoleVariable(TEXT("vm.DetailedVMScriptStats"));
	if (CVarOptimizeVMDetailedStats && CVarOptimizeVMDetailedStats->GetInt() != 0)
	{
		if (IsReadyToRun(ENiagaraSimTarget::CPUSim))
		{
			StatNamedEvents.Reserve(CachedScriptVM.StatScopes.Num());
			for (FNiagaraStatScope& StatScope : CachedScriptVM.StatScopes)

#Loc: <Workspace>/Engine/Plugins/FX/Niagara/Source/NiagaraEditor/Private/Toolkits/NiagaraSystemToolkit.cpp:72

Scope: file

Source code excerpt:

const FName FNiagaraSystemToolkit::ScalabilityModeName(TEXT("Scalability"));

IConsoleVariable* FNiagaraSystemToolkit::VmStatEnabledVar = IConsoleManager::Get().FindConsoleVariable(TEXT("vm.DetailedVMScriptStats"));

static int32 GbLogNiagaraSystemChanges = 0;
static FAutoConsoleVariableRef CVarLogNiagaraSystemChanges(
	TEXT("fx.LogNiagaraSystemChanges"),
	GbLogNiagaraSystemChanges,
	TEXT("If > 0 Niagara Systems will be written to a text format when opened and closed in the editor. \n"),

#Loc: <Workspace>/Engine/Plugins/FX/Niagara/Source/NiagaraEditorWidgets/Private/Stack/SNiagaraStackRowPerfWidget.cpp:22

Scope: file

Source code excerpt:

#define LOCTEXT_NAMESPACE "SNiagaraStackRowPerfWidget"

IConsoleVariable* SNiagaraStackRowPerfWidget::StatEnabledVar = IConsoleManager::Get().FindConsoleVariable(TEXT("vm.DetailedVMScriptStats"));

void SNiagaraStackRowPerfWidget::Construct(const FArguments& InArgs, UNiagaraStackEntry* InStackEntry)
{
	StackEntry = InStackEntry;
	SetToolTipText(CreateTooltipText());
	SetVisibility(TAttribute<EVisibility>::CreateSP(this, &SNiagaraStackRowPerfWidget::IsVisible));