Table of Contents

Class Performance

Namespace
Godot
Assembly
GodotSharp.dll

This class provides access to a number of different monitors related to performance, such as memory usage, draw calls, and FPS. These are the same as the values displayed in the Monitor tab in the editor's Debugger panel. By using the GetMonitor(Monitor) method of this class, you can access this data from your code.

You can add custom monitors using the AddCustomMonitor(StringName, Callable, Array) method. Custom monitors are available in Monitor tab in the editor's Debugger panel together with built-in monitors.

Note: Some of the built-in monitors are only available in debug mode and will always return 0 when used in a project exported in release mode.

Note: Some of the built-in monitors are not updated in real-time for performance reasons, so there may be a delay of up to 1 second between changes.

Note: Custom monitors do not support negative values. Negative values are clamped to 0.

public static class Performance
Inheritance
Performance
Inherited Members

Properties

Singleton

public static PerformanceInstance Singleton { get; }

Property Value

PerformanceInstance

Methods

AddCustomMonitor(StringName, Callable, Array)

Adds a custom monitor with the name id. You can specify the category of the monitor using slash delimiters in id (for example: "Game/NumberOfNPCs"). If there is more than one slash delimiter, then the default category is used. The default category is "Custom". Prints an error if given id is already present.

public override void _Ready()
  {
      var monitorValue = new Callable(this, MethodName.GetMonitorValue);
  // Adds monitor with name "MyName" to category "MyCategory".
  Performance.AddCustomMonitor("MyCategory/MyMonitor", monitorValue);
  // Adds monitor with name "MyName" to category "Custom".
  // Note: "MyCategory/MyMonitor" and "MyMonitor" have same name but different ids so the code is valid.
  Performance.AddCustomMonitor("MyMonitor", monitorValue);

  // Adds monitor with name "MyName" to category "Custom".
  // Note: "MyMonitor" and "Custom/MyMonitor" have same name and same category but different ids so the code is valid.
  Performance.AddCustomMonitor("Custom/MyMonitor", monitorValue);

  // Adds monitor with name "MyCategoryOne/MyCategoryTwo/MyMonitor" to category "Custom".
  Performance.AddCustomMonitor("MyCategoryOne/MyCategoryTwo/MyMonitor", monitorValue);

}

public int GetMonitorValue() { return GD.Randi() % 25; }

The debugger calls the callable to get the value of custom monitor. The callable must return a zero or positive integer or floating-point number.

Callables are called with arguments supplied in argument array.

public static void AddCustomMonitor(StringName id, Callable callable, Array arguments = null)

Parameters

id StringName
callable Callable
arguments Array

GetCustomMonitor(StringName)

Returns the value of custom monitor with given id. The callable is called to get the value of custom monitor. See also HasCustomMonitor(StringName). Prints an error if the given id is absent.

public static Variant GetCustomMonitor(StringName id)

Parameters

id StringName

Returns

Variant

GetCustomMonitorNames()

Returns the names of active custom monitors in an Array.

public static Array<StringName> GetCustomMonitorNames()

Returns

Array<StringName>

GetMonitor(Monitor)

Returns the value of one of the available built-in monitors. You should provide one of the Performance.Monitor constants as the argument, like this:

GD.Print(Performance.GetMonitor(Performance.Monitor.TimeFps)); // Prints the FPS to the console.

See GetCustomMonitor(StringName) to query custom performance monitors' values.

public static double GetMonitor(Performance.Monitor monitor)

Parameters

monitor Performance.Monitor

Returns

double

GetMonitorModificationTime()

Returns the last tick in which custom monitor was added/removed (in microseconds since the engine started). This is set to GetTicksUsec() when the monitor is updated.

public static ulong GetMonitorModificationTime()

Returns

ulong

HasCustomMonitor(StringName)

Returns true if custom monitor with the given id is present, false otherwise.

public static bool HasCustomMonitor(StringName id)

Parameters

id StringName

Returns

bool

RemoveCustomMonitor(StringName)

Removes the custom monitor with given id. Prints an error if the given id is already absent.

public static void RemoveCustomMonitor(StringName id)

Parameters

id StringName