| 1 | /**************************************************************************/ |
| 2 | /* servers_debugger.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 SERVERS_DEBUGGER_H |
| 32 | #define SERVERS_DEBUGGER_H |
| 33 | |
| 34 | #include "core/debugger/debugger_marshalls.h" |
| 35 | |
| 36 | #include "servers/rendering_server.h" |
| 37 | |
| 38 | class ServersDebugger { |
| 39 | public: |
| 40 | // Memory usage |
| 41 | struct ResourceInfo { |
| 42 | String path; |
| 43 | String format; |
| 44 | String type; |
| 45 | RID id; |
| 46 | int vram = 0; |
| 47 | bool operator<(const ResourceInfo &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; } |
| 48 | }; |
| 49 | |
| 50 | struct ResourceUsage { |
| 51 | List<ResourceInfo> infos; |
| 52 | |
| 53 | Array serialize(); |
| 54 | bool deserialize(const Array &p_arr); |
| 55 | }; |
| 56 | |
| 57 | // Script Profiler |
| 58 | struct ScriptFunctionSignature { |
| 59 | StringName name; |
| 60 | int id = -1; |
| 61 | |
| 62 | Array serialize(); |
| 63 | bool deserialize(const Array &p_arr); |
| 64 | }; |
| 65 | |
| 66 | struct ScriptFunctionInfo { |
| 67 | StringName name; |
| 68 | int sig_id = -1; |
| 69 | int call_count = 0; |
| 70 | double self_time = 0; |
| 71 | double total_time = 0; |
| 72 | }; |
| 73 | |
| 74 | // Servers profiler |
| 75 | struct ServerFunctionInfo { |
| 76 | StringName name; |
| 77 | double time = 0; |
| 78 | }; |
| 79 | |
| 80 | struct ServerInfo { |
| 81 | StringName name; |
| 82 | List<ServerFunctionInfo> functions; |
| 83 | }; |
| 84 | |
| 85 | struct ServersProfilerFrame { |
| 86 | int frame_number = 0; |
| 87 | double frame_time = 0; |
| 88 | double process_time = 0; |
| 89 | double physics_time = 0; |
| 90 | double physics_frame_time = 0; |
| 91 | double script_time = 0; |
| 92 | List<ServerInfo> servers; |
| 93 | Vector<ScriptFunctionInfo> script_functions; |
| 94 | |
| 95 | Array serialize(); |
| 96 | bool deserialize(const Array &p_arr); |
| 97 | }; |
| 98 | |
| 99 | // Visual Profiler |
| 100 | struct VisualProfilerFrame { |
| 101 | uint64_t frame_number = 0; |
| 102 | Vector<RS::FrameProfileArea> areas; |
| 103 | |
| 104 | Array serialize(); |
| 105 | bool deserialize(const Array &p_arr); |
| 106 | }; |
| 107 | |
| 108 | private: |
| 109 | class ScriptsProfiler; |
| 110 | class ServersProfiler; |
| 111 | class VisualProfiler; |
| 112 | |
| 113 | double last_draw_time = 0.0; |
| 114 | Ref<ServersProfiler> servers_profiler; |
| 115 | Ref<VisualProfiler> visual_profiler; |
| 116 | |
| 117 | static ServersDebugger *singleton; |
| 118 | |
| 119 | static Error _capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured); |
| 120 | |
| 121 | void _send_resource_usage(); |
| 122 | |
| 123 | ServersDebugger(); |
| 124 | |
| 125 | public: |
| 126 | static void initialize(); |
| 127 | static void deinitialize(); |
| 128 | |
| 129 | ~ServersDebugger(); |
| 130 | }; |
| 131 | |
| 132 | #endif // SERVERS_DEBUGGER_H |
| 133 | |