| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/gui/box_container.h" |
| 34 |
#include "scene/gui/button.h" |
| 35 |
#include "scene/gui/check_button.h" |
| 36 |
#include "scene/gui/label.h" |
| 37 |
#include "scene/gui/option_button.h" |
| 38 |
#include "scene/gui/spin_box.h" |
| 39 |
#include "scene/gui/split_container.h" |
| 40 |
#include "scene/gui/texture_rect.h" |
| 41 |
#include "scene/gui/tree.h" |
| 42 |
|
| 43 |
class ImageTexture; |
| 44 |
|
| 45 |
class EditorProfiler : public VBoxContainer { |
| 46 |
GDCLASS(EditorProfiler, VBoxContainer); |
| 47 |
|
| 48 |
public: |
| 49 |
struct Metric { |
| 50 |
bool valid = false; |
| 51 |
|
| 52 |
int frame_number = 0; |
| 53 |
float frame_time = 0; |
| 54 |
float process_time = 0; |
| 55 |
float physics_time = 0; |
| 56 |
float physics_frame_time = 0; |
| 57 |
|
| 58 |
struct Category { |
| 59 |
StringName signature; |
| 60 |
String name; |
| 61 |
float total_time = 0; |
| 62 |
|
| 63 |
struct Item { |
| 64 |
StringName signature; |
| 65 |
String name; |
| 66 |
String script; |
| 67 |
int line = 0; |
| 68 |
float self = 0; |
| 69 |
float total = 0; |
| 70 |
float internal = 0; |
| 71 |
int calls = 0; |
| 72 |
}; |
| 73 |
|
| 74 |
Vector<Item> items; |
| 75 |
}; |
| 76 |
|
| 77 |
Vector<Category> categories; |
| 78 |
|
| 79 |
HashMap<StringName, Category *> category_ptrs; |
| 80 |
HashMap<StringName, Category::Item *> item_ptrs; |
| 81 |
}; |
| 82 |
|
| 83 |
enum DisplayMode { |
| 84 |
DISPLAY_FRAME_TIME, |
| 85 |
DISPLAY_AVERAGE_TIME, |
| 86 |
DISPLAY_FRAME_PERCENT, |
| 87 |
DISPLAY_PHYSICS_FRAME_PERCENT, |
| 88 |
}; |
| 89 |
|
| 90 |
enum DisplayTime { |
| 91 |
DISPLAY_TOTAL_TIME, |
| 92 |
DISPLAY_SELF_TIME, |
| 93 |
}; |
| 94 |
|
| 95 |
private: |
| 96 |
struct ThemeCache { |
| 97 |
Color seek_line_color; |
| 98 |
Color seek_line_hover_color; |
| 99 |
} theme_cache; |
| 100 |
|
| 101 |
Button *activate = nullptr; |
| 102 |
Button *clear_button = nullptr; |
| 103 |
TextureRect *graph = nullptr; |
| 104 |
Ref<ImageTexture> graph_texture; |
| 105 |
Vector<uint8_t> graph_image; |
| 106 |
|
| 107 |
float graph_zoom = 0.0f; |
| 108 |
float pan_accumulator = 0.0f; |
| 109 |
int zoom_center = -1; |
| 110 |
|
| 111 |
Tree *variables = nullptr; |
| 112 |
HSplitContainer *h_split = nullptr; |
| 113 |
|
| 114 |
HashSet<StringName> plot_sigs; |
| 115 |
|
| 116 |
OptionButton *display_mode = nullptr; |
| 117 |
OptionButton *display_time = nullptr; |
| 118 |
|
| 119 |
CheckButton *display_internal_profiles = nullptr; |
| 120 |
|
| 121 |
SpinBox *cursor_metric_edit = nullptr; |
| 122 |
|
| 123 |
Vector<Metric> frame_metrics; |
| 124 |
int total_metrics = 0; |
| 125 |
int last_metric = -1; |
| 126 |
|
| 127 |
bool updating_frame = false; |
| 128 |
|
| 129 |
int hover_metric = -1; |
| 130 |
|
| 131 |
float graph_height = 1.0f; |
| 132 |
|
| 133 |
bool seeking = false; |
| 134 |
|
| 135 |
Timer *frame_delay = nullptr; |
| 136 |
Timer *plot_delay = nullptr; |
| 137 |
|
| 138 |
void _update_button_text(); |
| 139 |
void _update_frame(); |
| 140 |
|
| 141 |
void _activate_pressed(); |
| 142 |
void _clear_pressed(); |
| 143 |
void _autostart_toggled(bool p_toggled_on); |
| 144 |
|
| 145 |
void _internal_profiles_pressed(); |
| 146 |
|
| 147 |
String _get_time_as_text(const Metric &m, float p_time, int p_calls); |
| 148 |
|
| 149 |
void _make_metric_ptrs(Metric &m); |
| 150 |
void _item_edited(); |
| 151 |
|
| 152 |
void _update_plot(); |
| 153 |
|
| 154 |
void _graph_tex_mouse_exit(); |
| 155 |
|
| 156 |
void _graph_tex_draw(); |
| 157 |
void _graph_tex_input(const Ref<InputEvent> &p_ev); |
| 158 |
|
| 159 |
Color _get_color_from_signature(const StringName &p_signature) const; |
| 160 |
int _get_zoom_left_border() const; |
| 161 |
|
| 162 |
void _cursor_metric_changed(double); |
| 163 |
|
| 164 |
void _combo_changed(int); |
| 165 |
|
| 166 |
Metric _get_frame_metric(int index); |
| 167 |
|
| 168 |
protected: |
| 169 |
void _notification(int p_what); |
| 170 |
static void _bind_methods(); |
| 171 |
|
| 172 |
public: |
| 173 |
void add_frame_metric(const Metric &p_metric, bool p_final = false); |
| 174 |
void set_enabled(bool p_enable, bool p_clear = true); |
| 175 |
void set_profiling(bool p_pressed); |
| 176 |
bool is_profiling(); |
| 177 |
bool is_seeking() { return seeking; } |
| 178 |
void disable_seeking(); |
| 179 |
|
| 180 |
void clear(); |
| 181 |
|
| 182 |
Vector<Vector<String>> get_data_as_csv() const; |
| 183 |
|
| 184 |
EditorProfiler(); |
| 185 |
}; |