editor_visual_profiler.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**************************************************************************/
  2. /* editor_visual_profiler.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 EDITOR_VISUAL_PROFILER_H
  31. #define EDITOR_VISUAL_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 ImageTexture;
  42. class EditorVisualProfiler : public VBoxContainer {
  43. GDCLASS(EditorVisualProfiler, VBoxContainer);
  44. public:
  45. struct Metric {
  46. bool valid = false;
  47. uint64_t frame_number = 0;
  48. struct Area {
  49. String name;
  50. Color color_cache;
  51. StringName fullpath_cache;
  52. float cpu_time = 0;
  53. float gpu_time = 0;
  54. };
  55. Vector<Area> areas;
  56. };
  57. enum DisplayTimeMode {
  58. DISPLAY_FRAME_TIME,
  59. DISPLAY_FRAME_PERCENT,
  60. };
  61. private:
  62. Button *activate = nullptr;
  63. Button *clear_button = nullptr;
  64. TextureRect *graph = nullptr;
  65. Ref<ImageTexture> graph_texture;
  66. Vector<uint8_t> graph_image;
  67. Tree *variables = nullptr;
  68. HSplitContainer *h_split = nullptr;
  69. CheckBox *frame_relative = nullptr;
  70. CheckBox *linked = nullptr;
  71. OptionButton *display_mode = nullptr;
  72. SpinBox *cursor_metric_edit = nullptr;
  73. Vector<Metric> frame_metrics;
  74. int last_metric = -1;
  75. int hover_metric = -1;
  76. StringName selected_area;
  77. bool updating_frame = false;
  78. float graph_height_cpu = 1.0f;
  79. float graph_height_gpu = 1.0f;
  80. float graph_limit = 1000.0f / 60;
  81. bool seeking = false;
  82. Timer *frame_delay = nullptr;
  83. Timer *plot_delay = nullptr;
  84. void _update_button_text();
  85. void _update_frame(bool p_focus_selected = false);
  86. void _activate_pressed();
  87. void _clear_pressed();
  88. void _autostart_toggled(bool p_toggled_on);
  89. String _get_time_as_text(float p_time);
  90. //void _make_metric_ptrs(Metric &m);
  91. void _item_selected();
  92. void _update_plot();
  93. void _graph_tex_mouse_exit();
  94. void _graph_tex_draw();
  95. void _graph_tex_input(const Ref<InputEvent> &p_ev);
  96. int _get_cursor_index() const;
  97. Color _get_color_from_signature(const StringName &p_signature) const;
  98. void _cursor_metric_changed(double);
  99. void _combo_changed(int);
  100. protected:
  101. void _notification(int p_what);
  102. static void _bind_methods();
  103. public:
  104. void add_frame_metric(const Metric &p_metric);
  105. void set_enabled(bool p_enable);
  106. void set_profiling(bool p_profiling);
  107. bool is_profiling();
  108. bool is_seeking() { return seeking; }
  109. void disable_seeking();
  110. void clear();
  111. Vector<Vector<String>> get_data_as_csv() const;
  112. EditorVisualProfiler();
  113. };
  114. #endif // EDITOR_VISUAL_PROFILER_H