Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Autostart Feature on Profiler / Visual Profiler / Network Profiler #70766

Closed
wants to merge 8 commits into from
17 changes: 15 additions & 2 deletions editor/debugger/editor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,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;

Expand Down Expand Up @@ -415,6 +415,10 @@ void EditorProfiler::_internal_profiles_pressed() {
_combo_changed(0);
}

void EditorProfiler::_autostart_pressed() {
EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_profiler", autostart_button->is_pressed());
}

void EditorProfiler::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
Expand All @@ -423,6 +427,7 @@ void EditorProfiler::_notification(int p_what) {
case NOTIFICATION_TRANSLATION_CHANGED: {
activate->set_icon(get_editor_theme_icon(SNAME("Play")));
clear_button->set_icon(get_editor_theme_icon(SNAME("Clear")));
autostart_button->set_icon(get_editor_theme_icon(SNAME("AutoPlay")));
} break;
}
}
Expand Down Expand Up @@ -532,6 +537,7 @@ void EditorProfiler::set_enabled(bool p_enable, bool p_clear) {
void EditorProfiler::set_pressed(bool p_pressed) {
activate->set_pressed(p_pressed);
_update_button_text();
emit_signal(SNAME("enable_profiling"), activate->is_pressed());
}

bool EditorProfiler::is_profiling() {
Expand Down Expand Up @@ -623,6 +629,13 @@ EditorProfiler::EditorProfiler() {
clear_button->set_disabled(true);
hb->add_child(clear_button);

autostart_button = memnew(Button);
autostart_button->set_toggle_mode(true);
autostart_button->set_text(TTR("Autostart"));
autostart_button->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_profiler", false));
autostart_button->connect("pressed", callable_mp(this, &EditorProfiler::_autostart_pressed));
hb->add_child(autostart_button);

hb->add_child(memnew(Label(TTR("Measure:"))));

display_mode = memnew(OptionButton);
Expand Down
2 changes: 2 additions & 0 deletions editor/debugger/editor_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class EditorProfiler : public VBoxContainer {
private:
Button *activate = nullptr;
Button *clear_button = nullptr;
Button *autostart_button = nullptr;
TextureRect *graph = nullptr;
Ref<ImageTexture> graph_texture;
Vector<uint8_t> graph_image;
Expand Down Expand Up @@ -133,6 +134,7 @@ class EditorProfiler : public VBoxContainer {

void _activate_pressed();
void _clear_pressed();
void _autostart_pressed();

void _internal_profiles_pressed();

Expand Down
17 changes: 15 additions & 2 deletions editor/debugger/editor_visual_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,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;

Expand Down Expand Up @@ -425,6 +425,10 @@ void EditorVisualProfiler::_clear_pressed() {
_update_plot();
}

void EditorVisualProfiler::_autostart_pressed() {
EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_visual_profiler", autostart_button->is_pressed());
}

void EditorVisualProfiler::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
Expand All @@ -437,6 +441,7 @@ void EditorVisualProfiler::_notification(int p_what) {
activate->set_icon(get_editor_theme_icon(SNAME("Play")));
}
clear_button->set_icon(get_editor_theme_icon(SNAME("Clear")));
autostart_button->set_icon(get_editor_theme_icon(SNAME("AutoPlay")));
} break;
}
}
Expand Down Expand Up @@ -669,6 +674,7 @@ void EditorVisualProfiler::set_enabled(bool p_enable) {
void EditorVisualProfiler::set_pressed(bool p_pressed) {
activate->set_pressed(p_pressed);
_update_button_text();
emit_signal(SNAME("enable_profiling"), activate->is_pressed());
}

bool EditorVisualProfiler::is_profiling() {
Expand Down Expand Up @@ -745,6 +751,13 @@ EditorVisualProfiler::EditorVisualProfiler() {
clear_button->connect("pressed", callable_mp(this, &EditorVisualProfiler::_clear_pressed));
hb->add_child(clear_button);

autostart_button = memnew(Button);
autostart_button->set_toggle_mode(true);
autostart_button->set_text(TTR("Autostart"));
autostart_button->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false));
autostart_button->connect("pressed", callable_mp(this, &EditorVisualProfiler::_autostart_pressed));
hb->add_child(autostart_button);

hb->add_child(memnew(Label(TTR("Measure:"))));

display_mode = memnew(OptionButton);
Expand Down
2 changes: 2 additions & 0 deletions editor/debugger/editor_visual_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class EditorVisualProfiler : public VBoxContainer {
private:
Button *activate = nullptr;
Button *clear_button = nullptr;
Button *autostart_button = nullptr;

TextureRect *graph = nullptr;
Ref<ImageTexture> graph_texture;
Expand Down Expand Up @@ -109,6 +110,7 @@ class EditorVisualProfiler : public VBoxContainer {

void _activate_pressed();
void _clear_pressed();
void _autostart_pressed();

String _get_time_as_text(float p_time);

Expand Down
10 changes: 10 additions & 0 deletions editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,16 @@ 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)) {
tabs->set_current_tab(2);
profiler->set_pressed(true); // activate profiler
}

if (EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_visual_profiler", false)) {
tabs->set_current_tab(3);
visual_profiler->set_pressed(true); // activate visual profiler
}
}

void ScriptEditorDebugger::_update_buttons_state() {
Expand Down
45 changes: 44 additions & 1 deletion modules/multiplayer/editor/editor_network_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void EditorNetworkProfiler::_bind_methods() {

void EditorNetworkProfiler::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
if (activate->is_pressed()) {
activate->set_icon(theme_cache.stop_icon);
Expand All @@ -53,6 +54,8 @@ void EditorNetworkProfiler::_notification(int p_what) {
incoming_bandwidth_text->set_right_icon(theme_cache.incoming_bandwidth_icon);
outgoing_bandwidth_text->set_right_icon(theme_cache.outgoing_bandwidth_icon);

autostart_button->set_icon(theme_cache.autoplay_profiler_icon);

// This needs to be done here to set the faded color when the profiler is first opened
incoming_bandwidth_text->add_theme_color_override("font_uneditable_color", theme_cache.incoming_bandwidth_color * Color(1, 1, 1, 0.5));
outgoing_bandwidth_text->add_theme_color_override("font_uneditable_color", theme_cache.outgoing_bandwidth_color * Color(1, 1, 1, 0.5));
Expand All @@ -76,6 +79,8 @@ void EditorNetworkProfiler::_update_theme_item_cache() {

theme_cache.incoming_bandwidth_color = get_theme_color(SNAME("font_color"), EditorStringName(Editor));
theme_cache.outgoing_bandwidth_color = get_theme_color(SNAME("font_color"), EditorStringName(Editor));

theme_cache.autoplay_profiler_icon = get_editor_theme_icon(SNAME("AutoPlay"));
}

void EditorNetworkProfiler::_refresh() {
Expand Down Expand Up @@ -170,15 +175,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_pressed(true);
refresh_timer->start();
}
}

void EditorNetworkProfiler::stopped() {
set_pressed(false);
refresh_timer->stop();
}

void EditorNetworkProfiler::set_pressed(bool p_pressed) {
activate->set_pressed(p_pressed);
_update_button_text();
emit_signal(SNAME("enable_profiling"), activate->is_pressed());
}

Expand All @@ -192,6 +224,10 @@ void EditorNetworkProfiler::_clear_pressed() {
refresh_replication_data();
}

void EditorNetworkProfiler::_autostart_pressed() {
EditorSettings::get_singleton()->set_project_metadata("debug_options", "autostart_network_profiler", autostart_button->is_pressed());
}

void EditorNetworkProfiler::_replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button) {
if (!p_item) {
return;
Expand Down Expand Up @@ -268,6 +304,13 @@ EditorNetworkProfiler::EditorNetworkProfiler() {
clear_button->connect("pressed", callable_mp(this, &EditorNetworkProfiler::_clear_pressed));
hb->add_child(clear_button);

autostart_button = memnew(Button);
autostart_button->set_toggle_mode(true);
autostart_button->set_text(TTR("Autostart"));
autostart_button->set_pressed(EditorSettings::get_singleton()->get_project_metadata("debug_options", "autostart_network_profiler", false));
autostart_button->connect("pressed", callable_mp(this, &EditorNetworkProfiler::_autostart_pressed));
hb->add_child(autostart_button);

hb->add_spacer();

Label *lb = memnew(Label);
Expand Down
11 changes: 11 additions & 0 deletions modules/multiplayer/editor/editor_network_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ class EditorNetworkProfiler : public VBoxContainer {

bool dirty = false;
Timer *refresh_timer = nullptr;

Button *activate = nullptr;
Button *clear_button = nullptr;
Button *autostart_button = nullptr;

Tree *counters_display = nullptr;
LineEdit *incoming_bandwidth_text = nullptr;
LineEdit *outgoing_bandwidth_text = nullptr;
Expand All @@ -86,13 +89,17 @@ class EditorNetworkProfiler : public VBoxContainer {
Ref<Texture2D> incoming_bandwidth_icon;
Ref<Texture2D> outgoing_bandwidth_icon;

Ref<Texture2D> autoplay_profiler_icon;

Color incoming_bandwidth_color;
Color outgoing_bandwidth_color;
} theme_cache;

void _activate_pressed();
void _clear_pressed();
void _autostart_pressed();
void _refresh();
void _update_button_text();
void _replication_button_clicked(TreeItem *p_item, int p_column, int p_idx, MouseButton p_button);

protected:
Expand All @@ -112,6 +119,10 @@ class EditorNetworkProfiler : public VBoxContainer {
void set_bandwidth(int p_incoming, int p_outgoing);
bool is_profiling();

void set_pressed(bool p_pressed);
void started();
void stopped();

EditorNetworkProfiler();
};

Expand Down
2 changes: 2 additions & 0 deletions modules/multiplayer/editor/multiplayer_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading