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 | |
31 | #ifndef EDITOR_VISUAL_PROFILER_H |
32 | #define EDITOR_VISUAL_PROFILER_H |
33 | |
34 | #include "scene/gui/box_container.h" |
35 | #include "scene/gui/button.h" |
36 | #include "scene/gui/check_box.h" |
37 | #include "scene/gui/label.h" |
38 | #include "scene/gui/option_button.h" |
39 | #include "scene/gui/spin_box.h" |
40 | #include "scene/gui/split_container.h" |
41 | #include "scene/gui/texture_rect.h" |
42 | #include "scene/gui/tree.h" |
43 | |
44 | class ImageTexture; |
45 | |
46 | class EditorVisualProfiler : public VBoxContainer { |
47 | GDCLASS(EditorVisualProfiler, VBoxContainer); |
48 | |
49 | public: |
50 | struct Metric { |
51 | bool valid = false; |
52 | |
53 | uint64_t frame_number = 0; |
54 | |
55 | struct Area { |
56 | String name; |
57 | Color color_cache; |
58 | StringName fullpath_cache; |
59 | float cpu_time = 0; |
60 | float gpu_time = 0; |
61 | }; |
62 | |
63 | Vector<Area> areas; |
64 | }; |
65 | |
66 | enum DisplayTimeMode { |
67 | DISPLAY_FRAME_TIME, |
68 | DISPLAY_FRAME_PERCENT, |
69 | }; |
70 | |
71 | private: |
72 | Button *activate = nullptr; |
73 | Button *clear_button = nullptr; |
74 | |
75 | TextureRect *graph = nullptr; |
76 | Ref<ImageTexture> graph_texture; |
77 | Vector<uint8_t> graph_image; |
78 | Tree *variables = nullptr; |
79 | HSplitContainer *h_split = nullptr; |
80 | CheckBox *frame_relative = nullptr; |
81 | CheckBox *linked = nullptr; |
82 | |
83 | OptionButton *display_mode = nullptr; |
84 | |
85 | SpinBox *cursor_metric_edit = nullptr; |
86 | |
87 | Vector<Metric> frame_metrics; |
88 | int last_metric = -1; |
89 | |
90 | int hover_metric = -1; |
91 | |
92 | StringName selected_area; |
93 | |
94 | bool updating_frame = false; |
95 | |
96 | float graph_height_cpu = 1.0f; |
97 | float graph_height_gpu = 1.0f; |
98 | |
99 | float graph_limit = 1000.0f / 60; |
100 | |
101 | bool seeking = false; |
102 | |
103 | Timer *frame_delay = nullptr; |
104 | Timer *plot_delay = nullptr; |
105 | |
106 | void _update_button_text(); |
107 | |
108 | void _update_frame(bool p_focus_selected = false); |
109 | |
110 | void _activate_pressed(); |
111 | void _clear_pressed(); |
112 | |
113 | String _get_time_as_text(float p_time); |
114 | |
115 | //void _make_metric_ptrs(Metric &m); |
116 | void _item_selected(); |
117 | |
118 | void _update_plot(); |
119 | |
120 | void _graph_tex_mouse_exit(); |
121 | |
122 | void _graph_tex_draw(); |
123 | void _graph_tex_input(const Ref<InputEvent> &p_ev); |
124 | |
125 | int _get_cursor_index() const; |
126 | |
127 | Color _get_color_from_signature(const StringName &p_signature) const; |
128 | |
129 | void _cursor_metric_changed(double); |
130 | |
131 | void _combo_changed(int); |
132 | |
133 | protected: |
134 | void _notification(int p_what); |
135 | static void _bind_methods(); |
136 | |
137 | public: |
138 | void add_frame_metric(const Metric &p_metric); |
139 | void set_enabled(bool p_enable); |
140 | void set_pressed(bool p_pressed); |
141 | bool is_profiling(); |
142 | bool is_seeking() { return seeking; } |
143 | void disable_seeking(); |
144 | |
145 | void clear(); |
146 | |
147 | Vector<Vector<String>> get_data_as_csv() const; |
148 | |
149 | EditorVisualProfiler(); |
150 | }; |
151 | |
152 | #endif // EDITOR_VISUAL_PROFILER_H |
153 | |