editor_visual_profiler.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*************************************************************************/
  2. /* editor_visual_profiler.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 EDITOR_FRAME_PROFILER_H
  31. #define EDITOR_FRAME_PROFILER_H
  32. #include "scene/gui/box_container.h"
  33. #include "scene/gui/button.h"
  34. #include "scene/gui/check_box.h"
  35. #include "scene/gui/label.h"
  36. #include "scene/gui/option_button.h"
  37. #include "scene/gui/spin_box.h"
  38. #include "scene/gui/split_container.h"
  39. #include "scene/gui/texture_rect.h"
  40. #include "scene/gui/tree.h"
  41. class EditorVisualProfiler : public VBoxContainer {
  42. GDCLASS(EditorVisualProfiler, VBoxContainer);
  43. public:
  44. struct Metric {
  45. bool valid = false;
  46. uint64_t frame_number = 0;
  47. struct Area {
  48. String name;
  49. Color color_cache;
  50. StringName fullpath_cache;
  51. float cpu_time = 0;
  52. float gpu_time = 0;
  53. };
  54. Vector<Area> areas;
  55. };
  56. enum DisplayTimeMode {
  57. DISPLAY_FRAME_TIME,
  58. DISPLAY_FRAME_PERCENT,
  59. };
  60. private:
  61. Button *activate = nullptr;
  62. Button *clear_button = nullptr;
  63. TextureRect *graph = nullptr;
  64. Ref<ImageTexture> graph_texture;
  65. Vector<uint8_t> graph_image;
  66. Tree *variables = nullptr;
  67. HSplitContainer *h_split = nullptr;
  68. CheckBox *frame_relative = nullptr;
  69. CheckBox *linked = nullptr;
  70. OptionButton *display_mode = nullptr;
  71. SpinBox *cursor_metric_edit = nullptr;
  72. Vector<Metric> frame_metrics;
  73. int last_metric = -1;
  74. int hover_metric = -1;
  75. StringName selected_area;
  76. bool updating_frame = false;
  77. float graph_height_cpu = 1.0f;
  78. float graph_height_gpu = 1.0f;
  79. float graph_limit = 1000.0f / 60;
  80. bool seeking = false;
  81. Timer *frame_delay = nullptr;
  82. Timer *plot_delay = nullptr;
  83. void _update_frame(bool p_focus_selected = false);
  84. void _activate_pressed();
  85. void _clear_pressed();
  86. String _get_time_as_text(float p_time);
  87. //void _make_metric_ptrs(Metric &m);
  88. void _item_selected();
  89. void _update_plot();
  90. void _graph_tex_mouse_exit();
  91. void _graph_tex_draw();
  92. void _graph_tex_input(const Ref<InputEvent> &p_ev);
  93. int _get_cursor_index() const;
  94. Color _get_color_from_signature(const StringName &p_signature) const;
  95. void _cursor_metric_changed(double);
  96. void _combo_changed(int);
  97. protected:
  98. void _notification(int p_what);
  99. static void _bind_methods();
  100. public:
  101. void add_frame_metric(const Metric &p_metric);
  102. void set_enabled(bool p_enable);
  103. bool is_profiling();
  104. bool is_seeking() { return seeking; }
  105. void disable_seeking();
  106. void clear();
  107. Vector<Vector<String>> get_data_as_csv() const;
  108. EditorVisualProfiler();
  109. };
  110. #endif // EDITOR_FRAME_PROFILER_H