Table of Contents

Class Performance

Exposes performance-related data.

Inheritance
Performance

Remarks

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 Performance.get_monitor method of this class, you can access this data from your code.

You can add custom monitors using the Performance.add_custom_monitor 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.

Methods

add_custom_monitor(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.

func _ready():
    var monitor_value = Callable(self, "get_monitor_value")

    # Adds monitor with name "MyName" to category "MyCategory".
    Performance.add_custom_monitor("MyCategory/MyMonitor", monitor_value)

    # 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.add_custom_monitor("MyMonitor", monitor_value)

    # 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.add_custom_monitor("Custom/MyMonitor", monitor_value)

    # Adds monitor with name "MyCategoryOne/MyCategoryTwo/MyMonitor" to category "Custom".
    Performance.add_custom_monitor("MyCategoryOne/MyCategoryTwo/MyMonitor", monitor_value)

func get_monitor_value():
    return 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.

void add_custom_monitor(StringName id, Callable callable, Array arguments)

Parameters

id StringName
callable Callable
arguments Array

get_custom_monitor(StringName)

Returns the value of custom monitor with given id. The callable is called to get the value of custom monitor. See also Performance.has_custom_monitor. Prints an error if the given id is absent.

Variant get_custom_monitor(StringName id)

Parameters

id StringName

get_custom_monitor_names

Returns the names of active custom monitors in an Array.

StringName[] get_custom_monitor_names

get_monitor(int)

Qualifiers: const

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

print(Performance.get_monitor(Performance.TIME_FPS)) # Prints the FPS to the console.

See Performance.get_custom_monitor to query custom performance monitors' values.

float get_monitor(int monitor)

Parameters

monitor int

get_monitor_modification_time

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

int get_monitor_modification_time

has_custom_monitor(StringName)

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

bool has_custom_monitor(StringName id)

Parameters

id StringName

remove_custom_monitor(StringName)

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

void remove_custom_monitor(StringName id)

Parameters

id StringName