servers_debugger.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. double internal_time = 0;
  64. };
  65. // Servers profiler
  66. struct ServerFunctionInfo {
  67. StringName name;
  68. double time = 0;
  69. };
  70. struct ServerInfo {
  71. StringName name;
  72. List<ServerFunctionInfo> functions;
  73. };
  74. struct ServersProfilerFrame {
  75. int frame_number = 0;
  76. double frame_time = 0;
  77. double process_time = 0;
  78. double physics_time = 0;
  79. double physics_frame_time = 0;
  80. double script_time = 0;
  81. List<ServerInfo> servers;
  82. Vector<ScriptFunctionInfo> script_functions;
  83. Array serialize();
  84. bool deserialize(const Array &p_arr);
  85. };
  86. // Visual Profiler
  87. struct VisualProfilerFrame {
  88. uint64_t frame_number = 0;
  89. Vector<RS::FrameProfileArea> areas;
  90. Array serialize();
  91. bool deserialize(const Array &p_arr);
  92. };
  93. private:
  94. class ScriptsProfiler;
  95. class ServersProfiler;
  96. class VisualProfiler;
  97. double last_draw_time = 0.0;
  98. Ref<ServersProfiler> servers_profiler;
  99. Ref<VisualProfiler> visual_profiler;
  100. static ServersDebugger *singleton;
  101. static Error _capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured);
  102. void _send_resource_usage();
  103. ServersDebugger();
  104. public:
  105. static void initialize();
  106. static void deinitialize();
  107. ~ServersDebugger();
  108. };
  109. #endif // SERVERS_DEBUGGER_H