servers_debugger.h 4.2 KB

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