2017-09-12 22:42:36 +02:00
<?xml version="1.0" encoding="UTF-8" ?>
2022-02-14 14:18:53 +01:00
<class name= "Performance" inherits= "Object" version= "4.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation= "../class.xsd" >
2017-09-12 22:42:36 +02:00
<brief_description >
2019-06-26 15:57:13 +02:00
Exposes performance-related data.
2017-09-12 22:42:36 +02:00
</brief_description>
<description >
2019-06-22 01:04:47 +02:00
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 [b]Monitor[/b] tab in the editor's [b]Debugger[/b] panel. By using the [method get_monitor] method of this class, you can access this data from your code.
2020-06-04 15:18:57 +02:00
You can add custom monitors using the [method add_custom_monitor] method. Custom monitors are available in [b]Monitor[/b] tab in the editor's [b]Debugger[/b] panel together with built-in monitors.
2022-05-15 20:43:07 +02:00
[b]Note:[/b] Some of the built-in monitors are only available in debug mode and will always return [code]0[/code] when used in a project exported in release mode.
[b]Note:[/b] 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.
2020-06-04 15:18:57 +02:00
[b]Note:[/b] Custom monitors do not support negative values. Negative values are clamped to 0.
2017-09-12 22:42:36 +02:00
</description>
<tutorials >
</tutorials>
<methods >
2020-06-04 15:18:57 +02:00
<method name= "add_custom_monitor" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "id" type= "StringName" />
<param index= "1" name= "callable" type= "Callable" />
<param index= "2" name= "arguments" type= "Array" default= "[]" />
2020-06-04 15:18:57 +02:00
<description >
2022-05-15 20:43:07 +02:00
Adds a custom monitor with the name [code]id[/code]. You can specify the category of the monitor using slash delimiters in [code]id[/code] (for example: [code]"Game/NumberOfNPCs"[/code]). If there is more than one slash delimiter, then the default category is used. The default category is [code]"Custom"[/code]. Prints an error if given [code]id[/code] is already present.
2020-10-31 18:54:17 +01:00
[codeblocks]
[gdscript]
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".
2022-05-15 20:43:07 +02:00
# Note: "MyCategory/MyMonitor" and "MyMonitor" have same name but different IDs, so the code is valid.
2020-10-31 18:54:17 +01:00
Performance.add_custom_monitor("MyMonitor", monitor_value)
# Adds monitor with name "MyName" to category "Custom".
2022-05-15 20:43:07 +02:00
# Note: "MyMonitor" and "Custom/MyMonitor" have same name and same category but different IDs, so the code is valid.
2020-10-31 18:54:17 +01:00
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
[/gdscript]
[csharp]
public override void _Ready()
{
var monitorValue = new Callable(this, nameof(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;
}
[/csharp]
[/codeblocks]
2022-05-15 20:43:07 +02:00
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.
2020-06-04 15:18:57 +02:00
Callables are called with arguments supplied in argument array.
</description>
</method>
<method name= "get_custom_monitor" >
2021-07-30 15:28:05 +02:00
<return type= "Variant" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "id" type= "StringName" />
2020-06-04 15:18:57 +02:00
<description >
2022-05-15 20:43:07 +02:00
Returns the value of custom monitor with given [code]id[/code]. The callable is called to get the value of custom monitor. See also [method has_custom_monitor]. Prints an error if the given [code]id[/code] is absent.
2020-06-04 15:18:57 +02:00
</description>
</method>
<method name= "get_custom_monitor_names" >
2021-07-30 15:28:05 +02:00
<return type= "Array" />
2020-06-04 15:18:57 +02:00
<description >
2022-05-15 20:43:07 +02:00
Returns the names of active custom monitors in an [Array].
2020-06-04 15:18:57 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
<method name= "get_monitor" qualifiers= "const" >
2021-07-30 15:28:05 +02:00
<return type= "float" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "monitor" type= "int" enum= "Performance.Monitor" />
2017-09-12 22:42:36 +02:00
<description >
2022-05-15 20:43:07 +02:00
Returns the value of one of the available built-in monitors. You should provide one of the [enum Monitor] constants as the argument, like this:
2020-10-31 18:54:17 +01:00
[codeblocks]
[gdscript]
print(Performance.get_monitor(Performance.TIME_FPS)) # Prints the FPS to the console.
[/gdscript]
[csharp]
GD.Print(Performance.GetMonitor(Performance.Monitor.TimeFps)); // Prints the FPS to the console.
[/csharp]
[/codeblocks]
2022-05-15 20:43:07 +02:00
See [method get_custom_monitor] to query custom performance monitors' values.
2017-09-12 22:42:36 +02:00
</description>
</method>
2020-06-04 15:18:57 +02:00
<method name= "get_monitor_modification_time" >
2021-07-30 15:28:05 +02:00
<return type= "int" />
2020-06-04 15:18:57 +02:00
<description >
2022-05-15 20:43:07 +02:00
Returns the last tick in which custom monitor was added/removed (in microseconds since the engine started). This is set to [method Time.get_ticks_usec] when the monitor is updated.
2020-06-04 15:18:57 +02:00
</description>
</method>
<method name= "has_custom_monitor" >
2021-07-30 15:28:05 +02:00
<return type= "bool" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "id" type= "StringName" />
2020-06-04 15:18:57 +02:00
<description >
2022-05-15 20:43:07 +02:00
Returns [code]true[/code] if custom monitor with the given [code]id[/code] is present, [code]false[/code] otherwise.
2020-06-04 15:18:57 +02:00
</description>
</method>
<method name= "remove_custom_monitor" >
2021-07-30 15:28:05 +02:00
<return type= "void" />
2022-08-06 20:11:48 +02:00
<param index= "0" name= "id" type= "StringName" />
2020-06-04 15:18:57 +02:00
<description >
2022-05-15 20:43:07 +02:00
Removes the custom monitor with given [code]id[/code]. Prints an error if the given [code]id[/code] is already absent.
2020-06-04 15:18:57 +02:00
</description>
</method>
2017-09-12 22:42:36 +02:00
</methods>
<constants >
2017-11-24 23:16:30 +01:00
<constant name= "TIME_FPS" value= "0" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
The number of frames rendered in the last second. This metric is only updated once per second, even if queried more often. [i]Higher is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2017-11-24 23:16:30 +01:00
<constant name= "TIME_PROCESS" value= "1" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Time it took to complete one frame, in seconds. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2017-11-24 23:16:30 +01:00
<constant name= "TIME_PHYSICS_PROCESS" value= "2" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Time it took to complete one physics frame, in seconds. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2017-11-24 23:16:30 +01:00
<constant name= "MEMORY_STATIC" value= "3" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Static memory currently used, in bytes. Not available in release builds. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2020-02-18 13:59:24 +01:00
<constant name= "MEMORY_STATIC_MAX" value= "4" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Available static memory. Not available in release builds. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2020-02-18 13:59:24 +01:00
<constant name= "MEMORY_MESSAGE_BUFFER_MAX" value= "5" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Largest amount of memory the message queue buffer has used, in bytes. The message queue is used for deferred functions calls and notifications. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2020-02-18 13:59:24 +01:00
<constant name= "OBJECT_COUNT" value= "6" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of objects currently instantiated (including nodes). [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2020-02-18 13:59:24 +01:00
<constant name= "OBJECT_RESOURCE_COUNT" value= "7" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of resources currently used. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2020-02-18 13:59:24 +01:00
<constant name= "OBJECT_NODE_COUNT" value= "8" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of nodes currently instantiated in the scene tree. This also includes the root node. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2020-02-18 13:59:24 +01:00
<constant name= "OBJECT_ORPHAN_NODE_COUNT" value= "9" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of orphan nodes, i.e. nodes which are not parented to a node of the scene tree. [i]Lower is better.[/i]
2019-04-17 22:46:21 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "RENDER_TOTAL_OBJECTS_IN_FRAME" value= "10" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
The total number of objects in the last rendered frame. This metric doesn't include culled objects (either via hiding nodes, frustum culling or occlusion culling). [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "RENDER_TOTAL_PRIMITIVES_IN_FRAME" value= "11" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
The total number of vertices or indices rendered in the last rendered frame. This metric doesn't include primitives from culled objects (either via hiding nodes, frustum culling or occlusion culling). Due to the depth prepass and shadow passes, the number of primitives is always higher than the actual number of vertices in the scene (typically double or triple the original vertex count). [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "RENDER_TOTAL_DRAW_CALLS_IN_FRAME" value= "12" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
The total number of draw calls performed in the last rendered frame. This metric doesn't include culled objects (either via hiding nodes, frustum culling or occlusion culling), since they do not result in draw calls. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "RENDER_VIDEO_MEM_USED" value= "13" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
The amount of video memory used (texture and vertex memory combined, in bytes). Since this metric also includes miscellaneous allocations, this value is always greater than the sum of [constant RENDER_TEXTURE_MEM_USED] and [constant RENDER_BUFFER_MEM_USED]. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "RENDER_TEXTURE_MEM_USED" value= "14" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
The amount of texture memory used (in bytes). [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "RENDER_BUFFER_MEM_USED" value= "15" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
The amount of render buffer memory used (in bytes). [i]Lower is better.[/i]
2017-10-22 12:56:11 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "PHYSICS_2D_ACTIVE_OBJECTS" value= "16" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of active [RigidDynamicBody2D] nodes in the game. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "PHYSICS_2D_COLLISION_PAIRS" value= "17" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of collision pairs in the 2D physics engine. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "PHYSICS_2D_ISLAND_COUNT" value= "18" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of islands in the 2D physics engine. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "PHYSICS_3D_ACTIVE_OBJECTS" value= "19" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of active [RigidDynamicBody3D] and [VehicleBody3D] nodes in the game. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "PHYSICS_3D_COLLISION_PAIRS" value= "20" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of collision pairs in the 3D physics engine. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "PHYSICS_3D_ISLAND_COUNT" value= "21" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Number of islands in the 3D physics engine. [i]Lower is better.[/i]
2017-09-12 22:42:36 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "AUDIO_OUTPUT_LATENCY" value= "22" enum= "Monitor" >
2022-05-15 20:43:07 +02:00
Output latency of the [AudioServer]. [i]Lower is better.[/i]
2018-07-26 11:56:21 +02:00
</constant>
2021-07-03 01:14:19 +02:00
<constant name= "MONITOR_MAX" value= "23" enum= "Monitor" >
2019-06-26 15:57:13 +02:00
Represents the size of the [enum Monitor] enum.
2017-09-12 22:42:36 +02:00
</constant>
</constants>
</class>