Net.UseGranularNetworkTracking

Net.UseGranularNetworkTracking

#Overview

name: Net.UseGranularNetworkTracking

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 Net.UseGranularNetworkTracking is to enable detailed logging of network memory usage in Unreal Engine 5. This setting variable is primarily used for debugging and profiling network-related memory consumption.

This setting variable is utilized by the networking subsystem of Unreal Engine, specifically within the granular memory tracking module. Based on the callsites, it’s part of the Engine module and is used in the networking code.

The value of this variable is set through a console variable (CVar) named CVarUseGranularNetworkTracking. It’s initialized with a default value of 0, meaning it’s disabled by default. Developers can enable it by setting it to 1 through the console or configuration files.

The associated variable CVarUseGranularNetworkTracking directly interacts with Net.UseGranularNetworkTracking. They share the same value and purpose.

Developers must be aware that enabling this variable will result in more detailed memory usage information being printed out, which can be useful for debugging but may impact performance. It should be used judiciously, primarily in development or debugging scenarios rather than in production builds.

Best practices when using this variable include:

  1. Enable it only when investigating network memory issues or optimizing network memory usage.
  2. Be prepared for potential performance overhead when enabled.
  3. Use it in conjunction with other networking profiling tools for a comprehensive analysis.
  4. Remember to disable it after debugging to avoid unnecessary overhead in regular gameplay or shipping builds.

Regarding the associated variable CVarUseGranularNetworkTracking:

The purpose of CVarUseGranularNetworkTracking is to provide programmatic access to the Net.UseGranularNetworkTracking setting within the C++ code.

This variable is used in the Engine module, specifically in the networking code related to memory tracking. It’s defined in the UE::Net::Private::GranularMemoryTracking namespace.

The value of CVarUseGranularNetworkTracking is set through the console variable system, which allows it to be changed at runtime or through configuration files.

CVarUseGranularNetworkTracking directly controls the behavior of the granular network memory tracking system. It’s used in the ShouldTrackMemory function to determine whether detailed memory tracking should be performed.

Developers should be aware that accessing this variable’s value may have a slight performance cost, especially if checked frequently. The GetValueOnAnyThread() method is used to retrieve its value, which suggests it’s designed for multi-threaded access.

Best practices for using CVarUseGranularNetworkTracking include:

  1. Use it to conditionally enable or disable memory tracking in performance-sensitive code paths.
  2. Consider caching its value if it’s accessed frequently in a tight loop.
  3. Be aware of its impact on memory usage and performance when enabled.
  4. Use it in combination with other debugging tools and variables for comprehensive network profiling.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetworkGranularMemoryLogging.cpp:14

Scope (from outer to inner):

file
namespace    UE::Net::Private::GranularMemoryTracking

Source code excerpt:

{
	static TAutoConsoleVariable<int32> CVarUseGranularNetworkTracking(
		TEXT("Net.UseGranularNetworkTracking"),
		0,
		TEXT("When enabled, Obj List will print out highly detailed information about Network Memory Usage")
	);

	struct FNetworkMemoryTrackingScope
	{

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetworkGranularMemoryLogging.cpp:13

Scope (from outer to inner):

file
namespace    UE::Net::Private::GranularMemoryTracking

Source code excerpt:

namespace UE::Net::Private::GranularMemoryTracking
{
	static TAutoConsoleVariable<int32> CVarUseGranularNetworkTracking(
		TEXT("Net.UseGranularNetworkTracking"),
		0,
		TEXT("When enabled, Obj List will print out highly detailed information about Network Memory Usage")
	);

	struct FNetworkMemoryTrackingScope

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Net/NetworkGranularMemoryLogging.cpp:211

Scope (from outer to inner):

file
namespace    UE::Net::Private::GranularMemoryTracking
function     static const bool ShouldTrackMemory

Source code excerpt:

	static const bool ShouldTrackMemory(const FArchive& Ar)
	{
		return CVarUseGranularNetworkTracking.GetValueOnAnyThread() && Ar.IsCountingMemory() && FString(TEXT("FArchiveCountMem")).Equals(Ar.GetArchiveName());
	}

	FScopeMarker::FScopeMarker(FArchive& InAr, FString&& InScopeName) :
		Ar(InAr),
		ScopeName(InScopeName),
		ScopeStack(ShouldTrackMemory(Ar) ? FNetworkMemoryTrackingScopeStack::Get().Get() : nullptr)