2
0
Эх сурвалжийг харах

Merge pull request #96759 from Geometror/implement-autostart-profilers

Implement autostart for all profilers
Rémi Verschelde 1 жил өмнө
parent
commit
97843116f6

+ 15 - 3
editor/debugger/editor_profiler.cpp

@@ -35,6 +35,7 @@
 #include "editor/editor_string_names.h"
 #include "editor/themes/editor_scale.h"
 #include "editor/themes/editor_theme_manager.h"
+#include "scene/gui/check_box.h"
 #include "scene/resources/image_texture.h"
 
 void EditorProfiler::_make_metric_ptrs(Metric &m) {
@@ -177,8 +178,8 @@ void EditorProfiler::_item_edited() {
 }
 
 void EditorProfiler::_update_plot() {
-	const int w = graph->get_size().width;
-	const int h = graph->get_size().height;
+	const int w = MAX(1, graph->get_size().width); // Clamp to 1 to prevent from crashing when profiler is autostarted.
+	const int h = MAX(1, graph->get_size().height);
 	bool reset_texture = false;
 	const int desired_len = w * h * 4;
 
@@ -416,6 +417,10 @@ void EditorProfiler::_internal_profiles_pressed() {
 	_combo_changed(0);
 }
 
+void EditorProfiler::_autostart_toggled(bool p_toggled_on) {
+	EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_profiler", p_toggled_on);
+}
+
 void EditorProfiler::_notification(int p_what) {
 	switch (p_what) {
 		case NOTIFICATION_ENTER_TREE:
@@ -539,9 +544,10 @@ void EditorProfiler::set_enabled(bool p_enable, bool p_clear) {
 	}
 }
 
-void EditorProfiler::set_pressed(bool p_pressed) {
+void EditorProfiler::set_profiling(bool p_pressed) {
 	activate->set_pressed(p_pressed);
 	_update_button_text();
+	emit_signal(SNAME("enable_profiling"), activate->is_pressed());
 }
 
 bool EditorProfiler::is_profiling() {
@@ -633,6 +639,12 @@ EditorProfiler::EditorProfiler() {
 	clear_button->set_disabled(true);
 	hb->add_child(clear_button);
 
+	CheckBox *autostart_checkbox = memnew(CheckBox);
+	autostart_checkbox->set_text(TTR("Autostart"));
+	autostart_checkbox->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false));
+	autostart_checkbox->connect(SceneStringName(toggled), callable_mp(this, &EditorProfiler::_autostart_toggled));
+	hb->add_child(autostart_checkbox);
+
 	hb->add_child(memnew(Label(TTR("Measure:"))));
 
 	display_mode = memnew(OptionButton);

+ 2 - 1
editor/debugger/editor_profiler.h

@@ -138,6 +138,7 @@ private:
 
 	void _activate_pressed();
 	void _clear_pressed();
+	void _autostart_toggled(bool p_toggled_on);
 
 	void _internal_profiles_pressed();
 
@@ -168,7 +169,7 @@ protected:
 public:
 	void add_frame_metric(const Metric &p_metric, bool p_final = false);
 	void set_enabled(bool p_enable, bool p_clear = true);
-	void set_pressed(bool p_pressed);
+	void set_profiling(bool p_pressed);
 	bool is_profiling();
 	bool is_seeking() { return seeking; }
 	void disable_seeking();

+ 15 - 4
editor/debugger/editor_visual_profiler.cpp

@@ -148,8 +148,8 @@ void EditorVisualProfiler::_item_selected() {
 }
 
 void EditorVisualProfiler::_update_plot() {
-	const int w = graph->get_size().width;
-	const int h = graph->get_size().height;
+	const int w = graph->get_size().width + 1; // `+1` is to prevent from crashing when visual profiler is auto started.
+	const int h = graph->get_size().height + 1;
 
 	bool reset_texture = false;
 
@@ -427,6 +427,10 @@ void EditorVisualProfiler::_clear_pressed() {
 	_update_plot();
 }
 
+void EditorVisualProfiler::_autostart_toggled(bool p_toggled_on) {
+	EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_visual_profiler", p_toggled_on);
+}
+
 void EditorVisualProfiler::_notification(int p_what) {
 	switch (p_what) {
 		case NOTIFICATION_ENTER_TREE:
@@ -668,9 +672,10 @@ void EditorVisualProfiler::set_enabled(bool p_enable) {
 	activate->set_disabled(!p_enable);
 }
 
-void EditorVisualProfiler::set_pressed(bool p_pressed) {
-	activate->set_pressed(p_pressed);
+void EditorVisualProfiler::set_profiling(bool p_profiling) {
+	activate->set_pressed(p_profiling);
 	_update_button_text();
+	emit_signal(SNAME("enable_profiling"), activate->is_pressed());
 }
 
 bool EditorVisualProfiler::is_profiling() {
@@ -747,6 +752,12 @@ EditorVisualProfiler::EditorVisualProfiler() {
 	clear_button->connect(SceneStringName(pressed), callable_mp(this, &EditorVisualProfiler::_clear_pressed));
 	hb->add_child(clear_button);
 
+	CheckBox *autostart_checkbox = memnew(CheckBox);
+	autostart_checkbox->set_text(TTR("Autostart"));
+	autostart_checkbox->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false));
+	autostart_checkbox->connect(SceneStringName(toggled), callable_mp(this, &EditorVisualProfiler::_autostart_toggled));
+	hb->add_child(autostart_checkbox);
+
 	hb->add_child(memnew(Label(TTR("Measure:"))));
 
 	display_mode = memnew(OptionButton);

+ 2 - 1
editor/debugger/editor_visual_profiler.h

@@ -109,6 +109,7 @@ private:
 
 	void _activate_pressed();
 	void _clear_pressed();
+	void _autostart_toggled(bool p_toggled_on);
 
 	String _get_time_as_text(float p_time);
 
@@ -137,7 +138,7 @@ protected:
 public:
 	void add_frame_metric(const Metric &p_metric);
 	void set_enabled(bool p_enable);
-	void set_pressed(bool p_pressed);
+	void set_profiling(bool p_profiling);
 	bool is_profiling();
 	bool is_seeking() { return seeking; }
 	void disable_seeking();

+ 10 - 2
editor/debugger/script_editor_debugger.cpp

@@ -1012,6 +1012,14 @@ void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) {
 	_set_reason_text(TTR("Debug session started."), MESSAGE_SUCCESS);
 	_update_buttons_state();
 	emit_signal(SNAME("started"));
+
+	if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false)) {
+		profiler->set_profiling(true);
+	}
+
+	if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false)) {
+		visual_profiler->set_profiling(true);
+	}
 }
 
 void ScriptEditorDebugger::_update_buttons_state() {
@@ -1076,10 +1084,10 @@ void ScriptEditorDebugger::stop() {
 	profiler_signature.clear();
 
 	profiler->set_enabled(false, false);
-	profiler->set_pressed(false);
+	profiler->set_profiling(false);
 
 	visual_profiler->set_enabled(false);
-	visual_profiler->set_pressed(false);
+	visual_profiler->set_profiling(false);
 
 	inspector->edit(nullptr);
 	_update_buttons_state();

+ 39 - 1
modules/multiplayer/editor/editor_network_profiler.cpp

@@ -34,6 +34,7 @@
 #include "editor/editor_settings.h"
 #include "editor/editor_string_names.h"
 #include "editor/themes/editor_scale.h"
+#include "scene/gui/check_box.h"
 
 void EditorNetworkProfiler::_bind_methods() {
 	ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable")));
@@ -170,15 +171,42 @@ void EditorNetworkProfiler::add_node_data(const NodeInfo &p_info) {
 }
 
 void EditorNetworkProfiler::_activate_pressed() {
+	_update_button_text();
+
 	if (activate->is_pressed()) {
 		refresh_timer->start();
+	} else {
+		refresh_timer->stop();
+	}
+
+	emit_signal(SNAME("enable_profiling"), activate->is_pressed());
+}
+
+void EditorNetworkProfiler::_update_button_text() {
+	if (activate->is_pressed()) {
 		activate->set_icon(theme_cache.stop_icon);
 		activate->set_text(TTR("Stop"));
 	} else {
-		refresh_timer->stop();
 		activate->set_icon(theme_cache.play_icon);
 		activate->set_text(TTR("Start"));
 	}
+}
+
+void EditorNetworkProfiler::started() {
+	if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_network_profiler", false)) {
+		set_profiling(true);
+		refresh_timer->start();
+	}
+}
+
+void EditorNetworkProfiler::stopped() {
+	set_profiling(false);
+	refresh_timer->stop();
+}
+
+void EditorNetworkProfiler::set_profiling(bool p_pressed) {
+	activate->set_pressed(p_pressed);
+	_update_button_text();
 	emit_signal(SNAME("enable_profiling"), activate->is_pressed());
 }
 
@@ -192,6 +220,10 @@ void EditorNetworkProfiler::_clear_pressed() {
 	refresh_replication_data();
 }
 
+void EditorNetworkProfiler::_autostart_toggled(bool p_toggled_on) {
+	EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_network_profiler", p_toggled_on);
+}
+
 void EditorNetworkProfiler::_replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button) {
 	if (!p_item) {
 		return;
@@ -268,6 +300,12 @@ EditorNetworkProfiler::EditorNetworkProfiler() {
 	clear_button->connect(SceneStringName(pressed), callable_mp(this, &EditorNetworkProfiler::_clear_pressed));
 	hb->add_child(clear_button);
 
+	CheckBox *autostart_checkbox = memnew(CheckBox);
+	autostart_checkbox->set_text(TTR("Autostart"));
+	autostart_checkbox->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_network_profiler", false));
+	autostart_checkbox->connect(SceneStringName(toggled), callable_mp(this, &EditorNetworkProfiler::_autostart_toggled));
+	hb->add_child(autostart_checkbox);
+
 	hb->add_spacer();
 
 	Label *lb = memnew(Label);

+ 6 - 0
modules/multiplayer/editor/editor_network_profiler.h

@@ -92,7 +92,9 @@ private:
 
 	void _activate_pressed();
 	void _clear_pressed();
+	void _autostart_toggled(bool p_toggled_on);
 	void _refresh();
+	void _update_button_text();
 	void _replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button);
 
 protected:
@@ -112,6 +114,10 @@ public:
 	void set_bandwidth(int p_incoming, int p_outgoing);
 	bool is_profiling();
 
+	void set_profiling(bool p_pressed);
+	void started();
+	void stopped();
+
 	EditorNetworkProfiler();
 };
 

+ 2 - 0
modules/multiplayer/editor/multiplayer_editor_plugin.cpp

@@ -106,6 +106,8 @@ void MultiplayerEditorDebugger::setup_session(int p_session_id) {
 	profiler->connect("enable_profiling", callable_mp(this, &MultiplayerEditorDebugger::_profiler_activate).bind(p_session_id));
 	profiler->connect("open_request", callable_mp(this, &MultiplayerEditorDebugger::_open_request));
 	profiler->set_name(TTR("Network Profiler"));
+	session->connect("started", callable_mp(profiler, &EditorNetworkProfiler::started));
+	session->connect("stopped", callable_mp(profiler, &EditorNetworkProfiler::stopped));
 	session->add_session_tab(profiler);
 	profilers[p_session_id] = profiler;
 }