performance.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*************************************************************************/
  2. /* performance.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. class MonitorCall {
  46. Callable _callable;
  47. Vector<Variant> _arguments;
  48. public:
  49. MonitorCall(Callable p_callable, Vector<Variant> p_arguments);
  50. MonitorCall();
  51. Variant call(bool &r_error, String &r_error_message);
  52. };
  53. HashMap<StringName, MonitorCall> _monitor_map;
  54. uint64_t _monitor_modification_time;
  55. public:
  56. enum Monitor {
  57. TIME_FPS,
  58. TIME_PROCESS,
  59. TIME_PHYSICS_PROCESS,
  60. MEMORY_STATIC,
  61. MEMORY_STATIC_MAX,
  62. MEMORY_MESSAGE_BUFFER_MAX,
  63. OBJECT_COUNT,
  64. OBJECT_RESOURCE_COUNT,
  65. OBJECT_NODE_COUNT,
  66. OBJECT_ORPHAN_NODE_COUNT,
  67. RENDER_TOTAL_OBJECTS_IN_FRAME,
  68. RENDER_TOTAL_PRIMITIVES_IN_FRAME,
  69. RENDER_TOTAL_DRAW_CALLS_IN_FRAME,
  70. RENDER_VIDEO_MEM_USED,
  71. RENDER_TEXTURE_MEM_USED,
  72. RENDER_BUFFER_MEM_USED,
  73. PHYSICS_2D_ACTIVE_OBJECTS,
  74. PHYSICS_2D_COLLISION_PAIRS,
  75. PHYSICS_2D_ISLAND_COUNT,
  76. PHYSICS_3D_ACTIVE_OBJECTS,
  77. PHYSICS_3D_COLLISION_PAIRS,
  78. PHYSICS_3D_ISLAND_COUNT,
  79. AUDIO_OUTPUT_LATENCY,
  80. MONITOR_MAX
  81. };
  82. enum MonitorType {
  83. MONITOR_TYPE_QUANTITY,
  84. MONITOR_TYPE_MEMORY,
  85. MONITOR_TYPE_TIME
  86. };
  87. double get_monitor(Monitor p_monitor) const;
  88. String get_monitor_name(Monitor p_monitor) const;
  89. MonitorType get_monitor_type(Monitor p_monitor) const;
  90. void set_process_time(double p_pt);
  91. void set_physics_process_time(double p_pt);
  92. void add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args);
  93. void remove_custom_monitor(const StringName &p_id);
  94. bool has_custom_monitor(const StringName &p_id);
  95. Variant get_custom_monitor(const StringName &p_id);
  96. TypedArray<StringName> get_custom_monitor_names();
  97. uint64_t get_monitor_modification_time();
  98. static Performance *get_singleton() { return singleton; }
  99. Performance();
  100. };
  101. VARIANT_ENUM_CAST(Performance::Monitor);
  102. #endif // PERFORMANCE_H