Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/main/performance.cpp
9887 views
1
/**************************************************************************/
2
/* performance.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "performance.h"
32
33
#include "core/os/os.h"
34
#include "core/variant/typed_array.h"
35
#include "scene/main/node.h"
36
#include "scene/main/scene_tree.h"
37
#include "servers/audio_server.h"
38
#ifndef NAVIGATION_2D_DISABLED
39
#include "servers/navigation_server_2d.h"
40
#endif // NAVIGATION_2D_DISABLED
41
#ifndef NAVIGATION_3D_DISABLED
42
#include "servers/navigation_server_3d.h"
43
#endif // NAVIGATION_3D_DISABLED
44
#include "servers/rendering_server.h"
45
46
#ifndef PHYSICS_2D_DISABLED
47
#include "servers/physics_server_2d.h"
48
#endif // PHYSICS_2D_DISABLED
49
50
#ifndef PHYSICS_3D_DISABLED
51
#include "servers/physics_server_3d.h"
52
#endif // PHYSICS_3D_DISABLED
53
54
Performance *Performance::singleton = nullptr;
55
56
void Performance::_bind_methods() {
57
ClassDB::bind_method(D_METHOD("get_monitor", "monitor"), &Performance::get_monitor);
58
ClassDB::bind_method(D_METHOD("add_custom_monitor", "id", "callable", "arguments"), &Performance::add_custom_monitor, DEFVAL(Array()));
59
ClassDB::bind_method(D_METHOD("remove_custom_monitor", "id"), &Performance::remove_custom_monitor);
60
ClassDB::bind_method(D_METHOD("has_custom_monitor", "id"), &Performance::has_custom_monitor);
61
ClassDB::bind_method(D_METHOD("get_custom_monitor", "id"), &Performance::get_custom_monitor);
62
ClassDB::bind_method(D_METHOD("get_monitor_modification_time"), &Performance::get_monitor_modification_time);
63
ClassDB::bind_method(D_METHOD("get_custom_monitor_names"), &Performance::get_custom_monitor_names);
64
65
BIND_ENUM_CONSTANT(TIME_FPS);
66
BIND_ENUM_CONSTANT(TIME_PROCESS);
67
BIND_ENUM_CONSTANT(TIME_PHYSICS_PROCESS);
68
BIND_ENUM_CONSTANT(TIME_NAVIGATION_PROCESS);
69
BIND_ENUM_CONSTANT(MEMORY_STATIC);
70
BIND_ENUM_CONSTANT(MEMORY_STATIC_MAX);
71
BIND_ENUM_CONSTANT(MEMORY_MESSAGE_BUFFER_MAX);
72
BIND_ENUM_CONSTANT(OBJECT_COUNT);
73
BIND_ENUM_CONSTANT(OBJECT_RESOURCE_COUNT);
74
BIND_ENUM_CONSTANT(OBJECT_NODE_COUNT);
75
BIND_ENUM_CONSTANT(OBJECT_ORPHAN_NODE_COUNT);
76
BIND_ENUM_CONSTANT(RENDER_TOTAL_OBJECTS_IN_FRAME);
77
BIND_ENUM_CONSTANT(RENDER_TOTAL_PRIMITIVES_IN_FRAME);
78
BIND_ENUM_CONSTANT(RENDER_TOTAL_DRAW_CALLS_IN_FRAME);
79
BIND_ENUM_CONSTANT(RENDER_VIDEO_MEM_USED);
80
BIND_ENUM_CONSTANT(RENDER_TEXTURE_MEM_USED);
81
BIND_ENUM_CONSTANT(RENDER_BUFFER_MEM_USED);
82
BIND_ENUM_CONSTANT(PHYSICS_2D_ACTIVE_OBJECTS);
83
BIND_ENUM_CONSTANT(PHYSICS_2D_COLLISION_PAIRS);
84
BIND_ENUM_CONSTANT(PHYSICS_2D_ISLAND_COUNT);
85
#ifndef _3D_DISABLED
86
BIND_ENUM_CONSTANT(PHYSICS_3D_ACTIVE_OBJECTS);
87
BIND_ENUM_CONSTANT(PHYSICS_3D_COLLISION_PAIRS);
88
BIND_ENUM_CONSTANT(PHYSICS_3D_ISLAND_COUNT);
89
#endif // _3D_DISABLED
90
BIND_ENUM_CONSTANT(AUDIO_OUTPUT_LATENCY);
91
#if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
92
BIND_ENUM_CONSTANT(NAVIGATION_ACTIVE_MAPS);
93
BIND_ENUM_CONSTANT(NAVIGATION_REGION_COUNT);
94
BIND_ENUM_CONSTANT(NAVIGATION_AGENT_COUNT);
95
BIND_ENUM_CONSTANT(NAVIGATION_LINK_COUNT);
96
BIND_ENUM_CONSTANT(NAVIGATION_POLYGON_COUNT);
97
BIND_ENUM_CONSTANT(NAVIGATION_EDGE_COUNT);
98
BIND_ENUM_CONSTANT(NAVIGATION_EDGE_MERGE_COUNT);
99
BIND_ENUM_CONSTANT(NAVIGATION_EDGE_CONNECTION_COUNT);
100
BIND_ENUM_CONSTANT(NAVIGATION_EDGE_FREE_COUNT);
101
BIND_ENUM_CONSTANT(NAVIGATION_OBSTACLE_COUNT);
102
#endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
103
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_CANVAS);
104
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_MESH);
105
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_SURFACE);
106
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_DRAW);
107
BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_SPECIALIZATION);
108
#ifndef NAVIGATION_2D_DISABLED
109
BIND_ENUM_CONSTANT(NAVIGATION_2D_ACTIVE_MAPS);
110
BIND_ENUM_CONSTANT(NAVIGATION_2D_REGION_COUNT);
111
BIND_ENUM_CONSTANT(NAVIGATION_2D_AGENT_COUNT);
112
BIND_ENUM_CONSTANT(NAVIGATION_2D_LINK_COUNT);
113
BIND_ENUM_CONSTANT(NAVIGATION_2D_POLYGON_COUNT);
114
BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_COUNT);
115
BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_MERGE_COUNT);
116
BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_CONNECTION_COUNT);
117
BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_FREE_COUNT);
118
BIND_ENUM_CONSTANT(NAVIGATION_2D_OBSTACLE_COUNT);
119
#endif // NAVIGATION_2D_DISABLED
120
#ifndef NAVIGATION_3D_DISABLED
121
BIND_ENUM_CONSTANT(NAVIGATION_3D_ACTIVE_MAPS);
122
BIND_ENUM_CONSTANT(NAVIGATION_3D_REGION_COUNT);
123
BIND_ENUM_CONSTANT(NAVIGATION_3D_AGENT_COUNT);
124
BIND_ENUM_CONSTANT(NAVIGATION_3D_LINK_COUNT);
125
BIND_ENUM_CONSTANT(NAVIGATION_3D_POLYGON_COUNT);
126
BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_COUNT);
127
BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_MERGE_COUNT);
128
BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_CONNECTION_COUNT);
129
BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_FREE_COUNT);
130
BIND_ENUM_CONSTANT(NAVIGATION_3D_OBSTACLE_COUNT);
131
#endif // NAVIGATION_3D_DISABLED
132
BIND_ENUM_CONSTANT(MONITOR_MAX);
133
}
134
135
int Performance::_get_node_count() const {
136
MainLoop *ml = OS::get_singleton()->get_main_loop();
137
SceneTree *sml = Object::cast_to<SceneTree>(ml);
138
if (!sml) {
139
return 0;
140
}
141
return sml->get_node_count();
142
}
143
144
String Performance::get_monitor_name(Monitor p_monitor) const {
145
ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, String());
146
static const char *names[MONITOR_MAX] = {
147
PNAME("time/fps"),
148
PNAME("time/process"),
149
PNAME("time/physics_process"),
150
PNAME("time/navigation_process"),
151
PNAME("memory/static"),
152
PNAME("memory/static_max"),
153
PNAME("memory/msg_buf_max"),
154
PNAME("object/objects"),
155
PNAME("object/resources"),
156
PNAME("object/nodes"),
157
PNAME("object/orphan_nodes"),
158
PNAME("raster/total_objects_drawn"),
159
PNAME("raster/total_primitives_drawn"),
160
PNAME("raster/total_draw_calls"),
161
PNAME("video/video_mem"),
162
PNAME("video/texture_mem"),
163
PNAME("video/buffer_mem"),
164
PNAME("physics_2d/active_objects"),
165
PNAME("physics_2d/collision_pairs"),
166
PNAME("physics_2d/islands"),
167
PNAME("physics_3d/active_objects"),
168
PNAME("physics_3d/collision_pairs"),
169
PNAME("physics_3d/islands"),
170
PNAME("audio/driver/output_latency"),
171
#if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
172
PNAME("navigation/active_maps"),
173
PNAME("navigation/regions"),
174
PNAME("navigation/agents"),
175
PNAME("navigation/links"),
176
PNAME("navigation/polygons"),
177
PNAME("navigation/edges"),
178
PNAME("navigation/edges_merged"),
179
PNAME("navigation/edges_connected"),
180
PNAME("navigation/edges_free"),
181
PNAME("navigation/obstacles"),
182
#endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
183
PNAME("pipeline/compilations_canvas"),
184
PNAME("pipeline/compilations_mesh"),
185
PNAME("pipeline/compilations_surface"),
186
PNAME("pipeline/compilations_draw"),
187
PNAME("pipeline/compilations_specialization"),
188
#ifndef NAVIGATION_2D_DISABLED
189
PNAME("navigation_2d/active_maps"),
190
PNAME("navigation_2d/regions"),
191
PNAME("navigation_2d/agents"),
192
PNAME("navigation_2d/links"),
193
PNAME("navigation_2d/polygons"),
194
PNAME("navigation_2d/edges"),
195
PNAME("navigation_2d/edges_merged"),
196
PNAME("navigation_2d/edges_connected"),
197
PNAME("navigation_2d/edges_free"),
198
PNAME("navigation_2d/obstacles"),
199
#endif // NAVIGATION_2D_DISABLED
200
#ifndef NAVIGATION_3D_DISABLED
201
PNAME("navigation_3d/active_maps"),
202
PNAME("navigation_3d/regions"),
203
PNAME("navigation_3d/agents"),
204
PNAME("navigation_3d/links"),
205
PNAME("navigation_3d/polygons"),
206
PNAME("navigation_3d/edges"),
207
PNAME("navigation_3d/edges_merged"),
208
PNAME("navigation_3d/edges_connected"),
209
PNAME("navigation_3d/edges_free"),
210
PNAME("navigation_3d/obstacles"),
211
#endif // NAVIGATION_3D_DISABLED
212
};
213
static_assert(std::size(names) == MONITOR_MAX);
214
215
return names[p_monitor];
216
}
217
218
double Performance::get_monitor(Monitor p_monitor) const {
219
int info = 0;
220
221
switch (p_monitor) {
222
case TIME_FPS:
223
return Engine::get_singleton()->get_frames_per_second();
224
case TIME_PROCESS:
225
return _process_time;
226
case TIME_PHYSICS_PROCESS:
227
return _physics_process_time;
228
case TIME_NAVIGATION_PROCESS:
229
return _navigation_process_time;
230
case MEMORY_STATIC:
231
return Memory::get_mem_usage();
232
case MEMORY_STATIC_MAX:
233
return Memory::get_mem_max_usage();
234
case MEMORY_MESSAGE_BUFFER_MAX:
235
return MessageQueue::get_singleton()->get_max_buffer_usage();
236
case OBJECT_COUNT:
237
return ObjectDB::get_object_count();
238
case OBJECT_RESOURCE_COUNT:
239
return ResourceCache::get_cached_resource_count();
240
case OBJECT_NODE_COUNT:
241
return _get_node_count();
242
case OBJECT_ORPHAN_NODE_COUNT:
243
return Node::orphan_node_count;
244
case RENDER_TOTAL_OBJECTS_IN_FRAME:
245
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME);
246
case RENDER_TOTAL_PRIMITIVES_IN_FRAME:
247
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME);
248
case RENDER_TOTAL_DRAW_CALLS_IN_FRAME:
249
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME);
250
case RENDER_VIDEO_MEM_USED:
251
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_VIDEO_MEM_USED);
252
case RENDER_TEXTURE_MEM_USED:
253
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TEXTURE_MEM_USED);
254
case RENDER_BUFFER_MEM_USED:
255
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_BUFFER_MEM_USED);
256
case PIPELINE_COMPILATIONS_CANVAS:
257
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_CANVAS);
258
case PIPELINE_COMPILATIONS_MESH:
259
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_MESH);
260
case PIPELINE_COMPILATIONS_SURFACE:
261
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_SURFACE);
262
case PIPELINE_COMPILATIONS_DRAW:
263
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_DRAW);
264
case PIPELINE_COMPILATIONS_SPECIALIZATION:
265
return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_SPECIALIZATION);
266
#ifndef PHYSICS_2D_DISABLED
267
case PHYSICS_2D_ACTIVE_OBJECTS:
268
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ACTIVE_OBJECTS);
269
case PHYSICS_2D_COLLISION_PAIRS:
270
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS);
271
case PHYSICS_2D_ISLAND_COUNT:
272
return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ISLAND_COUNT);
273
#else
274
case PHYSICS_2D_ACTIVE_OBJECTS:
275
return 0;
276
case PHYSICS_2D_COLLISION_PAIRS:
277
return 0;
278
case PHYSICS_2D_ISLAND_COUNT:
279
return 0;
280
#endif // PHYSICS_2D_DISABLED
281
#ifndef PHYSICS_3D_DISABLED
282
case PHYSICS_3D_ACTIVE_OBJECTS:
283
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ACTIVE_OBJECTS);
284
case PHYSICS_3D_COLLISION_PAIRS:
285
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_COLLISION_PAIRS);
286
case PHYSICS_3D_ISLAND_COUNT:
287
return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ISLAND_COUNT);
288
#else
289
case PHYSICS_3D_ACTIVE_OBJECTS:
290
return 0;
291
case PHYSICS_3D_COLLISION_PAIRS:
292
return 0;
293
case PHYSICS_3D_ISLAND_COUNT:
294
return 0;
295
#endif // PHYSICS_3D_DISABLED
296
297
case AUDIO_OUTPUT_LATENCY:
298
return AudioServer::get_singleton()->get_output_latency();
299
300
case NAVIGATION_ACTIVE_MAPS:
301
#ifndef NAVIGATION_2D_DISABLED
302
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_ACTIVE_MAPS);
303
#endif // NAVIGATION_2D_DISABLED
304
#ifndef NAVIGATION_3D_DISABLED
305
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_ACTIVE_MAPS);
306
#endif // NAVIGATION_3D_DISABLED
307
return info;
308
309
case NAVIGATION_REGION_COUNT:
310
#ifndef NAVIGATION_2D_DISABLED
311
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_REGION_COUNT);
312
#endif // NAVIGATION_2D_DISABLED
313
#ifndef NAVIGATION_3D_DISABLED
314
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_REGION_COUNT);
315
#endif // NAVIGATION_3D_DISABLED
316
return info;
317
318
case NAVIGATION_AGENT_COUNT:
319
#ifndef NAVIGATION_2D_DISABLED
320
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_AGENT_COUNT);
321
#endif // NAVIGATION_2D_DISABLED
322
#ifndef NAVIGATION_3D_DISABLED
323
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_AGENT_COUNT);
324
#endif // NAVIGATION_3D_DISABLED
325
return info;
326
327
case NAVIGATION_LINK_COUNT:
328
#ifndef NAVIGATION_2D_DISABLED
329
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_LINK_COUNT);
330
#endif // NAVIGATION_2D_DISABLED
331
#ifndef NAVIGATION_3D_DISABLED
332
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_LINK_COUNT);
333
#endif // NAVIGATION_3D_DISABLED
334
return info;
335
336
case NAVIGATION_POLYGON_COUNT:
337
#ifndef NAVIGATION_2D_DISABLED
338
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_POLYGON_COUNT);
339
#endif // NAVIGATION_2D_DISABLED
340
#ifndef NAVIGATION_3D_DISABLED
341
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_POLYGON_COUNT);
342
#endif // NAVIGATION_3D_DISABLED
343
return info;
344
345
case NAVIGATION_EDGE_COUNT:
346
#ifndef NAVIGATION_2D_DISABLED
347
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_COUNT);
348
#endif // NAVIGATION_2D_DISABLED
349
#ifndef NAVIGATION_3D_DISABLED
350
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_COUNT);
351
#endif // NAVIGATION_3D_DISABLED
352
return info;
353
354
case NAVIGATION_EDGE_MERGE_COUNT:
355
#ifndef NAVIGATION_2D_DISABLED
356
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_MERGE_COUNT);
357
#endif // NAVIGATION_2D_DISABLED
358
#ifndef NAVIGATION_3D_DISABLED
359
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_MERGE_COUNT);
360
#endif // NAVIGATION_3D_DISABLED
361
return info;
362
363
case NAVIGATION_EDGE_CONNECTION_COUNT:
364
#ifndef NAVIGATION_2D_DISABLED
365
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_CONNECTION_COUNT);
366
#endif // NAVIGATION_2D_DISABLED
367
#ifndef NAVIGATION_3D_DISABLED
368
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT);
369
#endif // NAVIGATION_3D_DISABLED
370
return info;
371
372
case NAVIGATION_EDGE_FREE_COUNT:
373
#ifndef NAVIGATION_2D_DISABLED
374
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_FREE_COUNT);
375
#endif // NAVIGATION_2D_DISABLED
376
#ifndef NAVIGATION_3D_DISABLED
377
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT);
378
#endif // NAVIGATION_3D_DISABLED
379
return info;
380
381
case NAVIGATION_OBSTACLE_COUNT:
382
#ifndef NAVIGATION_2D_DISABLED
383
info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_OBSTACLE_COUNT);
384
#endif // NAVIGATION_2D_DISABLED
385
#ifndef NAVIGATION_3D_DISABLED
386
info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_OBSTACLE_COUNT);
387
#endif // NAVIGATION_3D_DISABLED
388
return info;
389
390
#ifndef NAVIGATION_2D_DISABLED
391
case NAVIGATION_2D_ACTIVE_MAPS:
392
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_ACTIVE_MAPS);
393
case NAVIGATION_2D_REGION_COUNT:
394
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_REGION_COUNT);
395
case NAVIGATION_2D_AGENT_COUNT:
396
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_AGENT_COUNT);
397
case NAVIGATION_2D_LINK_COUNT:
398
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_LINK_COUNT);
399
case NAVIGATION_2D_POLYGON_COUNT:
400
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_POLYGON_COUNT);
401
case NAVIGATION_2D_EDGE_COUNT:
402
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_COUNT);
403
case NAVIGATION_2D_EDGE_MERGE_COUNT:
404
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_MERGE_COUNT);
405
case NAVIGATION_2D_EDGE_CONNECTION_COUNT:
406
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_CONNECTION_COUNT);
407
case NAVIGATION_2D_EDGE_FREE_COUNT:
408
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_FREE_COUNT);
409
case NAVIGATION_2D_OBSTACLE_COUNT:
410
return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_OBSTACLE_COUNT);
411
#endif // NAVIGATION_2D_DISABLED
412
413
#ifndef NAVIGATION_3D_DISABLED
414
case NAVIGATION_3D_ACTIVE_MAPS:
415
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_ACTIVE_MAPS);
416
case NAVIGATION_3D_REGION_COUNT:
417
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_REGION_COUNT);
418
case NAVIGATION_3D_AGENT_COUNT:
419
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_AGENT_COUNT);
420
case NAVIGATION_3D_LINK_COUNT:
421
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_LINK_COUNT);
422
case NAVIGATION_3D_POLYGON_COUNT:
423
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_POLYGON_COUNT);
424
case NAVIGATION_3D_EDGE_COUNT:
425
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_COUNT);
426
case NAVIGATION_3D_EDGE_MERGE_COUNT:
427
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_MERGE_COUNT);
428
case NAVIGATION_3D_EDGE_CONNECTION_COUNT:
429
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT);
430
case NAVIGATION_3D_EDGE_FREE_COUNT:
431
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT);
432
case NAVIGATION_3D_OBSTACLE_COUNT:
433
return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_OBSTACLE_COUNT);
434
#endif // NAVIGATION_3D_DISABLED
435
436
default: {
437
}
438
}
439
440
return 0;
441
}
442
443
Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const {
444
ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, MONITOR_TYPE_QUANTITY);
445
// ugly
446
static const MonitorType types[MONITOR_MAX] = {
447
MONITOR_TYPE_QUANTITY,
448
MONITOR_TYPE_TIME,
449
MONITOR_TYPE_TIME,
450
MONITOR_TYPE_TIME,
451
MONITOR_TYPE_MEMORY,
452
MONITOR_TYPE_MEMORY,
453
MONITOR_TYPE_MEMORY,
454
MONITOR_TYPE_QUANTITY,
455
MONITOR_TYPE_QUANTITY,
456
MONITOR_TYPE_QUANTITY,
457
MONITOR_TYPE_QUANTITY,
458
MONITOR_TYPE_QUANTITY,
459
MONITOR_TYPE_QUANTITY,
460
MONITOR_TYPE_QUANTITY,
461
MONITOR_TYPE_MEMORY,
462
MONITOR_TYPE_MEMORY,
463
MONITOR_TYPE_MEMORY,
464
MONITOR_TYPE_QUANTITY,
465
MONITOR_TYPE_QUANTITY,
466
MONITOR_TYPE_QUANTITY,
467
MONITOR_TYPE_QUANTITY,
468
MONITOR_TYPE_QUANTITY,
469
MONITOR_TYPE_QUANTITY,
470
MONITOR_TYPE_TIME,
471
MONITOR_TYPE_QUANTITY,
472
MONITOR_TYPE_QUANTITY,
473
MONITOR_TYPE_QUANTITY,
474
MONITOR_TYPE_QUANTITY,
475
MONITOR_TYPE_QUANTITY,
476
MONITOR_TYPE_QUANTITY,
477
MONITOR_TYPE_QUANTITY,
478
MONITOR_TYPE_QUANTITY,
479
MONITOR_TYPE_QUANTITY,
480
MONITOR_TYPE_QUANTITY,
481
MONITOR_TYPE_QUANTITY,
482
MONITOR_TYPE_QUANTITY,
483
MONITOR_TYPE_QUANTITY,
484
MONITOR_TYPE_QUANTITY,
485
MONITOR_TYPE_QUANTITY,
486
MONITOR_TYPE_QUANTITY,
487
MONITOR_TYPE_QUANTITY,
488
MONITOR_TYPE_QUANTITY,
489
MONITOR_TYPE_QUANTITY,
490
MONITOR_TYPE_QUANTITY,
491
MONITOR_TYPE_QUANTITY,
492
MONITOR_TYPE_QUANTITY,
493
MONITOR_TYPE_QUANTITY,
494
MONITOR_TYPE_QUANTITY,
495
MONITOR_TYPE_QUANTITY,
496
MONITOR_TYPE_QUANTITY,
497
MONITOR_TYPE_QUANTITY,
498
MONITOR_TYPE_QUANTITY,
499
MONITOR_TYPE_QUANTITY,
500
MONITOR_TYPE_QUANTITY,
501
MONITOR_TYPE_QUANTITY,
502
MONITOR_TYPE_QUANTITY,
503
MONITOR_TYPE_QUANTITY,
504
MONITOR_TYPE_QUANTITY,
505
MONITOR_TYPE_QUANTITY,
506
507
};
508
static_assert((sizeof(types) / sizeof(MonitorType)) == MONITOR_MAX);
509
510
return types[p_monitor];
511
}
512
513
void Performance::set_process_time(double p_pt) {
514
_process_time = p_pt;
515
}
516
517
void Performance::set_physics_process_time(double p_pt) {
518
_physics_process_time = p_pt;
519
}
520
521
void Performance::set_navigation_process_time(double p_pt) {
522
_navigation_process_time = p_pt;
523
}
524
525
void Performance::add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args) {
526
ERR_FAIL_COND_MSG(has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' already exists.");
527
_monitor_map.insert(p_id, MonitorCall(p_callable, p_args));
528
_monitor_modification_time = OS::get_singleton()->get_ticks_usec();
529
}
530
531
void Performance::remove_custom_monitor(const StringName &p_id) {
532
ERR_FAIL_COND_MSG(!has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' doesn't exist.");
533
_monitor_map.erase(p_id);
534
_monitor_modification_time = OS::get_singleton()->get_ticks_usec();
535
}
536
537
bool Performance::has_custom_monitor(const StringName &p_id) {
538
return _monitor_map.has(p_id);
539
}
540
541
Variant Performance::get_custom_monitor(const StringName &p_id) {
542
ERR_FAIL_COND_V_MSG(!has_custom_monitor(p_id), Variant(), "Custom monitor with id '" + String(p_id) + "' doesn't exist.");
543
bool error;
544
String error_message;
545
Variant return_value = _monitor_map[p_id].call(error, error_message);
546
ERR_FAIL_COND_V_MSG(error, return_value, "Error calling from custom monitor '" + String(p_id) + "' to callable: " + error_message);
547
return return_value;
548
}
549
550
TypedArray<StringName> Performance::get_custom_monitor_names() {
551
if (!_monitor_map.size()) {
552
return TypedArray<StringName>();
553
}
554
TypedArray<StringName> return_array;
555
return_array.resize(_monitor_map.size());
556
int index = 0;
557
for (KeyValue<StringName, MonitorCall> i : _monitor_map) {
558
return_array.set(index, i.key);
559
index++;
560
}
561
return return_array;
562
}
563
564
uint64_t Performance::get_monitor_modification_time() {
565
return _monitor_modification_time;
566
}
567
568
Performance::Performance() {
569
_process_time = 0;
570
_physics_process_time = 0;
571
_navigation_process_time = 0;
572
_monitor_modification_time = 0;
573
singleton = this;
574
}
575
576
Performance::MonitorCall::MonitorCall(Callable p_callable, Vector<Variant> p_arguments) {
577
_callable = p_callable;
578
_arguments = p_arguments;
579
}
580
581
Performance::MonitorCall::MonitorCall() {
582
}
583
584
Variant Performance::MonitorCall::call(bool &r_error, String &r_error_message) {
585
Vector<const Variant *> arguments_mem;
586
arguments_mem.resize(_arguments.size());
587
for (int i = 0; i < _arguments.size(); i++) {
588
arguments_mem.write[i] = &_arguments[i];
589
}
590
const Variant **args = (const Variant **)arguments_mem.ptr();
591
int argc = _arguments.size();
592
Variant return_value;
593
Callable::CallError error;
594
_callable.callp(args, argc, return_value, error);
595
r_error = (error.error != Callable::CallError::CALL_OK);
596
if (r_error) {
597
r_error_message = Variant::get_callable_error_text(_callable, args, argc, error);
598
}
599
return return_value;
600
}
601
602