Performance.xml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="Performance" inherits="Object" version="4.0">
  3. <brief_description>
  4. Exposes performance-related data.
  5. </brief_description>
  6. <description>
  7. 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.
  8. 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.
  9. [b]Note:[/b] A few of these monitors are only available in debug mode and will always return 0 when used in a release build.
  10. [b]Note:[/b] Many of these monitors are not updated in real-time, so there may be a short delay between changes.
  11. [b]Note:[/b] Custom monitors do not support negative values. Negative values are clamped to 0.
  12. </description>
  13. <tutorials>
  14. </tutorials>
  15. <methods>
  16. <method name="add_custom_monitor">
  17. <return type="void" />
  18. <argument index="0" name="id" type="StringName" />
  19. <argument index="1" name="callable" type="Callable" />
  20. <argument index="2" name="arguments" type="Array" default="[]" />
  21. <description>
  22. Adds a custom monitor with name same as id. You can specify the category of monitor using '/' in id. If there are more than one '/' then default category is used. Default category is "Custom".
  23. [codeblocks]
  24. [gdscript]
  25. func _ready():
  26. var monitor_value = Callable(self, "get_monitor_value")
  27. # Adds monitor with name "MyName" to category "MyCategory".
  28. Performance.add_custom_monitor("MyCategory/MyMonitor", monitor_value)
  29. # Adds monitor with name "MyName" to category "Custom".
  30. # Note: "MyCategory/MyMonitor" and "MyMonitor" have same name but different ids so the code is valid.
  31. Performance.add_custom_monitor("MyMonitor", monitor_value)
  32. # Adds monitor with name "MyName" to category "Custom".
  33. # Note: "MyMonitor" and "Custom/MyMonitor" have same name and same category but different ids so the code is valid.
  34. Performance.add_custom_monitor("Custom/MyMonitor", monitor_value)
  35. # Adds monitor with name "MyCategoryOne/MyCategoryTwo/MyMonitor" to category "Custom".
  36. Performance.add_custom_monitor("MyCategoryOne/MyCategoryTwo/MyMonitor", monitor_value)
  37. func get_monitor_value():
  38. return randi() % 25
  39. [/gdscript]
  40. [csharp]
  41. public override void _Ready()
  42. {
  43. var monitorValue = new Callable(this, nameof(GetMonitorValue));
  44. // Adds monitor with name "MyName" to category "MyCategory".
  45. Performance.AddCustomMonitor("MyCategory/MyMonitor", monitorValue);
  46. // Adds monitor with name "MyName" to category "Custom".
  47. // Note: "MyCategory/MyMonitor" and "MyMonitor" have same name but different ids so the code is valid.
  48. Performance.AddCustomMonitor("MyMonitor", monitorValue);
  49. // Adds monitor with name "MyName" to category "Custom".
  50. // Note: "MyMonitor" and "Custom/MyMonitor" have same name and same category but different ids so the code is valid.
  51. Performance.AddCustomMonitor("Custom/MyMonitor", monitorValue);
  52. // Adds monitor with name "MyCategoryOne/MyCategoryTwo/MyMonitor" to category "Custom".
  53. Performance.AddCustomMonitor("MyCategoryOne/MyCategoryTwo/MyMonitor", monitorValue);
  54. }
  55. public int GetMonitorValue()
  56. {
  57. return GD.Randi() % 25;
  58. }
  59. [/csharp]
  60. [/codeblocks]
  61. The debugger calls the callable to get the value of custom monitor. The callable must return a number.
  62. Callables are called with arguments supplied in argument array.
  63. [b]Note:[/b] It throws an error if given id is already present.
  64. </description>
  65. </method>
  66. <method name="get_custom_monitor">
  67. <return type="Variant" />
  68. <argument index="0" name="id" type="StringName" />
  69. <description>
  70. Returns the value of custom monitor with given id. The callable is called to get the value of custom monitor.
  71. [b]Note:[/b] It throws an error if the given id is absent.
  72. </description>
  73. </method>
  74. <method name="get_custom_monitor_names">
  75. <return type="Array" />
  76. <description>
  77. Returns the names of active custom monitors in an array.
  78. </description>
  79. </method>
  80. <method name="get_monitor" qualifiers="const">
  81. <return type="float" />
  82. <argument index="0" name="monitor" type="int" enum="Performance.Monitor" />
  83. <description>
  84. Returns the value of one of the available monitors. You should provide one of the [enum Monitor] constants as the argument, like this:
  85. [codeblocks]
  86. [gdscript]
  87. print(Performance.get_monitor(Performance.TIME_FPS)) # Prints the FPS to the console.
  88. [/gdscript]
  89. [csharp]
  90. GD.Print(Performance.GetMonitor(Performance.Monitor.TimeFps)); // Prints the FPS to the console.
  91. [/csharp]
  92. [/codeblocks]
  93. </description>
  94. </method>
  95. <method name="get_monitor_modification_time">
  96. <return type="int" />
  97. <description>
  98. Returns the last tick in which custom monitor was added/removed.
  99. </description>
  100. </method>
  101. <method name="has_custom_monitor">
  102. <return type="bool" />
  103. <argument index="0" name="id" type="StringName" />
  104. <description>
  105. Returns true if custom monitor with the given id is present otherwise returns false.
  106. </description>
  107. </method>
  108. <method name="remove_custom_monitor">
  109. <return type="void" />
  110. <argument index="0" name="id" type="StringName" />
  111. <description>
  112. Removes the custom monitor with given id.
  113. [b]Note:[/b] It throws an error if the given id is already absent.
  114. </description>
  115. </method>
  116. </methods>
  117. <constants>
  118. <constant name="TIME_FPS" value="0" enum="Monitor">
  119. Number of frames per second.
  120. </constant>
  121. <constant name="TIME_PROCESS" value="1" enum="Monitor">
  122. Time it took to complete one frame, in seconds.
  123. </constant>
  124. <constant name="TIME_PHYSICS_PROCESS" value="2" enum="Monitor">
  125. Time it took to complete one physics frame, in seconds.
  126. </constant>
  127. <constant name="MEMORY_STATIC" value="3" enum="Monitor">
  128. Static memory currently used, in bytes. Not available in release builds.
  129. </constant>
  130. <constant name="MEMORY_STATIC_MAX" value="4" enum="Monitor">
  131. Available static memory. Not available in release builds.
  132. </constant>
  133. <constant name="MEMORY_MESSAGE_BUFFER_MAX" value="5" enum="Monitor">
  134. Largest amount of memory the message queue buffer has used, in bytes. The message queue is used for deferred functions calls and notifications.
  135. </constant>
  136. <constant name="OBJECT_COUNT" value="6" enum="Monitor">
  137. Number of objects currently instantiated (including nodes).
  138. </constant>
  139. <constant name="OBJECT_RESOURCE_COUNT" value="7" enum="Monitor">
  140. Number of resources currently used.
  141. </constant>
  142. <constant name="OBJECT_NODE_COUNT" value="8" enum="Monitor">
  143. Number of nodes currently instantiated in the scene tree. This also includes the root node.
  144. </constant>
  145. <constant name="OBJECT_ORPHAN_NODE_COUNT" value="9" enum="Monitor">
  146. Number of orphan nodes, i.e. nodes which are not parented to a node of the scene tree.
  147. </constant>
  148. <constant name="RENDER_TOTAL_OBJECTS_IN_FRAME" value="10" enum="Monitor">
  149. </constant>
  150. <constant name="RENDER_TOTAL_PRIMITIVES_IN_FRAME" value="11" enum="Monitor">
  151. </constant>
  152. <constant name="RENDER_TOTAL_DRAW_CALLS_IN_FRAME" value="12" enum="Monitor">
  153. </constant>
  154. <constant name="RENDER_VIDEO_MEM_USED" value="13" enum="Monitor">
  155. The amount of video memory used, i.e. texture and vertex memory combined.
  156. </constant>
  157. <constant name="RENDER_TEXTURE_MEM_USED" value="14" enum="Monitor">
  158. The amount of texture memory used.
  159. </constant>
  160. <constant name="RENDER_BUFFER_MEM_USED" value="15" enum="Monitor">
  161. </constant>
  162. <constant name="PHYSICS_2D_ACTIVE_OBJECTS" value="16" enum="Monitor">
  163. Number of active [RigidDynamicBody2D] nodes in the game.
  164. </constant>
  165. <constant name="PHYSICS_2D_COLLISION_PAIRS" value="17" enum="Monitor">
  166. Number of collision pairs in the 2D physics engine.
  167. </constant>
  168. <constant name="PHYSICS_2D_ISLAND_COUNT" value="18" enum="Monitor">
  169. Number of islands in the 2D physics engine.
  170. </constant>
  171. <constant name="PHYSICS_3D_ACTIVE_OBJECTS" value="19" enum="Monitor">
  172. Number of active [RigidDynamicBody3D] and [VehicleBody3D] nodes in the game.
  173. </constant>
  174. <constant name="PHYSICS_3D_COLLISION_PAIRS" value="20" enum="Monitor">
  175. Number of collision pairs in the 3D physics engine.
  176. </constant>
  177. <constant name="PHYSICS_3D_ISLAND_COUNT" value="21" enum="Monitor">
  178. Number of islands in the 3D physics engine.
  179. </constant>
  180. <constant name="AUDIO_OUTPUT_LATENCY" value="22" enum="Monitor">
  181. Output latency of the [AudioServer].
  182. </constant>
  183. <constant name="MONITOR_MAX" value="23" enum="Monitor">
  184. Represents the size of the [enum Monitor] enum.
  185. </constant>
  186. </constants>
  187. </class>