performance.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**************************************************************************/
  2. /* performance.h */
  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. #pragma once
  31. #include "core/object/class_db.h"
  32. #include "core/templates/hash_map.h"
  33. #define PERF_WARN_OFFLINE_FUNCTION
  34. #define PERF_WARN_PROCESS_SYNC
  35. template <typename T>
  36. class TypedArray;
  37. class Performance : public Object {
  38. GDCLASS(Performance, Object);
  39. static Performance *singleton;
  40. static void _bind_methods();
  41. #ifndef DISABLE_DEPRECATED
  42. void _add_custom_monitor_bind_compat_110433(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args);
  43. static void _bind_compatibility_methods();
  44. #endif
  45. int _get_node_count() const;
  46. int _get_orphan_node_count() const;
  47. double _process_time;
  48. double _physics_process_time;
  49. double _navigation_process_time;
  50. public:
  51. enum Monitor {
  52. TIME_FPS,
  53. TIME_PROCESS,
  54. TIME_PHYSICS_PROCESS,
  55. TIME_NAVIGATION_PROCESS,
  56. MEMORY_STATIC,
  57. MEMORY_STATIC_MAX,
  58. MEMORY_MESSAGE_BUFFER_MAX,
  59. OBJECT_COUNT,
  60. OBJECT_RESOURCE_COUNT,
  61. OBJECT_NODE_COUNT,
  62. OBJECT_ORPHAN_NODE_COUNT,
  63. RENDER_TOTAL_OBJECTS_IN_FRAME,
  64. RENDER_TOTAL_PRIMITIVES_IN_FRAME,
  65. RENDER_TOTAL_DRAW_CALLS_IN_FRAME,
  66. RENDER_VIDEO_MEM_USED,
  67. RENDER_TEXTURE_MEM_USED,
  68. RENDER_BUFFER_MEM_USED,
  69. PHYSICS_2D_ACTIVE_OBJECTS,
  70. PHYSICS_2D_COLLISION_PAIRS,
  71. PHYSICS_2D_ISLAND_COUNT,
  72. PHYSICS_3D_ACTIVE_OBJECTS,
  73. PHYSICS_3D_COLLISION_PAIRS,
  74. PHYSICS_3D_ISLAND_COUNT,
  75. AUDIO_OUTPUT_LATENCY,
  76. // Deprecated, use the 2D/3D specific ones instead.
  77. NAVIGATION_ACTIVE_MAPS,
  78. NAVIGATION_REGION_COUNT,
  79. NAVIGATION_AGENT_COUNT,
  80. NAVIGATION_LINK_COUNT,
  81. NAVIGATION_POLYGON_COUNT,
  82. NAVIGATION_EDGE_COUNT,
  83. NAVIGATION_EDGE_MERGE_COUNT,
  84. NAVIGATION_EDGE_CONNECTION_COUNT,
  85. NAVIGATION_EDGE_FREE_COUNT,
  86. NAVIGATION_OBSTACLE_COUNT,
  87. PIPELINE_COMPILATIONS_CANVAS,
  88. PIPELINE_COMPILATIONS_MESH,
  89. PIPELINE_COMPILATIONS_SURFACE,
  90. PIPELINE_COMPILATIONS_DRAW,
  91. PIPELINE_COMPILATIONS_SPECIALIZATION,
  92. NAVIGATION_2D_ACTIVE_MAPS,
  93. NAVIGATION_2D_REGION_COUNT,
  94. NAVIGATION_2D_AGENT_COUNT,
  95. NAVIGATION_2D_LINK_COUNT,
  96. NAVIGATION_2D_POLYGON_COUNT,
  97. NAVIGATION_2D_EDGE_COUNT,
  98. NAVIGATION_2D_EDGE_MERGE_COUNT,
  99. NAVIGATION_2D_EDGE_CONNECTION_COUNT,
  100. NAVIGATION_2D_EDGE_FREE_COUNT,
  101. NAVIGATION_2D_OBSTACLE_COUNT,
  102. #ifndef _3D_DISABLED
  103. NAVIGATION_3D_ACTIVE_MAPS,
  104. NAVIGATION_3D_REGION_COUNT,
  105. NAVIGATION_3D_AGENT_COUNT,
  106. NAVIGATION_3D_LINK_COUNT,
  107. NAVIGATION_3D_POLYGON_COUNT,
  108. NAVIGATION_3D_EDGE_COUNT,
  109. NAVIGATION_3D_EDGE_MERGE_COUNT,
  110. NAVIGATION_3D_EDGE_CONNECTION_COUNT,
  111. NAVIGATION_3D_EDGE_FREE_COUNT,
  112. NAVIGATION_3D_OBSTACLE_COUNT,
  113. #endif // _3D_DISABLED
  114. MONITOR_MAX
  115. };
  116. enum MonitorType {
  117. MONITOR_TYPE_QUANTITY,
  118. MONITOR_TYPE_MEMORY,
  119. MONITOR_TYPE_TIME,
  120. MONITOR_TYPE_PERCENTAGE,
  121. };
  122. double get_monitor(Monitor p_monitor) const;
  123. String get_monitor_name(Monitor p_monitor) const;
  124. MonitorType get_monitor_type(Monitor p_monitor) const;
  125. void set_process_time(double p_pt);
  126. void set_physics_process_time(double p_pt);
  127. void set_navigation_process_time(double p_pt);
  128. void add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args, MonitorType p_type = MONITOR_TYPE_QUANTITY);
  129. void remove_custom_monitor(const StringName &p_id);
  130. bool has_custom_monitor(const StringName &p_id);
  131. Variant get_custom_monitor(const StringName &p_id);
  132. TypedArray<StringName> get_custom_monitor_names();
  133. Vector<int> get_custom_monitor_types();
  134. uint64_t get_monitor_modification_time();
  135. static Performance *get_singleton() { return singleton; }
  136. Performance();
  137. private:
  138. class MonitorCall {
  139. MonitorType _type = MONITOR_TYPE_QUANTITY;
  140. Callable _callable;
  141. Vector<Variant> _arguments;
  142. public:
  143. MonitorCall(MonitorType p_type, const Callable &p_callable, const Vector<Variant> &p_arguments);
  144. MonitorCall();
  145. Variant call(bool &r_error, String &r_error_message);
  146. inline MonitorType get_monitor_type() const { return _type; }
  147. };
  148. HashMap<StringName, MonitorCall> _monitor_map;
  149. uint64_t _monitor_modification_time;
  150. };
  151. VARIANT_ENUM_CAST(Performance::Monitor);
  152. VARIANT_ENUM_CAST(Performance::MonitorType);