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