2
0

performance.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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. #include "performance.h"
  31. #include "core/os/os.h"
  32. #include "core/variant/typed_array.h"
  33. #include "scene/main/node.h"
  34. #include "scene/main/scene_tree.h"
  35. #include "servers/audio_server.h"
  36. #include "servers/navigation_server_2d.h"
  37. #include "servers/navigation_server_3d.h"
  38. #include "servers/rendering_server.h"
  39. #ifndef PHYSICS_2D_DISABLED
  40. #include "servers/physics_server_2d.h"
  41. #endif // PHYSICS_2D_DISABLED
  42. #ifndef PHYSICS_3D_DISABLED
  43. #include "servers/physics_server_3d.h"
  44. #endif // PHYSICS_3D_DISABLED
  45. Performance *Performance::singleton = nullptr;
  46. void Performance::_bind_methods() {
  47. ClassDB::bind_method(D_METHOD("get_monitor", "monitor"), &Performance::get_monitor);
  48. ClassDB::bind_method(D_METHOD("add_custom_monitor", "id", "callable", "arguments"), &Performance::add_custom_monitor, DEFVAL(Array()));
  49. ClassDB::bind_method(D_METHOD("remove_custom_monitor", "id"), &Performance::remove_custom_monitor);
  50. ClassDB::bind_method(D_METHOD("has_custom_monitor", "id"), &Performance::has_custom_monitor);
  51. ClassDB::bind_method(D_METHOD("get_custom_monitor", "id"), &Performance::get_custom_monitor);
  52. ClassDB::bind_method(D_METHOD("get_monitor_modification_time"), &Performance::get_monitor_modification_time);
  53. ClassDB::bind_method(D_METHOD("get_custom_monitor_names"), &Performance::get_custom_monitor_names);
  54. BIND_ENUM_CONSTANT(TIME_FPS);
  55. BIND_ENUM_CONSTANT(TIME_PROCESS);
  56. BIND_ENUM_CONSTANT(TIME_PHYSICS_PROCESS);
  57. BIND_ENUM_CONSTANT(TIME_NAVIGATION_PROCESS);
  58. BIND_ENUM_CONSTANT(MEMORY_STATIC);
  59. BIND_ENUM_CONSTANT(MEMORY_STATIC_MAX);
  60. BIND_ENUM_CONSTANT(MEMORY_MESSAGE_BUFFER_MAX);
  61. BIND_ENUM_CONSTANT(OBJECT_COUNT);
  62. BIND_ENUM_CONSTANT(OBJECT_RESOURCE_COUNT);
  63. BIND_ENUM_CONSTANT(OBJECT_NODE_COUNT);
  64. BIND_ENUM_CONSTANT(OBJECT_ORPHAN_NODE_COUNT);
  65. BIND_ENUM_CONSTANT(RENDER_TOTAL_OBJECTS_IN_FRAME);
  66. BIND_ENUM_CONSTANT(RENDER_TOTAL_PRIMITIVES_IN_FRAME);
  67. BIND_ENUM_CONSTANT(RENDER_TOTAL_DRAW_CALLS_IN_FRAME);
  68. BIND_ENUM_CONSTANT(RENDER_VIDEO_MEM_USED);
  69. BIND_ENUM_CONSTANT(RENDER_TEXTURE_MEM_USED);
  70. BIND_ENUM_CONSTANT(RENDER_BUFFER_MEM_USED);
  71. BIND_ENUM_CONSTANT(PHYSICS_2D_ACTIVE_OBJECTS);
  72. BIND_ENUM_CONSTANT(PHYSICS_2D_COLLISION_PAIRS);
  73. BIND_ENUM_CONSTANT(PHYSICS_2D_ISLAND_COUNT);
  74. #ifndef _3D_DISABLED
  75. BIND_ENUM_CONSTANT(PHYSICS_3D_ACTIVE_OBJECTS);
  76. BIND_ENUM_CONSTANT(PHYSICS_3D_COLLISION_PAIRS);
  77. BIND_ENUM_CONSTANT(PHYSICS_3D_ISLAND_COUNT);
  78. #endif // _3D_DISABLED
  79. BIND_ENUM_CONSTANT(AUDIO_OUTPUT_LATENCY);
  80. BIND_ENUM_CONSTANT(NAVIGATION_ACTIVE_MAPS);
  81. BIND_ENUM_CONSTANT(NAVIGATION_REGION_COUNT);
  82. BIND_ENUM_CONSTANT(NAVIGATION_AGENT_COUNT);
  83. BIND_ENUM_CONSTANT(NAVIGATION_LINK_COUNT);
  84. BIND_ENUM_CONSTANT(NAVIGATION_POLYGON_COUNT);
  85. BIND_ENUM_CONSTANT(NAVIGATION_EDGE_COUNT);
  86. BIND_ENUM_CONSTANT(NAVIGATION_EDGE_MERGE_COUNT);
  87. BIND_ENUM_CONSTANT(NAVIGATION_EDGE_CONNECTION_COUNT);
  88. BIND_ENUM_CONSTANT(NAVIGATION_EDGE_FREE_COUNT);
  89. BIND_ENUM_CONSTANT(NAVIGATION_OBSTACLE_COUNT);
  90. BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_CANVAS);
  91. BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_MESH);
  92. BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_SURFACE);
  93. BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_DRAW);
  94. BIND_ENUM_CONSTANT(PIPELINE_COMPILATIONS_SPECIALIZATION);
  95. BIND_ENUM_CONSTANT(NAVIGATION_2D_ACTIVE_MAPS);
  96. BIND_ENUM_CONSTANT(NAVIGATION_2D_REGION_COUNT);
  97. BIND_ENUM_CONSTANT(NAVIGATION_2D_AGENT_COUNT);
  98. BIND_ENUM_CONSTANT(NAVIGATION_2D_LINK_COUNT);
  99. BIND_ENUM_CONSTANT(NAVIGATION_2D_POLYGON_COUNT);
  100. BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_COUNT);
  101. BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_MERGE_COUNT);
  102. BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_CONNECTION_COUNT);
  103. BIND_ENUM_CONSTANT(NAVIGATION_2D_EDGE_FREE_COUNT);
  104. BIND_ENUM_CONSTANT(NAVIGATION_2D_OBSTACLE_COUNT);
  105. BIND_ENUM_CONSTANT(NAVIGATION_3D_ACTIVE_MAPS);
  106. BIND_ENUM_CONSTANT(NAVIGATION_3D_REGION_COUNT);
  107. BIND_ENUM_CONSTANT(NAVIGATION_3D_AGENT_COUNT);
  108. BIND_ENUM_CONSTANT(NAVIGATION_3D_LINK_COUNT);
  109. BIND_ENUM_CONSTANT(NAVIGATION_3D_POLYGON_COUNT);
  110. BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_COUNT);
  111. BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_MERGE_COUNT);
  112. BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_CONNECTION_COUNT);
  113. BIND_ENUM_CONSTANT(NAVIGATION_3D_EDGE_FREE_COUNT);
  114. BIND_ENUM_CONSTANT(NAVIGATION_3D_OBSTACLE_COUNT);
  115. BIND_ENUM_CONSTANT(MONITOR_MAX);
  116. }
  117. int Performance::_get_node_count() const {
  118. MainLoop *ml = OS::get_singleton()->get_main_loop();
  119. SceneTree *sml = Object::cast_to<SceneTree>(ml);
  120. if (!sml) {
  121. return 0;
  122. }
  123. return sml->get_node_count();
  124. }
  125. String Performance::get_monitor_name(Monitor p_monitor) const {
  126. ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, String());
  127. static const char *names[MONITOR_MAX] = {
  128. PNAME("time/fps"),
  129. PNAME("time/process"),
  130. PNAME("time/physics_process"),
  131. PNAME("time/navigation_process"),
  132. PNAME("memory/static"),
  133. PNAME("memory/static_max"),
  134. PNAME("memory/msg_buf_max"),
  135. PNAME("object/objects"),
  136. PNAME("object/resources"),
  137. PNAME("object/nodes"),
  138. PNAME("object/orphan_nodes"),
  139. PNAME("raster/total_objects_drawn"),
  140. PNAME("raster/total_primitives_drawn"),
  141. PNAME("raster/total_draw_calls"),
  142. PNAME("video/video_mem"),
  143. PNAME("video/texture_mem"),
  144. PNAME("video/buffer_mem"),
  145. PNAME("physics_2d/active_objects"),
  146. PNAME("physics_2d/collision_pairs"),
  147. PNAME("physics_2d/islands"),
  148. PNAME("physics_3d/active_objects"),
  149. PNAME("physics_3d/collision_pairs"),
  150. PNAME("physics_3d/islands"),
  151. PNAME("audio/driver/output_latency"),
  152. PNAME("navigation/active_maps"),
  153. PNAME("navigation/regions"),
  154. PNAME("navigation/agents"),
  155. PNAME("navigation/links"),
  156. PNAME("navigation/polygons"),
  157. PNAME("navigation/edges"),
  158. PNAME("navigation/edges_merged"),
  159. PNAME("navigation/edges_connected"),
  160. PNAME("navigation/edges_free"),
  161. PNAME("navigation/obstacles"),
  162. PNAME("pipeline/compilations_canvas"),
  163. PNAME("pipeline/compilations_mesh"),
  164. PNAME("pipeline/compilations_surface"),
  165. PNAME("pipeline/compilations_draw"),
  166. PNAME("pipeline/compilations_specialization"),
  167. PNAME("navigation_2d/active_maps"),
  168. PNAME("navigation_2d/regions"),
  169. PNAME("navigation_2d/agents"),
  170. PNAME("navigation_2d/links"),
  171. PNAME("navigation_2d/polygons"),
  172. PNAME("navigation_2d/edges"),
  173. PNAME("navigation_2d/edges_merged"),
  174. PNAME("navigation_2d/edges_connected"),
  175. PNAME("navigation_2d/edges_free"),
  176. PNAME("navigation_2d/obstacles"),
  177. PNAME("navigation_2d/active_maps"),
  178. PNAME("navigation_3d/regions"),
  179. PNAME("navigation_3d/agents"),
  180. PNAME("navigation_3d/links"),
  181. PNAME("navigation_3d/polygons"),
  182. PNAME("navigation_3d/edges"),
  183. PNAME("navigation_3d/edges_merged"),
  184. PNAME("navigation_3d/edges_connected"),
  185. PNAME("navigation_3d/edges_free"),
  186. PNAME("navigation_3d/obstacles"),
  187. };
  188. static_assert(std::size(names) == MONITOR_MAX);
  189. return names[p_monitor];
  190. }
  191. double Performance::get_monitor(Monitor p_monitor) const {
  192. switch (p_monitor) {
  193. case TIME_FPS:
  194. return Engine::get_singleton()->get_frames_per_second();
  195. case TIME_PROCESS:
  196. return _process_time;
  197. case TIME_PHYSICS_PROCESS:
  198. return _physics_process_time;
  199. case TIME_NAVIGATION_PROCESS:
  200. return _navigation_process_time;
  201. case MEMORY_STATIC:
  202. return Memory::get_mem_usage();
  203. case MEMORY_STATIC_MAX:
  204. return Memory::get_mem_max_usage();
  205. case MEMORY_MESSAGE_BUFFER_MAX:
  206. return MessageQueue::get_singleton()->get_max_buffer_usage();
  207. case OBJECT_COUNT:
  208. return ObjectDB::get_object_count();
  209. case OBJECT_RESOURCE_COUNT:
  210. return ResourceCache::get_cached_resource_count();
  211. case OBJECT_NODE_COUNT:
  212. return _get_node_count();
  213. case OBJECT_ORPHAN_NODE_COUNT:
  214. return Node::orphan_node_count;
  215. case RENDER_TOTAL_OBJECTS_IN_FRAME:
  216. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_OBJECTS_IN_FRAME);
  217. case RENDER_TOTAL_PRIMITIVES_IN_FRAME:
  218. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_PRIMITIVES_IN_FRAME);
  219. case RENDER_TOTAL_DRAW_CALLS_IN_FRAME:
  220. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TOTAL_DRAW_CALLS_IN_FRAME);
  221. case RENDER_VIDEO_MEM_USED:
  222. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_VIDEO_MEM_USED);
  223. case RENDER_TEXTURE_MEM_USED:
  224. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_TEXTURE_MEM_USED);
  225. case RENDER_BUFFER_MEM_USED:
  226. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_BUFFER_MEM_USED);
  227. case PIPELINE_COMPILATIONS_CANVAS:
  228. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_CANVAS);
  229. case PIPELINE_COMPILATIONS_MESH:
  230. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_MESH);
  231. case PIPELINE_COMPILATIONS_SURFACE:
  232. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_SURFACE);
  233. case PIPELINE_COMPILATIONS_DRAW:
  234. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_DRAW);
  235. case PIPELINE_COMPILATIONS_SPECIALIZATION:
  236. return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_SPECIALIZATION);
  237. #ifndef PHYSICS_2D_DISABLED
  238. case PHYSICS_2D_ACTIVE_OBJECTS:
  239. return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ACTIVE_OBJECTS);
  240. case PHYSICS_2D_COLLISION_PAIRS:
  241. return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS);
  242. case PHYSICS_2D_ISLAND_COUNT:
  243. return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ISLAND_COUNT);
  244. #else
  245. case PHYSICS_2D_ACTIVE_OBJECTS:
  246. return 0;
  247. case PHYSICS_2D_COLLISION_PAIRS:
  248. return 0;
  249. case PHYSICS_2D_ISLAND_COUNT:
  250. return 0;
  251. #endif // PHYSICS_2D_DISABLED
  252. #ifndef PHYSICS_3D_DISABLED
  253. case PHYSICS_3D_ACTIVE_OBJECTS:
  254. return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ACTIVE_OBJECTS);
  255. case PHYSICS_3D_COLLISION_PAIRS:
  256. return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_COLLISION_PAIRS);
  257. case PHYSICS_3D_ISLAND_COUNT:
  258. return PhysicsServer3D::get_singleton()->get_process_info(PhysicsServer3D::INFO_ISLAND_COUNT);
  259. #else
  260. case PHYSICS_3D_ACTIVE_OBJECTS:
  261. return 0;
  262. case PHYSICS_3D_COLLISION_PAIRS:
  263. return 0;
  264. case PHYSICS_3D_ISLAND_COUNT:
  265. return 0;
  266. #endif // PHYSICS_3D_DISABLED
  267. case AUDIO_OUTPUT_LATENCY:
  268. return AudioServer::get_singleton()->get_output_latency();
  269. case NAVIGATION_ACTIVE_MAPS:
  270. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_ACTIVE_MAPS) +
  271. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_ACTIVE_MAPS);
  272. case NAVIGATION_REGION_COUNT:
  273. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_REGION_COUNT) +
  274. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_REGION_COUNT);
  275. case NAVIGATION_AGENT_COUNT:
  276. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_AGENT_COUNT) +
  277. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_AGENT_COUNT);
  278. case NAVIGATION_LINK_COUNT:
  279. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_LINK_COUNT) +
  280. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_LINK_COUNT);
  281. case NAVIGATION_POLYGON_COUNT:
  282. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_POLYGON_COUNT) +
  283. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_POLYGON_COUNT);
  284. case NAVIGATION_EDGE_COUNT:
  285. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_COUNT) +
  286. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_COUNT);
  287. case NAVIGATION_EDGE_MERGE_COUNT:
  288. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_MERGE_COUNT) +
  289. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_MERGE_COUNT);
  290. case NAVIGATION_EDGE_CONNECTION_COUNT:
  291. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_CONNECTION_COUNT) +
  292. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT);
  293. case NAVIGATION_EDGE_FREE_COUNT:
  294. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_FREE_COUNT) +
  295. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT);
  296. case NAVIGATION_OBSTACLE_COUNT:
  297. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_OBSTACLE_COUNT) +
  298. NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_OBSTACLE_COUNT);
  299. case NAVIGATION_2D_ACTIVE_MAPS:
  300. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_ACTIVE_MAPS);
  301. case NAVIGATION_2D_REGION_COUNT:
  302. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_REGION_COUNT);
  303. case NAVIGATION_2D_AGENT_COUNT:
  304. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_AGENT_COUNT);
  305. case NAVIGATION_2D_LINK_COUNT:
  306. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_LINK_COUNT);
  307. case NAVIGATION_2D_POLYGON_COUNT:
  308. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_POLYGON_COUNT);
  309. case NAVIGATION_2D_EDGE_COUNT:
  310. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_COUNT);
  311. case NAVIGATION_2D_EDGE_MERGE_COUNT:
  312. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_MERGE_COUNT);
  313. case NAVIGATION_2D_EDGE_CONNECTION_COUNT:
  314. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_CONNECTION_COUNT);
  315. case NAVIGATION_2D_EDGE_FREE_COUNT:
  316. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_EDGE_FREE_COUNT);
  317. case NAVIGATION_2D_OBSTACLE_COUNT:
  318. return NavigationServer2D::get_singleton()->get_process_info(NavigationServer2D::INFO_OBSTACLE_COUNT);
  319. case NAVIGATION_3D_ACTIVE_MAPS:
  320. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_ACTIVE_MAPS);
  321. case NAVIGATION_3D_REGION_COUNT:
  322. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_REGION_COUNT);
  323. case NAVIGATION_3D_AGENT_COUNT:
  324. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_AGENT_COUNT);
  325. case NAVIGATION_3D_LINK_COUNT:
  326. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_LINK_COUNT);
  327. case NAVIGATION_3D_POLYGON_COUNT:
  328. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_POLYGON_COUNT);
  329. case NAVIGATION_3D_EDGE_COUNT:
  330. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_COUNT);
  331. case NAVIGATION_3D_EDGE_MERGE_COUNT:
  332. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_MERGE_COUNT);
  333. case NAVIGATION_3D_EDGE_CONNECTION_COUNT:
  334. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_CONNECTION_COUNT);
  335. case NAVIGATION_3D_EDGE_FREE_COUNT:
  336. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_EDGE_FREE_COUNT);
  337. case NAVIGATION_3D_OBSTACLE_COUNT:
  338. return NavigationServer3D::get_singleton()->get_process_info(NavigationServer3D::INFO_OBSTACLE_COUNT);
  339. default: {
  340. }
  341. }
  342. return 0;
  343. }
  344. Performance::MonitorType Performance::get_monitor_type(Monitor p_monitor) const {
  345. ERR_FAIL_INDEX_V(p_monitor, MONITOR_MAX, MONITOR_TYPE_QUANTITY);
  346. // ugly
  347. static const MonitorType types[MONITOR_MAX] = {
  348. MONITOR_TYPE_QUANTITY,
  349. MONITOR_TYPE_TIME,
  350. MONITOR_TYPE_TIME,
  351. MONITOR_TYPE_TIME,
  352. MONITOR_TYPE_MEMORY,
  353. MONITOR_TYPE_MEMORY,
  354. MONITOR_TYPE_MEMORY,
  355. MONITOR_TYPE_QUANTITY,
  356. MONITOR_TYPE_QUANTITY,
  357. MONITOR_TYPE_QUANTITY,
  358. MONITOR_TYPE_QUANTITY,
  359. MONITOR_TYPE_QUANTITY,
  360. MONITOR_TYPE_QUANTITY,
  361. MONITOR_TYPE_QUANTITY,
  362. MONITOR_TYPE_MEMORY,
  363. MONITOR_TYPE_MEMORY,
  364. MONITOR_TYPE_MEMORY,
  365. MONITOR_TYPE_QUANTITY,
  366. MONITOR_TYPE_QUANTITY,
  367. MONITOR_TYPE_QUANTITY,
  368. MONITOR_TYPE_QUANTITY,
  369. MONITOR_TYPE_QUANTITY,
  370. MONITOR_TYPE_QUANTITY,
  371. MONITOR_TYPE_TIME,
  372. MONITOR_TYPE_QUANTITY,
  373. MONITOR_TYPE_QUANTITY,
  374. MONITOR_TYPE_QUANTITY,
  375. MONITOR_TYPE_QUANTITY,
  376. MONITOR_TYPE_QUANTITY,
  377. MONITOR_TYPE_QUANTITY,
  378. MONITOR_TYPE_QUANTITY,
  379. MONITOR_TYPE_QUANTITY,
  380. MONITOR_TYPE_QUANTITY,
  381. MONITOR_TYPE_QUANTITY,
  382. MONITOR_TYPE_QUANTITY,
  383. MONITOR_TYPE_QUANTITY,
  384. MONITOR_TYPE_QUANTITY,
  385. MONITOR_TYPE_QUANTITY,
  386. MONITOR_TYPE_QUANTITY,
  387. MONITOR_TYPE_QUANTITY,
  388. MONITOR_TYPE_QUANTITY,
  389. MONITOR_TYPE_QUANTITY,
  390. MONITOR_TYPE_QUANTITY,
  391. MONITOR_TYPE_QUANTITY,
  392. MONITOR_TYPE_QUANTITY,
  393. MONITOR_TYPE_QUANTITY,
  394. MONITOR_TYPE_QUANTITY,
  395. MONITOR_TYPE_QUANTITY,
  396. MONITOR_TYPE_QUANTITY,
  397. MONITOR_TYPE_QUANTITY,
  398. MONITOR_TYPE_QUANTITY,
  399. MONITOR_TYPE_QUANTITY,
  400. MONITOR_TYPE_QUANTITY,
  401. MONITOR_TYPE_QUANTITY,
  402. MONITOR_TYPE_QUANTITY,
  403. MONITOR_TYPE_QUANTITY,
  404. MONITOR_TYPE_QUANTITY,
  405. MONITOR_TYPE_QUANTITY,
  406. MONITOR_TYPE_QUANTITY,
  407. };
  408. static_assert((sizeof(types) / sizeof(MonitorType)) == MONITOR_MAX);
  409. return types[p_monitor];
  410. }
  411. void Performance::set_process_time(double p_pt) {
  412. _process_time = p_pt;
  413. }
  414. void Performance::set_physics_process_time(double p_pt) {
  415. _physics_process_time = p_pt;
  416. }
  417. void Performance::set_navigation_process_time(double p_pt) {
  418. _navigation_process_time = p_pt;
  419. }
  420. void Performance::add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args) {
  421. ERR_FAIL_COND_MSG(has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' already exists.");
  422. _monitor_map.insert(p_id, MonitorCall(p_callable, p_args));
  423. _monitor_modification_time = OS::get_singleton()->get_ticks_usec();
  424. }
  425. void Performance::remove_custom_monitor(const StringName &p_id) {
  426. ERR_FAIL_COND_MSG(!has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' doesn't exists.");
  427. _monitor_map.erase(p_id);
  428. _monitor_modification_time = OS::get_singleton()->get_ticks_usec();
  429. }
  430. bool Performance::has_custom_monitor(const StringName &p_id) {
  431. return _monitor_map.has(p_id);
  432. }
  433. Variant Performance::get_custom_monitor(const StringName &p_id) {
  434. ERR_FAIL_COND_V_MSG(!has_custom_monitor(p_id), Variant(), "Custom monitor with id '" + String(p_id) + "' doesn't exists.");
  435. bool error;
  436. String error_message;
  437. Variant return_value = _monitor_map[p_id].call(error, error_message);
  438. ERR_FAIL_COND_V_MSG(error, return_value, "Error calling from custom monitor '" + String(p_id) + "' to callable: " + error_message);
  439. return return_value;
  440. }
  441. TypedArray<StringName> Performance::get_custom_monitor_names() {
  442. if (!_monitor_map.size()) {
  443. return TypedArray<StringName>();
  444. }
  445. TypedArray<StringName> return_array;
  446. return_array.resize(_monitor_map.size());
  447. int index = 0;
  448. for (KeyValue<StringName, MonitorCall> i : _monitor_map) {
  449. return_array.set(index, i.key);
  450. index++;
  451. }
  452. return return_array;
  453. }
  454. uint64_t Performance::get_monitor_modification_time() {
  455. return _monitor_modification_time;
  456. }
  457. Performance::Performance() {
  458. _process_time = 0;
  459. _physics_process_time = 0;
  460. _navigation_process_time = 0;
  461. _monitor_modification_time = 0;
  462. singleton = this;
  463. }
  464. Performance::MonitorCall::MonitorCall(Callable p_callable, Vector<Variant> p_arguments) {
  465. _callable = p_callable;
  466. _arguments = p_arguments;
  467. }
  468. Performance::MonitorCall::MonitorCall() {
  469. }
  470. Variant Performance::MonitorCall::call(bool &r_error, String &r_error_message) {
  471. Vector<const Variant *> arguments_mem;
  472. arguments_mem.resize(_arguments.size());
  473. for (int i = 0; i < _arguments.size(); i++) {
  474. arguments_mem.write[i] = &_arguments[i];
  475. }
  476. const Variant **args = (const Variant **)arguments_mem.ptr();
  477. int argc = _arguments.size();
  478. Variant return_value;
  479. Callable::CallError error;
  480. _callable.callp(args, argc, return_value, error);
  481. r_error = (error.error != Callable::CallError::CALL_OK);
  482. if (r_error) {
  483. r_error_message = Variant::get_callable_error_text(_callable, args, argc, error);
  484. }
  485. return return_value;
  486. }