summaryrefslogtreecommitdiff
path: root/doc/classes/Performance.xml
blob: ff73844803edf011448607b59f7a48e06d711085 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Performance" inherits="Object" version="4.0">
	<brief_description>
		Exposes performance-related data.
	</brief_description>
	<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 [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.
		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.
		[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.
		[b]Note:[/b] Many of these monitors are not updated in real-time, so there may be a short delay between changes.
		[b]Note:[/b] Custom monitors do not support negative values. Negative values are clamped to 0.
	</description>
	<tutorials>
	</tutorials>
	<methods>
		<method name="add_custom_monitor">
			<return type="void">
			</return>
			<argument index="0" name="id" type="StringName">
			</argument>
			<argument index="1" name="callable" type="Callable">
			</argument>
			<argument index="2" name="arguments" type="Array" default="[]">
			</argument>
			<description>
				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".
				[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".
				    # 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
				[/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]
				The debugger calls the callable to get the value of custom monitor. The callable must return a number.
				Callables are called with arguments supplied in argument array.
				[b]Note:[/b] It throws an error if given id is already present.
			</description>
		</method>
		<method name="get_custom_monitor">
			<return type="Variant">
			</return>
			<argument index="0" name="id" type="StringName">
			</argument>
			<description>
				Returns the value of custom monitor with given id. The callable is called to get the value of custom monitor.
				[b]Note:[/b] It throws an error if the given id is absent.
			</description>
		</method>
		<method name="get_custom_monitor_names">
			<return type="Array">
			</return>
			<description>
				Returns the names of active custom monitors in an array.
			</description>
		</method>
		<method name="get_monitor" qualifiers="const">
			<return type="float">
			</return>
			<argument index="0" name="monitor" type="int" enum="Performance.Monitor">
			</argument>
			<description>
				Returns the value of one of the available monitors. You should provide one of the [enum Monitor] constants as the argument, like this:
				[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]
			</description>
		</method>
		<method name="get_monitor_modification_time">
			<return type="int">
			</return>
			<description>
				Returns the last tick in which custom monitor was added/removed.
			</description>
		</method>
		<method name="has_custom_monitor">
			<return type="bool">
			</return>
			<argument index="0" name="id" type="StringName">
			</argument>
			<description>
				Returns true if custom monitor with the given id is present otherwise returns false.
			</description>
		</method>
		<method name="remove_custom_monitor">
			<return type="void">
			</return>
			<argument index="0" name="id" type="StringName">
			</argument>
			<description>
				Removes the custom monitor with given id.
				[b]Note:[/b] It throws an error if the given id is already absent.
			</description>
		</method>
	</methods>
	<constants>
		<constant name="TIME_FPS" value="0" enum="Monitor">
			Number of frames per second.
		</constant>
		<constant name="TIME_PROCESS" value="1" enum="Monitor">
			Time it took to complete one frame, in seconds.
		</constant>
		<constant name="TIME_PHYSICS_PROCESS" value="2" enum="Monitor">
			Time it took to complete one physics frame, in seconds.
		</constant>
		<constant name="MEMORY_STATIC" value="3" enum="Monitor">
			Static memory currently used, in bytes. Not available in release builds.
		</constant>
		<constant name="MEMORY_STATIC_MAX" value="4" enum="Monitor">
			Available static memory. Not available in release builds.
		</constant>
		<constant name="MEMORY_MESSAGE_BUFFER_MAX" value="5" enum="Monitor">
			Largest amount of memory the message queue buffer has used, in bytes. The message queue is used for deferred functions calls and notifications.
		</constant>
		<constant name="OBJECT_COUNT" value="6" enum="Monitor">
			Number of objects currently instanced (including nodes).
		</constant>
		<constant name="OBJECT_RESOURCE_COUNT" value="7" enum="Monitor">
			Number of resources currently used.
		</constant>
		<constant name="OBJECT_NODE_COUNT" value="8" enum="Monitor">
			Number of nodes currently instanced in the scene tree. This also includes the root node.
		</constant>
		<constant name="OBJECT_ORPHAN_NODE_COUNT" value="9" enum="Monitor">
			Number of orphan nodes, i.e. nodes which are not parented to a node of the scene tree.
		</constant>
		<constant name="RENDER_OBJECTS_IN_FRAME" value="10" enum="Monitor">
			3D objects drawn per frame.
		</constant>
		<constant name="RENDER_VERTICES_IN_FRAME" value="11" enum="Monitor">
			Vertices drawn per frame. 3D only.
		</constant>
		<constant name="RENDER_MATERIAL_CHANGES_IN_FRAME" value="12" enum="Monitor">
			Material changes per frame. 3D only.
		</constant>
		<constant name="RENDER_SHADER_CHANGES_IN_FRAME" value="13" enum="Monitor">
			Shader changes per frame. 3D only.
		</constant>
		<constant name="RENDER_SURFACE_CHANGES_IN_FRAME" value="14" enum="Monitor">
			Render surface changes per frame. 3D only.
		</constant>
		<constant name="RENDER_DRAW_CALLS_IN_FRAME" value="15" enum="Monitor">
			Draw calls per frame. 3D only.
		</constant>
		<constant name="RENDER_VIDEO_MEM_USED" value="16" enum="Monitor">
			The amount of video memory used, i.e. texture and vertex memory combined.
		</constant>
		<constant name="RENDER_TEXTURE_MEM_USED" value="17" enum="Monitor">
			The amount of texture memory used.
		</constant>
		<constant name="RENDER_VERTEX_MEM_USED" value="18" enum="Monitor">
			The amount of vertex memory used.
		</constant>
		<constant name="RENDER_USAGE_VIDEO_MEM_TOTAL" value="19" enum="Monitor">
			Unimplemented in the GLES2 rendering backend, always returns 0.
		</constant>
		<constant name="PHYSICS_2D_ACTIVE_OBJECTS" value="20" enum="Monitor">
			Number of active [RigidBody2D] nodes in the game.
		</constant>
		<constant name="PHYSICS_2D_COLLISION_PAIRS" value="21" enum="Monitor">
			Number of collision pairs in the 2D physics engine.
		</constant>
		<constant name="PHYSICS_2D_ISLAND_COUNT" value="22" enum="Monitor">
			Number of islands in the 2D physics engine.
		</constant>
		<constant name="PHYSICS_3D_ACTIVE_OBJECTS" value="23" enum="Monitor">
			Number of active [RigidBody3D] and [VehicleBody3D] nodes in the game.
		</constant>
		<constant name="PHYSICS_3D_COLLISION_PAIRS" value="24" enum="Monitor">
			Number of collision pairs in the 3D physics engine.
		</constant>
		<constant name="PHYSICS_3D_ISLAND_COUNT" value="25" enum="Monitor">
			Number of islands in the 3D physics engine.
		</constant>
		<constant name="AUDIO_OUTPUT_LATENCY" value="26" enum="Monitor">
			Output latency of the [AudioServer].
		</constant>
		<constant name="MONITOR_MAX" value="27" enum="Monitor">
			Represents the size of the [enum Monitor] enum.
		</constant>
	</constants>
</class>