123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 |
- :github_url: hide
- .. DO NOT EDIT THIS FILE!!!
- .. Generated automatically from Godot engine sources.
- .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
- .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Performance.xml.
- .. _class_Performance:
- Performance
- ===========
- **Inherits:** :ref:`Object<class_Object>`
- Exposes performance-related data.
- .. rst-class:: classref-introduction-group
- Description
- -----------
- 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 :ref:`get_monitor<class_Performance_method_get_monitor>` method of this class, you can access this data from your code.
- You can add custom monitors using the :ref:`add_custom_monitor<class_Performance_method_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.
- .. rst-class:: classref-reftable-group
- Methods
- -------
- .. table::
- :widths: auto
- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`add_custom_monitor<class_Performance_method_add_custom_monitor>` **(** :ref:`StringName<class_StringName>` id, :ref:`Callable<class_Callable>` callable, :ref:`Array<class_Array>` arguments=[] **)** |
- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Variant<class_Variant>` | :ref:`get_custom_monitor<class_Performance_method_get_custom_monitor>` **(** :ref:`StringName<class_StringName>` id **)** |
- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`StringName[]<class_StringName>` | :ref:`get_custom_monitor_names<class_Performance_method_get_custom_monitor_names>` **(** **)** |
- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`float<class_float>` | :ref:`get_monitor<class_Performance_method_get_monitor>` **(** :ref:`Monitor<enum_Performance_Monitor>` monitor **)** |const| |
- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_monitor_modification_time<class_Performance_method_get_monitor_modification_time>` **(** **)** |
- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`bool<class_bool>` | :ref:`has_custom_monitor<class_Performance_method_has_custom_monitor>` **(** :ref:`StringName<class_StringName>` id **)** |
- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`remove_custom_monitor<class_Performance_method_remove_custom_monitor>` **(** :ref:`StringName<class_StringName>` id **)** |
- +---------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Enumerations
- ------------
- .. _enum_Performance_Monitor:
- .. rst-class:: classref-enumeration
- enum **Monitor**:
- .. _class_Performance_constant_TIME_FPS:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **TIME_FPS** = ``0``
- The number of frames rendered in the last second. This metric is only updated once per second, even if queried more often. *Higher is better.*
- .. _class_Performance_constant_TIME_PROCESS:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **TIME_PROCESS** = ``1``
- Time it took to complete one frame, in seconds. *Lower is better.*
- .. _class_Performance_constant_TIME_PHYSICS_PROCESS:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **TIME_PHYSICS_PROCESS** = ``2``
- Time it took to complete one physics frame, in seconds. *Lower is better.*
- .. _class_Performance_constant_TIME_NAVIGATION_PROCESS:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **TIME_NAVIGATION_PROCESS** = ``3``
- Time it took to complete one navigation step, in seconds. This includes navigation map updates as well as agent avoidance calculations. *Lower is better.*
- .. _class_Performance_constant_MEMORY_STATIC:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **MEMORY_STATIC** = ``4``
- Static memory currently used, in bytes. Not available in release builds. *Lower is better.*
- .. _class_Performance_constant_MEMORY_STATIC_MAX:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **MEMORY_STATIC_MAX** = ``5``
- Available static memory. Not available in release builds. *Lower is better.*
- .. _class_Performance_constant_MEMORY_MESSAGE_BUFFER_MAX:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **MEMORY_MESSAGE_BUFFER_MAX** = ``6``
- Largest amount of memory the message queue buffer has used, in bytes. The message queue is used for deferred functions calls and notifications. *Lower is better.*
- .. _class_Performance_constant_OBJECT_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **OBJECT_COUNT** = ``7``
- Number of objects currently instantiated (including nodes). *Lower is better.*
- .. _class_Performance_constant_OBJECT_RESOURCE_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **OBJECT_RESOURCE_COUNT** = ``8``
- Number of resources currently used. *Lower is better.*
- .. _class_Performance_constant_OBJECT_NODE_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **OBJECT_NODE_COUNT** = ``9``
- Number of nodes currently instantiated in the scene tree. This also includes the root node. *Lower is better.*
- .. _class_Performance_constant_OBJECT_ORPHAN_NODE_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **OBJECT_ORPHAN_NODE_COUNT** = ``10``
- Number of orphan nodes, i.e. nodes which are not parented to a node of the scene tree. *Lower is better.*
- .. _class_Performance_constant_RENDER_TOTAL_OBJECTS_IN_FRAME:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **RENDER_TOTAL_OBJECTS_IN_FRAME** = ``11``
- 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). *Lower is better.*
- .. _class_Performance_constant_RENDER_TOTAL_PRIMITIVES_IN_FRAME:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **RENDER_TOTAL_PRIMITIVES_IN_FRAME** = ``12``
- 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). *Lower is better.*
- .. _class_Performance_constant_RENDER_TOTAL_DRAW_CALLS_IN_FRAME:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **RENDER_TOTAL_DRAW_CALLS_IN_FRAME** = ``13``
- 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. *Lower is better.*
- .. _class_Performance_constant_RENDER_VIDEO_MEM_USED:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **RENDER_VIDEO_MEM_USED** = ``14``
- 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 :ref:`RENDER_TEXTURE_MEM_USED<class_Performance_constant_RENDER_TEXTURE_MEM_USED>` and :ref:`RENDER_BUFFER_MEM_USED<class_Performance_constant_RENDER_BUFFER_MEM_USED>`. *Lower is better.*
- .. _class_Performance_constant_RENDER_TEXTURE_MEM_USED:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **RENDER_TEXTURE_MEM_USED** = ``15``
- The amount of texture memory used (in bytes). *Lower is better.*
- .. _class_Performance_constant_RENDER_BUFFER_MEM_USED:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **RENDER_BUFFER_MEM_USED** = ``16``
- The amount of render buffer memory used (in bytes). *Lower is better.*
- .. _class_Performance_constant_PHYSICS_2D_ACTIVE_OBJECTS:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **PHYSICS_2D_ACTIVE_OBJECTS** = ``17``
- Number of active :ref:`RigidBody2D<class_RigidBody2D>` nodes in the game. *Lower is better.*
- .. _class_Performance_constant_PHYSICS_2D_COLLISION_PAIRS:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **PHYSICS_2D_COLLISION_PAIRS** = ``18``
- Number of collision pairs in the 2D physics engine. *Lower is better.*
- .. _class_Performance_constant_PHYSICS_2D_ISLAND_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **PHYSICS_2D_ISLAND_COUNT** = ``19``
- Number of islands in the 2D physics engine. *Lower is better.*
- .. _class_Performance_constant_PHYSICS_3D_ACTIVE_OBJECTS:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **PHYSICS_3D_ACTIVE_OBJECTS** = ``20``
- Number of active :ref:`RigidBody3D<class_RigidBody3D>` and :ref:`VehicleBody3D<class_VehicleBody3D>` nodes in the game. *Lower is better.*
- .. _class_Performance_constant_PHYSICS_3D_COLLISION_PAIRS:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **PHYSICS_3D_COLLISION_PAIRS** = ``21``
- Number of collision pairs in the 3D physics engine. *Lower is better.*
- .. _class_Performance_constant_PHYSICS_3D_ISLAND_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **PHYSICS_3D_ISLAND_COUNT** = ``22``
- Number of islands in the 3D physics engine. *Lower is better.*
- .. _class_Performance_constant_AUDIO_OUTPUT_LATENCY:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **AUDIO_OUTPUT_LATENCY** = ``23``
- Output latency of the :ref:`AudioServer<class_AudioServer>`. Equivalent to calling :ref:`AudioServer.get_output_latency<class_AudioServer_method_get_output_latency>`, it is not recommended to call this every frame.
- .. _class_Performance_constant_NAVIGATION_ACTIVE_MAPS:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **NAVIGATION_ACTIVE_MAPS** = ``24``
- Number of active navigation maps in the :ref:`NavigationServer3D<class_NavigationServer3D>`. This also includes the two empty default navigation maps created by World2D and World3D.
- .. _class_Performance_constant_NAVIGATION_REGION_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **NAVIGATION_REGION_COUNT** = ``25``
- Number of active navigation regions in the :ref:`NavigationServer3D<class_NavigationServer3D>`.
- .. _class_Performance_constant_NAVIGATION_AGENT_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **NAVIGATION_AGENT_COUNT** = ``26``
- Number of active navigation agents processing avoidance in the :ref:`NavigationServer3D<class_NavigationServer3D>`.
- .. _class_Performance_constant_NAVIGATION_LINK_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **NAVIGATION_LINK_COUNT** = ``27``
- Number of active navigation links in the :ref:`NavigationServer3D<class_NavigationServer3D>`.
- .. _class_Performance_constant_NAVIGATION_POLYGON_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **NAVIGATION_POLYGON_COUNT** = ``28``
- Number of navigation mesh polygons in the :ref:`NavigationServer3D<class_NavigationServer3D>`.
- .. _class_Performance_constant_NAVIGATION_EDGE_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **NAVIGATION_EDGE_COUNT** = ``29``
- Number of navigation mesh polygon edges in the :ref:`NavigationServer3D<class_NavigationServer3D>`.
- .. _class_Performance_constant_NAVIGATION_EDGE_MERGE_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **NAVIGATION_EDGE_MERGE_COUNT** = ``30``
- Number of navigation mesh polygon edges that were merged due to edge key overlap in the :ref:`NavigationServer3D<class_NavigationServer3D>`.
- .. _class_Performance_constant_NAVIGATION_EDGE_CONNECTION_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **NAVIGATION_EDGE_CONNECTION_COUNT** = ``31``
- Number of polygon edges that are considered connected by edge proximity :ref:`NavigationServer3D<class_NavigationServer3D>`.
- .. _class_Performance_constant_NAVIGATION_EDGE_FREE_COUNT:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **NAVIGATION_EDGE_FREE_COUNT** = ``32``
- Number of navigation mesh polygon edges that could not be merged in the :ref:`NavigationServer3D<class_NavigationServer3D>`. The edges still may be connected by edge proximity or with links.
- .. _class_Performance_constant_MONITOR_MAX:
- .. rst-class:: classref-enumeration-constant
- :ref:`Monitor<enum_Performance_Monitor>` **MONITOR_MAX** = ``33``
- Represents the size of the :ref:`Monitor<enum_Performance_Monitor>` enum.
- .. rst-class:: classref-section-separator
- ----
- .. rst-class:: classref-descriptions-group
- Method Descriptions
- -------------------
- .. _class_Performance_method_add_custom_monitor:
- .. rst-class:: classref-method
- void **add_custom_monitor** **(** :ref:`StringName<class_StringName>` id, :ref:`Callable<class_Callable>` callable, :ref:`Array<class_Array>` arguments=[] **)**
- 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.
- .. tabs::
- .. code-tab:: 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".
- # 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
- .. code-tab:: csharp
- 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.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Performance_method_get_custom_monitor:
- .. rst-class:: classref-method
- :ref:`Variant<class_Variant>` **get_custom_monitor** **(** :ref:`StringName<class_StringName>` id **)**
- Returns the value of custom monitor with given ``id``. The callable is called to get the value of custom monitor. See also :ref:`has_custom_monitor<class_Performance_method_has_custom_monitor>`. Prints an error if the given ``id`` is absent.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Performance_method_get_custom_monitor_names:
- .. rst-class:: classref-method
- :ref:`StringName[]<class_StringName>` **get_custom_monitor_names** **(** **)**
- Returns the names of active custom monitors in an :ref:`Array<class_Array>`.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Performance_method_get_monitor:
- .. rst-class:: classref-method
- :ref:`float<class_float>` **get_monitor** **(** :ref:`Monitor<enum_Performance_Monitor>` monitor **)** |const|
- Returns the value of one of the available built-in monitors. You should provide one of the :ref:`Monitor<enum_Performance_Monitor>` constants as the argument, like this:
- .. tabs::
- .. code-tab:: gdscript
- print(Performance.get_monitor(Performance.TIME_FPS)) # Prints the FPS to the console.
- .. code-tab:: csharp
- GD.Print(Performance.GetMonitor(Performance.Monitor.TimeFps)); // Prints the FPS to the console.
- See :ref:`get_custom_monitor<class_Performance_method_get_custom_monitor>` to query custom performance monitors' values.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Performance_method_get_monitor_modification_time:
- .. rst-class:: classref-method
- :ref:`int<class_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 :ref:`Time.get_ticks_usec<class_Time_method_get_ticks_usec>` when the monitor is updated.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Performance_method_has_custom_monitor:
- .. rst-class:: classref-method
- :ref:`bool<class_bool>` **has_custom_monitor** **(** :ref:`StringName<class_StringName>` id **)**
- Returns ``true`` if custom monitor with the given ``id`` is present, ``false`` otherwise.
- .. rst-class:: classref-item-separator
- ----
- .. _class_Performance_method_remove_custom_monitor:
- .. rst-class:: classref-method
- void **remove_custom_monitor** **(** :ref:`StringName<class_StringName>` id **)**
- Removes the custom monitor with given ``id``. Prints an error if the given ``id`` is already absent.
- .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
- .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
- .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
- .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
- .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
- .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
|