1 #ifndef EDITORPROFILER_H 2 #define EDITORPROFILER_H 3 4 #include "scene/gui/box_container.h" 5 #include "scene/gui/button.h" 6 #include "scene/gui/label.h" 7 #include "scene/gui/option_button.h" 8 #include "scene/gui/spin_box.h" 9 #include "scene/gui/split_container.h" 10 #include "scene/gui/texture_frame.h" 11 #include "scene/gui/tree.h" 12 13 class EditorProfiler : public VBoxContainer { 14 15 OBJ_TYPE(EditorProfiler, VBoxContainer) 16 17 public: 18 struct Metric { 19 20 bool valid; 21 22 int frame_number; 23 float frame_time; 24 float idle_time; 25 float fixed_time; 26 float fixed_frame_time; 27 28 struct Category { 29 30 StringName signature; 31 String name; 32 float total_time; //total for category 33 34 struct Item { 35 36 StringName signature; 37 String name; 38 String script; 39 int line; 40 float self; 41 float total; 42 int calls; 43 }; 44 45 Vector<Item> items; 46 }; 47 48 Vector<Category> categories; 49 50 Map<StringName, Category *> category_ptrs; 51 Map<StringName, Category::Item *> item_ptrs; 52 MetricMetric53 Metric() { 54 valid = false; 55 frame_number = 0; 56 } 57 }; 58 59 enum DisplayMode { 60 DISPLAY_FRAME_TIME, 61 DISPLAY_AVERAGE_TIME, 62 DISPLAY_FRAME_PERCENT, 63 DISPLAY_FIXED_FRAME_PERCENT, 64 }; 65 66 enum DisplayTime { 67 DISPLAY_TOTAL_TIME, 68 DISPLAY_SELF_TIME, 69 }; 70 71 private: 72 Button *activate; 73 TextureFrame *graph; 74 Ref<ImageTexture> graph_texture; 75 DVector<uint8_t> graph_image; 76 Tree *variables; 77 HSplitContainer *h_split; 78 79 Set<StringName> plot_sigs; 80 81 OptionButton *display_mode; 82 OptionButton *display_time; 83 84 SpinBox *cursor_metric_edit; 85 86 Vector<Metric> frame_metrics; 87 int last_metric; 88 89 int max_functions; 90 91 bool updating_frame; 92 93 //int cursor_metric; 94 int hover_metric; 95 96 float graph_height; 97 98 bool seeking; 99 100 Timer *frame_delay; 101 Timer *plot_delay; 102 103 void _update_frame(); 104 105 void _activate_pressed(); 106 107 String _get_time_as_text(Metric &m, float p_time, int p_calls); 108 109 void _make_metric_ptrs(Metric &m); 110 void _item_edited(); 111 112 void _update_plot(); 113 114 void _graph_tex_mouse_exit(); 115 116 void _graph_tex_draw(); 117 void _graph_tex_input(const InputEvent &p_ev); 118 119 int _get_cursor_index() const; 120 121 Color _get_color_from_signature(const StringName &p_signature) const; 122 123 void _cursor_metric_changed(double); 124 125 void _combo_changed(int); 126 127 protected: 128 void _notification(int p_what); 129 static void _bind_methods(); 130 131 public: 132 void add_frame_metric(const Metric &p_metric, bool p_final = false); 133 void set_enabled(bool p_enable); 134 bool is_profiling(); is_seeking()135 bool is_seeking() { return seeking; } 136 void disable_seeking(); 137 138 void clear(); 139 140 EditorProfiler(); 141 }; 142 143 #endif // EDITORPROFILER_H 144