performance.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #ifndef PERFORMANCE_H
  31. #define PERFORMANCE_H
  32. #include "core/object/class_db.h"
  33. #include "core/templates/hash_map.h"
  34. #define PERF_WARN_OFFLINE_FUNCTION
  35. #define PERF_WARN_PROCESS_SYNC
  36. template <typename T>
  37. class TypedArray;
  38. class Performance : public Object {
  39. GDCLASS(Performance, Object);
  40. static Performance *singleton;
  41. static void _bind_methods();
  42. int _get_node_count() const;
  43. double _process_time;
  44. double _physics_process_time;
  45. double _navigation_process_time;
  46. class MonitorCall {
  47. Callable _callable;
  48. Vector<Variant> _arguments;
  49. public:
  50. MonitorCall(Callable p_callable, Vector<Variant> p_arguments);
  51. MonitorCall();
  52. Variant call(bool &r_error, String &r_error_message);
  53. };
  54. HashMap<StringName, MonitorCall> _monitor_map;
  55. uint64_t _monitor_modification_time;
  56. public:
  57. enum Monitor {
  58. TIME_FPS,
  59. TIME_PROCESS,
  60. TIME_PHYSICS_PROCESS,
  61. TIME_NAVIGATION_PROCESS,
  62. MEMORY_STATIC,
  63. MEMORY_STATIC_MAX,
  64. MEMORY_MESSAGE_BUFFER_MAX,
  65. OBJECT_COUNT,
  66. OBJECT_RESOURCE_COUNT,
  67. OBJECT_NODE_COUNT,
  68. OBJECT_ORPHAN_NODE_COUNT,
  69. RENDER_TOTAL_OBJECTS_IN_FRAME,
  70. RENDER_TOTAL_PRIMITIVES_IN_FRAME,
  71. RENDER_TOTAL_DRAW_CALLS_IN_FRAME,
  72. RENDER_VIDEO_MEM_USED,
  73. RENDER_TEXTURE_MEM_USED,
  74. RENDER_BUFFER_MEM_USED,
  75. PHYSICS_2D_ACTIVE_OBJECTS,
  76. PHYSICS_2D_COLLISION_PAIRS,
  77. PHYSICS_2D_ISLAND_COUNT,
  78. PHYSICS_3D_ACTIVE_OBJECTS,
  79. PHYSICS_3D_COLLISION_PAIRS,
  80. PHYSICS_3D_ISLAND_COUNT,
  81. AUDIO_OUTPUT_LATENCY,
  82. NAVIGATION_ACTIVE_MAPS,
  83. NAVIGATION_REGION_COUNT,
  84. NAVIGATION_AGENT_COUNT,
  85. NAVIGATION_LINK_COUNT,
  86. NAVIGATION_POLYGON_COUNT,
  87. NAVIGATION_EDGE_COUNT,
  88. NAVIGATION_EDGE_MERGE_COUNT,
  89. NAVIGATION_EDGE_CONNECTION_COUNT,
  90. NAVIGATION_EDGE_FREE_COUNT,
  91. MONITOR_MAX
  92. };
  93. enum MonitorType {
  94. MONITOR_TYPE_QUANTITY,
  95. MONITOR_TYPE_MEMORY,
  96. MONITOR_TYPE_TIME
  97. };
  98. double get_monitor(Monitor p_monitor) const;
  99. String get_monitor_name(Monitor p_monitor) const;
  100. MonitorType get_monitor_type(Monitor p_monitor) const;
  101. void set_process_time(double p_pt);
  102. void set_physics_process_time(double p_pt);
  103. void set_navigation_process_time(double p_pt);
  104. void add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args);
  105. void remove_custom_monitor(const StringName &p_id);
  106. bool has_custom_monitor(const StringName &p_id);
  107. Variant get_custom_monitor(const StringName &p_id);
  108. TypedArray<StringName> get_custom_monitor_names();
  109. uint64_t get_monitor_modification_time();
  110. static Performance *get_singleton() { return singleton; }
  111. Performance();
  112. };
  113. VARIANT_ENUM_CAST(Performance::Monitor);
  114. #endif // PERFORMANCE_H