0.2.0-dev Download ZIP
658 lines ·26.1 KB Raw
| 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 | #include "performance.compat.inc" |
| 33 | |
| 34 | #include "core/config/engine.h" |
| 35 | #include "core/object/class_db.h" |
| 36 | #include "core/os/os.h" |
| 37 | #include "core/variant/typed_array.h" |
| 38 | #include "scene/main/node.h" |
| 39 | #include "scene/main/scene_tree.h" |
| 40 | #include "servers/audio/audio_server.h" |
| 41 | #include "servers/rendering/rendering_server.h" |
| 42 | |
| 43 | #ifndef NAVIGATION_2D_DISABLED |
| 44 | #include "servers/navigation_2d/navigation_server_2d.h" |
| 45 | #endif // NAVIGATION_2D_DISABLED |
| 46 | |
| 47 | #ifndef NAVIGATION_3D_DISABLED |
| 48 | #include "servers/navigation_3d/navigation_server_3d.h" |
| 49 | #endif // NAVIGATION_3D_DISABLED |
| 50 | |
| 51 | #ifndef PHYSICS_2D_DISABLED |
| 52 | #include "servers/physics_2d/physics_server_2d.h" |
| 53 | #endif // PHYSICS_2D_DISABLED |
| 54 | |
| 55 | #ifndef PHYSICS_3D_DISABLED |
| 56 | #include "servers/physics_3d/physics_server_3d.h" |
| 57 | #endif // PHYSICS_3D_DISABLED |
| 58 | |
| 59 | #include "modules/modules_enabled.gen.h" |
| 60 | |
| 61 | #ifdef MODULE_TEXTURE_STREAMING_ENABLED |
| 62 | #include "modules/texture_streaming/texture_streaming.h" |
| 63 | #endif |
| 64 | |
| 65 | Performance *Performance::singleton = nullptr; |
| 66 | |
| 67 | void Performance::_bind_methods() { |
| 68 | ClassDB::bind_method(D_METHOD("get_monitor", "monitor"), &Performance::get_monitor); |
| 69 | ClassDB::bind_method(D_METHOD("add_custom_monitor", "id", "callable", "arguments", "type"), &Performance::add_custom_monitor, DEFVAL(Array()), DEFVAL(MONITOR_TYPE_QUANTITY)); |
| 70 | ClassDB::bind_method(D_METHOD("remove_custom_monitor", "id"), &Performance::remove_custom_monitor); |
| 71 | ClassDB::bind_method(D_METHOD("has_custom_monitor", "id"), &Performance::has_custom_monitor); |
| 72 | ClassDB::bind_method(D_METHOD("get_custom_monitor", "id"), &Performance::get_custom_monitor); |
| 73 | ClassDB::bind_method(D_METHOD("get_monitor_modification_time"), &Performance::get_monitor_modification_time); |
| 74 | ClassDB::bind_method(D_METHOD("get_custom_monitor_names"), &Performance::get_custom_monitor_names); |
| 75 | ClassDB::bind_method(D_METHOD("get_custom_monitor_types"), &Performance::get_custom_monitor_types); |
| 76 | |
| 77 | BIND_ENUM_CONSTANT(TIME_FPS); |
| 78 | BIND_ENUM_CONSTANT(TIME_PROCESS); |
| 79 | BIND_ENUM_CONSTANT(TIME_PHYSICS_PROCESS); |
| 80 | BIND_ENUM_CONSTANT(TIME_NAVIGATION_PROCESS); |
| 81 | BIND_ENUM_CONSTANT(MEMORY_STATIC); |
| 82 | BIND_ENUM_CONSTANT(MEMORY_STATIC_MAX); |
| 83 | BIND_ENUM_CONSTANT(MEMORY_MESSAGE_BUFFER_MAX); |
| 84 | BIND_ENUM_CONSTANT(OBJECT_COUNT); |
| 85 | BIND_ENUM_CONSTANT(OBJECT_RESOURCE_COUNT); |
| 86 | BIND_ENUM_CONSTANT(OBJECT_NODE_COUNT); |
| 87 | BIND_ENUM_CONSTANT(OBJECT_ORPHAN_NODE_COUNT); |
| 88 | BIND_ENUM_CONSTANT(RENDER_TOTAL_OBJECTS_IN_FRAME); |
| 89 | BIND_ENUM_CONSTANT(RENDER_TOTAL_PRIMITIVES_IN_FRAME); |
| 90 | BIND_ENUM_CONSTANT(RENDER_TOTAL_DRAW_CALLS_IN_FRAME); |
| 91 | BIND_ENUM_CONSTANT(RENDER_VIDEO_MEM_USED); |
| 92 | BIND_ENUM_CONSTANT(RENDER_TEXTURE_MEM_USED); |
| 93 | BIND_ENUM_CONSTANT(RENDER_BUFFER_MEM_USED); |
| 94 | BIND_ENUM_CONSTANT(PHYSICS_2D_ACTIVE_OBJECTS); |
| 95 | BIND_ENUM_CONSTANT(PHYSICS_2D_COLLISION_PAIRS); |
| 96 | BIND_ENUM_CONSTANT(PHYSICS_2D_ISLAND_COUNT); |
| 97 | #ifndef _3D_DISABLED |
| 98 | BIND_ENUM_CONSTANT(PHYSICS_3D_ACTIVE_OBJECTS); |
| 99 | BIND_ENUM_CONSTANT(PHYSICS_3D_COLLISION_PAIRS); |
| 100 | BIND_ENUM_CONSTANT(PHYSICS_3D_ISLAND_COUNT); |
| 101 | #endif // _3D_DISABLED |
| 102 | BIND_ENUM_CONSTANT(AUDIO_OUTPUT_LATENCY); |
| 103 | #if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED) |
| 104 | BIND_ENUM_CONSTANT(NAVIGATION_ACTIVE_MAPS); |
| 105 | BIND_ENUM_CONSTANT(NAVIGATION_REGION_COUNT); |
| 106 | BIND_ENUM_CONSTANT(NAVIGATION_AGENT_COUNT); |
| 107 | BIND_ENUM_CONSTANT(NAVIGATION_LINK_COUNT); |
| 108 | BIND_ENUM_CONSTANT(NAVIGATION_POLYGON_COUNT); |
| 109 | BIND_ENUM_CONSTANT(NAVIGATION_EDGE_COUNT); |
| 110 | BIND_ENUM_CONSTANT(NAVIGATION_EDGE_MERGE_COUNT); |
| 111 | BIND_ENUM_CONSTANT(NAVIGATION_EDGE_CONNECTION_COUNT); |
| 112 | BIND_ENUM_CONSTANT(NAVIGATION_EDGE_FREE_COUNT); |
| 113 | BIND_ENUM_CONSTANT(NAVIGATION_OBSTACLE_COUNT); |
| 114 | #endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED) |
| 115 | BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_CANVAS); |
| 116 | BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_MESH); |
| 117 | BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_SURFACE); |
| 118 | BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_DRAW); |
| 119 | BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_SPECIALIZATION); |
| 120 | #ifndef NAVIGATION_2D_DISABLED |
| 121 | BIND_ENUM_CONSTANT(NAVIGATION_2D_ACTIVE_MAPS); |
| 122 | BIND_ENUM_CONSTANT(NAVIGATION_2D_REGION_COUNT); |
| 123 | BIND_ENUM_CONSTANT(NAVIGATION_2D_AGENT_COUNT); |
| 124 | BIND_ENUM_CONSTANT(NAVIGATION_2D_LINK_COUNT); |
| 125 | BIND_ENUM_CONSTANT(NAVIGATION_2D_POLYGON_COUNT); |
| 126 | BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_COUNT); |
| 127 | BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_MERGE_COUNT); |
| 128 | BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_CONNECTION_COUNT); |
| 129 | BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_FREE_COUNT); |
| 130 | BIND_ENUM_CONSTANT(NAVIGATION_2D_OBSTACLE_COUNT); |
| 131 | #endif // NAVIGATION_2D_DISABLED |
| 132 | #ifndef NAVIGATION_3D_DISABLED |
| 133 | BIND_ENUM_CONSTANT(NAVIGATION_3D_ACTIVE_MAPS); |
| 134 | BIND_ENUM_CONSTANT(NAVIGATION_3D_REGION_COUNT); |
| 135 | BIND_ENUM_CONSTANT(NAVIGATION_3D_AGENT_COUNT); |
| 136 | BIND_ENUM_CONSTANT(NAVIGATION_3D_LINK_COUNT); |
| 137 | BIND_ENUM_CONSTANT(NAVIGATION_3D_POLYGON_COUNT); |
| 138 | BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_COUNT); |
| 139 | BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_MERGE_COUNT); |
| 140 | BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_CONNECTION_COUNT); |
| 141 | BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_FREE_COUNT); |
| 142 | BIND_ENUM_CONSTANT(NAVIGATION_3D_OBSTACLE_COUNT); |
| 143 | #endif // NAVIGATION_3D_DISABLED |
| 144 | #ifdef MODULE_TEXTURE_STREAMING_ENABLED |
| 145 | BIND_ENUM_CONSTANT(RENDER_STREAMING_TEXTURE_MEM_USED); |
| 146 | #endif |
| 147 | BIND_ENUM_CONSTANT(MONITOR_MAX); |
| 148 | |
| 149 | BIND_ENUM_CONSTANT(MONITOR_TYPE_QUANTITY); |
| 150 | BIND_ENUM_CONSTANT(MONITOR_TYPE_MEMORY); |
| 151 | BIND_ENUM_CONSTANT(MONITOR_TYPE_TIME); |
| 152 | BIND_ENUM_CONSTANT(MONITOR_TYPE_PERCENTAGE); |
| 153 | } |
| 154 | |
| 155 | int Performance::_get_node_count() const { |
| 156 | MainLoop *ml = OS::get_singleton()->get_main_loop(); |
| 157 | SceneTree *sml = Object::cast_to<SceneTree>(ml); |
| 158 | if (!sml) { |
| 159 | return 0; |
| 160 | } |
| 161 | return sml->get_node_count(); |
| 162 | } |
| 163 | |
| 164 | int Performance::_get_orphan_node_count() const { |
| 165 | #ifdef DEBUG_ENABLED |
| 166 | const int total_node_count = Node::total_node_count.get(); |
| 167 | const int orphan_node_count = total_node_count - _get_node_count(); |
| 168 | return orphan_node_count; |
| 169 | #else |
| 170 | return 0; |
| 171 | #endif |
| 172 | } |
| 173 | |
| 174 | String Performance::get_monitor_name(Monitor p_monitor) const { |
| 175 | ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, String()); |
| 176 | static const char *names[MONITOR_MAX] = { |
| 177 | PNAME("time/fps"), |
| 178 | PNAME("time/process"), |
| 179 | PNAME("time/physics_process"), |
| 180 | PNAME("time/navigation_process"), |
| 181 | PNAME("memory/static"), |
| 182 | PNAME("memory/static_max"), |
| 183 | PNAME("memory/msg_buf_max"), |
| 184 | PNAME("object/objects"), |
| 185 | PNAME("object/resources"), |
| 186 | PNAME("object/nodes"), |
| 187 | PNAME("object/orphan_nodes"), |
| 188 | PNAME("raster/total_objects_drawn"), |
| 189 | PNAME("raster/total_primitives_drawn"), |
| 190 | PNAME("raster/total_draw_calls"), |
| 191 | PNAME("video/video_mem"), |
| 192 | PNAME("video/texture_mem"), |
| 193 | PNAME("video/buffer_mem"), |
| 194 | PNAME("physics_2d/active_objects"), |
| 195 | PNAME("physics_2d/collision_pairs"), |
| 196 | PNAME("physics_2d/islands"), |
| 197 | PNAME("physics_3d/active_objects"), |
| 198 | PNAME("physics_3d/collision_pairs"), |
| 199 | PNAME("physics_3d/islands"), |
| 200 | PNAME("audio/driver/output_latency"), |
| 201 | #if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED) |
| 202 | PNAME("navigation/active_maps"), |
| 203 | PNAME("navigation/regions"), |
| 204 | PNAME("navigation/agents"), |
| 205 | PNAME("navigation/links"), |
| 206 | PNAME("navigation/polygons"), |
| 207 | PNAME("navigation/edges"), |
| 208 | PNAME("navigation/edges_merged"), |
| 209 | PNAME("navigation/edges_connected"), |
| 210 | PNAME("navigation/edges_free"), |
| 211 | PNAME("navigation/obstacles"), |
| 212 | #endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED) |
| 213 | PNAME("pipeline/compilations_canvas"), |
| 214 | PNAME("pipeline/compilations_mesh"), |
| 215 | PNAME("pipeline/compilations_surface"), |
| 216 | PNAME("pipeline/compilations_draw"), |
| 217 | PNAME("pipeline/compilations_specialization"), |
| 218 | #ifndef NAVIGATION_2D_DISABLED |
| 219 | PNAME("navigation_2d/active_maps"), |
| 220 | PNAME("navigation_2d/regions"), |
| 221 | PNAME("navigation_2d/agents"), |
| 222 | PNAME("navigation_2d/links"), |
| 223 | PNAME("navigation_2d/polygons"), |
| 224 | PNAME("navigation_2d/edges"), |
| 225 | PNAME("navigation_2d/edges_merged"), |
| 226 | PNAME("navigation_2d/edges_connected"), |
| 227 | PNAME("navigation_2d/edges_free"), |
| 228 | PNAME("navigation_2d/obstacles"), |
| 229 | #endif // NAVIGATION_2D_DISABLED |
| 230 | #ifndef NAVIGATION_3D_DISABLED |
| 231 | PNAME("navigation_3d/active_maps"), |
| 232 | PNAME("navigation_3d/regions"), |
| 233 | PNAME("navigation_3d/agents"), |
| 234 | PNAME("navigation_3d/links"), |
| 235 | PNAME("navigation_3d/polygons"), |
| 236 | PNAME("navigation_3d/edges"), |
| 237 | PNAME("navigation_3d/edges_merged"), |
| 238 | PNAME("navigation_3d/edges_connected"), |
| 239 | PNAME("navigation_3d/edges_free"), |
| 240 | PNAME("navigation_3d/obstacles"), |
| 241 | #endif // NAVIGATION_3D_DISABLED |
| 242 | #ifdef MODULE_TEXTURE_STREAMING_ENABLED |
| 243 | PNAME("video/streaming_texture_mem_used"), |
| 244 | #endif |
| 245 | }; |
| 246 | static_assert(std_size(names) == MONITOR_MAX); |
| 247 | |
| 248 | return names[p_monitor]; |
| 249 | } |
| 250 | |
| 251 | double Performance::get_monitor(Monitor p_monitor) const { |
| 252 | int info = 0; |
| 253 | |
| 254 | switch (p_monitor) { |
| 255 | case TIME_FPS: |
| 256 | return Engine::get_singleton()->get_frames_per_second(); |
| 257 | case TIME_PROCESS: |
| 258 | return _process_time; |
| 259 | case TIME_PHYSICS_PROCESS: |
| 260 | return _physics_process_time; |
| 261 | case TIME_NAVIGATION_PROCESS: |
| 262 | return _navigation_process_time; |
| 263 | case MEMORY_STATIC: |
| 264 | return Memory::get_mem_usage(); |
| 265 | case MEMORY_STATIC_MAX: |
| 266 | return Memory::get_mem_max_usage(); |
| 267 | case MEMORY_MESSAGE_BUFFER_MAX: |
| 268 | return MessageQueue::get_singleton()->get_max_buffer_usage(); |
| 269 | case OBJECT_COUNT: |
| 270 | return ObjectDB::get_object_count(); |
| 271 | case OBJECT_RESOURCE_COUNT: |
| 272 | return ResourceCache::get_cached_resource_count(); |
| 273 | case OBJECT_NODE_COUNT: |
| 274 | return _get_node_count(); |
| 275 | case OBJECT_ORPHAN_NODE_COUNT: |
| 276 | return _get_orphan_node_count(); |
| 277 | case RENDER_TOTAL_OBJECTS_IN_FRAME: |
| 278 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME); |
| 279 | case RENDER_TOTAL_PRIMITIVES_IN_FRAME: |
| 280 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME); |
| 281 | case RENDER_TOTAL_DRAW_CALLS_IN_FRAME: |
| 282 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME); |
| 283 | case RENDER_VIDEO_MEM_USED: |
| 284 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_VIDEO_MEM_USED); |
| 285 | case RENDER_TEXTURE_MEM_USED: |
| 286 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_TEXTURE_MEM_USED); |
| 287 | case RENDER_BUFFER_MEM_USED: |
| 288 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_BUFFER_MEM_USED); |
| 289 | case PIPELINE_COMPILATIONS_CANVAS: |
| 290 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_PIPELINE_COMPILATIONS_CANVAS); |
| 291 | case PIPELINE_COMPILATIONS_MESH: |
| 292 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_PIPELINE_COMPILATIONS_MESH); |
| 293 | case PIPELINE_COMPILATIONS_SURFACE: |
| 294 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_PIPELINE_COMPILATIONS_SURFACE); |
| 295 | case PIPELINE_COMPILATIONS_DRAW: |
| 296 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_PIPELINE_COMPILATIONS_DRAW); |
| 297 | case PIPELINE_COMPILATIONS_SPECIALIZATION: |
| 298 | return RS::get_singleton()->get_rendering_info(RSE::RENDERING_INFO_PIPELINE_COMPILATIONS_SPECIALIZATION); |
| 299 | #ifndef PHYSICS_2D_DISABLED |
| 300 | case PHYSICS_2D_ACTIVE_OBJECTS: |
| 301 | return PhysicsServer2D::get_singleton()->get_process_info(PS2DE::INFO_ACTIVE_OBJECTS); |
| 302 | case PHYSICS_2D_COLLISION_PAIRS: |
| 303 | return PhysicsServer2D::get_singleton()->get_process_info(PS2DE::INFO_COLLISION_PAIRS); |
| 304 | case PHYSICS_2D_ISLAND_COUNT: |
| 305 | return PhysicsServer2D::get_singleton()->get_process_info(PS2DE::INFO_ISLAND_COUNT); |
| 306 | #else |
| 307 | case PHYSICS_2D_ACTIVE_OBJECTS: |
| 308 | return 0; |
| 309 | case PHYSICS_2D_COLLISION_PAIRS: |
| 310 | return 0; |
| 311 | case PHYSICS_2D_ISLAND_COUNT: |
| 312 | return 0; |
| 313 | #endif // PHYSICS_2D_DISABLED |
| 314 | #ifndef PHYSICS_3D_DISABLED |
| 315 | case PHYSICS_3D_ACTIVE_OBJECTS: |
| 316 | return PhysicsServer3D::get_singleton()->get_process_info(PS3DE::INFO_ACTIVE_OBJECTS); |
| 317 | case PHYSICS_3D_COLLISION_PAIRS: |
| 318 | return PhysicsServer3D::get_singleton()->get_process_info(PS3DE::INFO_COLLISION_PAIRS); |
| 319 | case PHYSICS_3D_ISLAND_COUNT: |
| 320 | return PhysicsServer3D::get_singleton()->get_process_info(PS3DE::INFO_ISLAND_COUNT); |
| 321 | #else |
| 322 | case PHYSICS_3D_ACTIVE_OBJECTS: |
| 323 | return 0; |
| 324 | case PHYSICS_3D_COLLISION_PAIRS: |
| 325 | return 0; |
| 326 | case PHYSICS_3D_ISLAND_COUNT: |
| 327 | return 0; |
| 328 | #endif // PHYSICS_3D_DISABLED |
| 329 | |
| 330 | case AUDIO_OUTPUT_LATENCY: |
| 331 | return AudioServer::get_singleton()->get_output_latency(); |
| 332 | |
| 333 | // Deprecated, use the 2D/3D specific ones instead. |
| 334 | case NAVIGATION_ACTIVE_MAPS: |
| 335 | #ifndef NAVIGATION_2D_DISABLED |
| 336 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_ACTIVE_MAPS); |
| 337 | #endif // NAVIGATION_2D_DISABLED |
| 338 | #ifndef NAVIGATION_3D_DISABLED |
| 339 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_ACTIVE_MAPS); |
| 340 | #endif // NAVIGATION_3D_DISABLED |
| 341 | return info; |
| 342 | |
| 343 | case NAVIGATION_REGION_COUNT: |
| 344 | #ifndef NAVIGATION_2D_DISABLED |
| 345 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_REGION_COUNT); |
| 346 | #endif // NAVIGATION_2D_DISABLED |
| 347 | #ifndef NAVIGATION_3D_DISABLED |
| 348 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_REGION_COUNT); |
| 349 | #endif // NAVIGATION_3D_DISABLED |
| 350 | return info; |
| 351 | |
| 352 | case NAVIGATION_AGENT_COUNT: |
| 353 | #ifndef NAVIGATION_2D_DISABLED |
| 354 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_AGENT_COUNT); |
| 355 | #endif // NAVIGATION_2D_DISABLED |
| 356 | #ifndef NAVIGATION_3D_DISABLED |
| 357 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_AGENT_COUNT); |
| 358 | #endif // NAVIGATION_3D_DISABLED |
| 359 | return info; |
| 360 | |
| 361 | case NAVIGATION_LINK_COUNT: |
| 362 | #ifndef NAVIGATION_2D_DISABLED |
| 363 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_LINK_COUNT); |
| 364 | #endif // NAVIGATION_2D_DISABLED |
| 365 | #ifndef NAVIGATION_3D_DISABLED |
| 366 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_LINK_COUNT); |
| 367 | #endif // NAVIGATION_3D_DISABLED |
| 368 | return info; |
| 369 | |
| 370 | case NAVIGATION_POLYGON_COUNT: |
| 371 | #ifndef NAVIGATION_2D_DISABLED |
| 372 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_POLYGON_COUNT); |
| 373 | #endif // NAVIGATION_2D_DISABLED |
| 374 | #ifndef NAVIGATION_3D_DISABLED |
| 375 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_POLYGON_COUNT); |
| 376 | #endif // NAVIGATION_3D_DISABLED |
| 377 | return info; |
| 378 | |
| 379 | case NAVIGATION_EDGE_COUNT: |
| 380 | #ifndef NAVIGATION_2D_DISABLED |
| 381 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_COUNT); |
| 382 | #endif // NAVIGATION_2D_DISABLED |
| 383 | #ifndef NAVIGATION_3D_DISABLED |
| 384 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_COUNT); |
| 385 | #endif // NAVIGATION_3D_DISABLED |
| 386 | return info; |
| 387 | |
| 388 | case NAVIGATION_EDGE_MERGE_COUNT: |
| 389 | #ifndef NAVIGATION_2D_DISABLED |
| 390 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_MERGE_COUNT); |
| 391 | #endif // NAVIGATION_2D_DISABLED |
| 392 | #ifndef NAVIGATION_3D_DISABLED |
| 393 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_MERGE_COUNT); |
| 394 | #endif // NAVIGATION_3D_DISABLED |
| 395 | return info; |
| 396 | |
| 397 | case NAVIGATION_EDGE_CONNECTION_COUNT: |
| 398 | #ifndef NAVIGATION_2D_DISABLED |
| 399 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_CONNECTION_COUNT); |
| 400 | #endif // NAVIGATION_2D_DISABLED |
| 401 | #ifndef NAVIGATION_3D_DISABLED |
| 402 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT); |
| 403 | #endif // NAVIGATION_3D_DISABLED |
| 404 | return info; |
| 405 | |
| 406 | case NAVIGATION_EDGE_FREE_COUNT: |
| 407 | #ifndef NAVIGATION_2D_DISABLED |
| 408 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_FREE_COUNT); |
| 409 | #endif // NAVIGATION_2D_DISABLED |
| 410 | #ifndef NAVIGATION_3D_DISABLED |
| 411 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT); |
| 412 | #endif // NAVIGATION_3D_DISABLED |
| 413 | return info; |
| 414 | |
| 415 | case NAVIGATION_OBSTACLE_COUNT: |
| 416 | #ifndef NAVIGATION_2D_DISABLED |
| 417 | info = NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_OBSTACLE_COUNT); |
| 418 | #endif // NAVIGATION_2D_DISABLED |
| 419 | #ifndef NAVIGATION_3D_DISABLED |
| 420 | info += NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_OBSTACLE_COUNT); |
| 421 | #endif // NAVIGATION_3D_DISABLED |
| 422 | return info; |
| 423 | |
| 424 | #ifndef NAVIGATION_2D_DISABLED |
| 425 | case NAVIGATION_2D_ACTIVE_MAPS: |
| 426 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_ACTIVE_MAPS); |
| 427 | case NAVIGATION_2D_REGION_COUNT: |
| 428 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_REGION_COUNT); |
| 429 | case NAVIGATION_2D_AGENT_COUNT: |
| 430 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_AGENT_COUNT); |
| 431 | case NAVIGATION_2D_LINK_COUNT: |
| 432 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_LINK_COUNT); |
| 433 | case NAVIGATION_2D_POLYGON_COUNT: |
| 434 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_POLYGON_COUNT); |
| 435 | case NAVIGATION_2D_EDGE_COUNT: |
| 436 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_COUNT); |
| 437 | case NAVIGATION_2D_EDGE_MERGE_COUNT: |
| 438 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_MERGE_COUNT); |
| 439 | case NAVIGATION_2D_EDGE_CONNECTION_COUNT: |
| 440 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_CONNECTION_COUNT); |
| 441 | case NAVIGATION_2D_EDGE_FREE_COUNT: |
| 442 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_FREE_COUNT); |
| 443 | case NAVIGATION_2D_OBSTACLE_COUNT: |
| 444 | return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_OBSTACLE_COUNT); |
| 445 | #endif // NAVIGATION_2D_DISABLED |
| 446 | |
| 447 | #ifndef NAVIGATION_3D_DISABLED |
| 448 | case NAVIGATION_3D_ACTIVE_MAPS: |
| 449 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_ACTIVE_MAPS); |
| 450 | case NAVIGATION_3D_REGION_COUNT: |
| 451 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_REGION_COUNT); |
| 452 | case NAVIGATION_3D_AGENT_COUNT: |
| 453 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_AGENT_COUNT); |
| 454 | case NAVIGATION_3D_LINK_COUNT: |
| 455 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_LINK_COUNT); |
| 456 | case NAVIGATION_3D_POLYGON_COUNT: |
| 457 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_POLYGON_COUNT); |
| 458 | case NAVIGATION_3D_EDGE_COUNT: |
| 459 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_COUNT); |
| 460 | case NAVIGATION_3D_EDGE_MERGE_COUNT: |
| 461 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_MERGE_COUNT); |
| 462 | case NAVIGATION_3D_EDGE_CONNECTION_COUNT: |
| 463 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT); |
| 464 | case NAVIGATION_3D_EDGE_FREE_COUNT: |
| 465 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT); |
| 466 | case NAVIGATION_3D_OBSTACLE_COUNT: |
| 467 | return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_OBSTACLE_COUNT); |
| 468 | #endif // NAVIGATION_3D_DISABLED |
| 469 | #ifdef MODULE_TEXTURE_STREAMING_ENABLED |
| 470 | case RENDER_STREAMING_TEXTURE_MEM_USED: { |
| 471 | TextureStreaming *texture_streaming = TextureStreaming::get_singleton(); |
| 472 | return texture_streaming ? texture_streaming->get_memory_budget_bytes_used() : 0; |
| 473 | } |
| 474 | #endif // MODULE_TEXTURE_STREAMING_ENABLED |
| 475 | default: { |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const { |
| 483 | ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, MONITOR_TYPE_QUANTITY); |
| 484 | // ugly |
| 485 | static const MonitorType types[MONITOR_MAX] = { |
| 486 | MONITOR_TYPE_QUANTITY, |
| 487 | MONITOR_TYPE_TIME, |
| 488 | MONITOR_TYPE_TIME, |
| 489 | MONITOR_TYPE_TIME, |
| 490 | MONITOR_TYPE_MEMORY, |
| 491 | MONITOR_TYPE_MEMORY, |
| 492 | MONITOR_TYPE_MEMORY, |
| 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_MEMORY, |
| 501 | MONITOR_TYPE_MEMORY, |
| 502 | MONITOR_TYPE_MEMORY, |
| 503 | MONITOR_TYPE_QUANTITY, |
| 504 | MONITOR_TYPE_QUANTITY, |
| 505 | MONITOR_TYPE_QUANTITY, |
| 506 | MONITOR_TYPE_QUANTITY, |
| 507 | MONITOR_TYPE_QUANTITY, |
| 508 | MONITOR_TYPE_QUANTITY, |
| 509 | MONITOR_TYPE_TIME, |
| 510 | MONITOR_TYPE_QUANTITY, |
| 511 | MONITOR_TYPE_QUANTITY, |
| 512 | MONITOR_TYPE_QUANTITY, |
| 513 | MONITOR_TYPE_QUANTITY, |
| 514 | MONITOR_TYPE_QUANTITY, |
| 515 | MONITOR_TYPE_QUANTITY, |
| 516 | MONITOR_TYPE_QUANTITY, |
| 517 | MONITOR_TYPE_QUANTITY, |
| 518 | MONITOR_TYPE_QUANTITY, |
| 519 | MONITOR_TYPE_QUANTITY, |
| 520 | MONITOR_TYPE_QUANTITY, |
| 521 | MONITOR_TYPE_QUANTITY, |
| 522 | MONITOR_TYPE_QUANTITY, |
| 523 | MONITOR_TYPE_QUANTITY, |
| 524 | MONITOR_TYPE_QUANTITY, |
| 525 | MONITOR_TYPE_QUANTITY, |
| 526 | MONITOR_TYPE_QUANTITY, |
| 527 | MONITOR_TYPE_QUANTITY, |
| 528 | MONITOR_TYPE_QUANTITY, |
| 529 | MONITOR_TYPE_QUANTITY, |
| 530 | MONITOR_TYPE_QUANTITY, |
| 531 | MONITOR_TYPE_QUANTITY, |
| 532 | MONITOR_TYPE_QUANTITY, |
| 533 | MONITOR_TYPE_QUANTITY, |
| 534 | MONITOR_TYPE_QUANTITY, |
| 535 | #ifndef _3D_DISABLED |
| 536 | MONITOR_TYPE_QUANTITY, |
| 537 | MONITOR_TYPE_QUANTITY, |
| 538 | MONITOR_TYPE_QUANTITY, |
| 539 | MONITOR_TYPE_QUANTITY, |
| 540 | MONITOR_TYPE_QUANTITY, |
| 541 | MONITOR_TYPE_QUANTITY, |
| 542 | MONITOR_TYPE_QUANTITY, |
| 543 | MONITOR_TYPE_QUANTITY, |
| 544 | MONITOR_TYPE_QUANTITY, |
| 545 | MONITOR_TYPE_QUANTITY, |
| 546 | #endif // _3D_DISABLED |
| 547 | #ifdef MODULE_TEXTURE_STREAMING_ENABLED |
| 548 | MONITOR_TYPE_MEMORY, |
| 549 | #endif // MODULE_TEXTURE_STREAMING_ENABLED |
| 550 | }; |
| 551 | static_assert((sizeof(types) / sizeof(MonitorType)) == MONITOR_MAX); |
| 552 | |
| 553 | return types[p_monitor]; |
| 554 | } |
| 555 | |
| 556 | void Performance::set_process_time(double p_pt) { |
| 557 | _process_time = p_pt; |
| 558 | } |
| 559 | |
| 560 | void Performance::set_physics_process_time(double p_pt) { |
| 561 | _physics_process_time = p_pt; |
| 562 | } |
| 563 | |
| 564 | void Performance::set_navigation_process_time(double p_pt) { |
| 565 | _navigation_process_time = p_pt; |
| 566 | } |
| 567 | |
| 568 | void Performance::add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args, MonitorType p_type) { |
| 569 | ERR_FAIL_COND_MSG(has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' already exists."); |
| 570 | _monitor_map.insert(p_id, MonitorCall(p_type, p_callable, p_args)); |
| 571 | _monitor_modification_time = OS::get_singleton()->get_ticks_usec(); |
| 572 | } |
| 573 | |
| 574 | void Performance::remove_custom_monitor(const StringName &p_id) { |
| 575 | ERR_FAIL_COND_MSG(!has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' doesn't exist."); |
| 576 | _monitor_map.erase(p_id); |
| 577 | _monitor_modification_time = OS::get_singleton()->get_ticks_usec(); |
| 578 | } |
| 579 | |
| 580 | bool Performance::has_custom_monitor(const StringName &p_id) { |
| 581 | return _monitor_map.has(p_id); |
| 582 | } |
| 583 | |
| 584 | Variant Performance::get_custom_monitor(const StringName &p_id) { |
| 585 | ERR_FAIL_COND_V_MSG(!has_custom_monitor(p_id), Variant(), "Custom monitor with id '" + String(p_id) + "' doesn't exist."); |
| 586 | bool error; |
| 587 | String error_message; |
| 588 | Variant return_value = _monitor_map[p_id].call(error, error_message); |
| 589 | ERR_FAIL_COND_V_MSG(error, return_value, "Error calling from custom monitor '" + String(p_id) + "' to callable: " + error_message); |
| 590 | return return_value; |
| 591 | } |
| 592 | |
| 593 | TypedArray<StringName> Performance::get_custom_monitor_names() { |
| 594 | if (!_monitor_map.size()) { |
| 595 | return TypedArray<StringName>(); |
| 596 | } |
| 597 | TypedArray<StringName> return_array; |
| 598 | return_array.resize(_monitor_map.size()); |
| 599 | int index = 0; |
| 600 | for (KeyValue<StringName, MonitorCall> i : _monitor_map) { |
| 601 | return_array.set(index, i.key); |
| 602 | index++; |
| 603 | } |
| 604 | return return_array; |
| 605 | } |
| 606 | |
| 607 | Vector<int> Performance::get_custom_monitor_types() { |
| 608 | if (_monitor_map.is_empty()) { |
| 609 | return Vector<int>(); |
| 610 | } |
| 611 | Vector<int> ret; |
| 612 | ret.resize(_monitor_map.size()); |
| 613 | int index = 0; |
| 614 | for (const KeyValue<StringName, MonitorCall> &i : _monitor_map) { |
| 615 | ret.set(index, (int)i.value.get_monitor_type()); |
| 616 | index++; |
| 617 | } |
| 618 | return ret; |
| 619 | } |
| 620 | |
| 621 | uint64_t Performance::get_monitor_modification_time() { |
| 622 | return _monitor_modification_time; |
| 623 | } |
| 624 | |
| 625 | Performance::Performance() { |
| 626 | _process_time = 0; |
| 627 | _physics_process_time = 0; |
| 628 | _navigation_process_time = 0; |
| 629 | _monitor_modification_time = 0; |
| 630 | singleton = this; |
| 631 | } |
| 632 | |
| 633 | Performance::MonitorCall::MonitorCall(Performance::MonitorType p_type, const Callable &p_callable, const Vector<Variant> &p_arguments) { |
| 634 | _type = p_type; |
| 635 | _callable = p_callable; |
| 636 | _arguments = p_arguments; |
| 637 | } |
| 638 | |
| 639 | Performance::MonitorCall::MonitorCall() { |
| 640 | } |
| 641 | |
| 642 | Variant Performance::MonitorCall::call(bool &r_error, String &r_error_message) { |
| 643 | Vector<const Variant *> arguments_mem; |
| 644 | arguments_mem.resize(_arguments.size()); |
| 645 | for (int i = 0; i < _arguments.size(); i++) { |
| 646 | arguments_mem.write[i] = &_arguments[i]; |
| 647 | } |
| 648 | const Variant **args = (const Variant **)arguments_mem.ptr(); |
| 649 | int argc = _arguments.size(); |
| 650 | Variant return_value; |
| 651 | Callable::CallError error; |
| 652 | _callable.callp(args, argc, return_value, error); |
| 653 | r_error = (error.error != Callable::CallError::CALL_OK); |
| 654 | if (r_error) { |
| 655 | r_error_message = Variant::get_callable_error_text(_callable, args, argc, error); |
| 656 | } |
| 657 | return return_value; |
| 658 | } |