servers_debugger.h 4.1 KB

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