Skip to content

Commit

Permalink
Merge pull request #70151 from stmSi/fix-profiler-and-visual-profiler…
Browse files Browse the repository at this point in the history
…-start-stop-state-inconsistency

Fix: Profiler and Visual Profiler start/stop state inconsistency
  • Loading branch information
akien-mga committed Dec 23, 2022
2 parents ecd895a + 97e9919 commit 6ff74f0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
13 changes: 9 additions & 4 deletions editor/debugger/editor_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void EditorProfiler::clear() {
seeking = false;

// Ensure button text (start, stop) is correct
_set_button_text();
_update_button_text();
emit_signal(SNAME("enable_profiling"), activate->is_pressed());
}

Expand Down Expand Up @@ -376,7 +376,7 @@ void EditorProfiler::_update_frame() {
updating_frame = false;
}

void EditorProfiler::_set_button_text() {
void EditorProfiler::_update_button_text() {
if (activate->is_pressed()) {
activate->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));
activate->set_text(TTR("Stop"));
Expand All @@ -387,7 +387,7 @@ void EditorProfiler::_set_button_text() {
}

void EditorProfiler::_activate_pressed() {
_set_button_text();
_update_button_text();

if (activate->is_pressed()) {
_clear_pressed();
Expand Down Expand Up @@ -510,13 +510,17 @@ void EditorProfiler::_bind_methods() {
}

void EditorProfiler::set_enabled(bool p_enable, bool p_clear) {
activate->set_pressed(false);
activate->set_disabled(!p_enable);
if (p_clear) {
clear();
}
}

void EditorProfiler::set_pressed(bool p_pressed) {
activate->set_pressed(p_pressed);
_update_button_text();
}

bool EditorProfiler::is_profiling() {
return activate->is_pressed();
}
Expand Down Expand Up @@ -595,6 +599,7 @@ EditorProfiler::EditorProfiler() {
add_child(hb);
activate = memnew(Button);
activate->set_toggle_mode(true);
activate->set_disabled(true);
activate->set_text(TTR("Start"));
activate->connect("pressed", callable_mp(this, &EditorProfiler::_activate_pressed));
hb->add_child(activate);
Expand Down
3 changes: 2 additions & 1 deletion editor/debugger/editor_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class EditorProfiler : public VBoxContainer {
Timer *frame_delay = nullptr;
Timer *plot_delay = nullptr;

void _set_button_text();
void _update_button_text();
void _update_frame();

void _activate_pressed();
Expand Down Expand Up @@ -155,6 +155,7 @@ class EditorProfiler : public VBoxContainer {
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);
bool is_profiling();
bool is_seeking() { return seeking; }
void disable_seeking();
Expand Down
20 changes: 20 additions & 0 deletions editor/debugger/editor_visual_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void EditorVisualProfiler::add_frame_metric(const Metric &p_metric) {
}

updating_frame = true;
clear_button->set_disabled(false);
cursor_metric_edit->set_max(frame_metrics[last_metric].frame_number);
cursor_metric_edit->set_min(MAX(frame_metrics[last_metric].frame_number - frame_metrics.size(), 0u));

Expand Down Expand Up @@ -408,6 +409,7 @@ void EditorVisualProfiler::_activate_pressed() {
activate->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));
activate->set_text(TTR("Stop"));
_clear_pressed(); //always clear on start
clear_button->set_disabled(false);
} else {
activate->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")));
activate->set_text(TTR("Start"));
Expand All @@ -416,6 +418,7 @@ void EditorVisualProfiler::_activate_pressed() {
}

void EditorVisualProfiler::_clear_pressed() {
clear_button->set_disabled(true);
clear();
_update_plot();
}
Expand Down Expand Up @@ -647,10 +650,25 @@ void EditorVisualProfiler::_bind_methods() {
ADD_SIGNAL(MethodInfo("enable_profiling", PropertyInfo(Variant::BOOL, "enable")));
}

void EditorVisualProfiler::_update_button_text() {
if (activate->is_pressed()) {
activate->set_icon(get_theme_icon(SNAME("Stop"), SNAME("EditorIcons")));
activate->set_text(TTR("Stop"));
} else {
activate->set_icon(get_theme_icon(SNAME("Play"), SNAME("EditorIcons")));
activate->set_text(TTR("Start"));
}
}

void EditorVisualProfiler::set_enabled(bool p_enable) {
activate->set_disabled(!p_enable);
}

void EditorVisualProfiler::set_pressed(bool p_pressed) {
activate->set_pressed(p_pressed);
_update_button_text();
}

bool EditorVisualProfiler::is_profiling() {
return activate->is_pressed();
}
Expand Down Expand Up @@ -714,12 +732,14 @@ EditorVisualProfiler::EditorVisualProfiler() {
add_child(hb);
activate = memnew(Button);
activate->set_toggle_mode(true);
activate->set_disabled(true);
activate->set_text(TTR("Start"));
activate->connect("pressed", callable_mp(this, &EditorVisualProfiler::_activate_pressed));
hb->add_child(activate);

clear_button = memnew(Button);
clear_button->set_text(TTR("Clear"));
clear_button->set_disabled(true);
clear_button->connect("pressed", callable_mp(this, &EditorVisualProfiler::_clear_pressed));
hb->add_child(clear_button);

Expand Down
3 changes: 3 additions & 0 deletions editor/debugger/editor_visual_profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class EditorVisualProfiler : public VBoxContainer {
Timer *frame_delay = nullptr;
Timer *plot_delay = nullptr;

void _update_button_text();

void _update_frame(bool p_focus_selected = false);

void _activate_pressed();
Expand Down Expand Up @@ -133,6 +135,7 @@ class EditorVisualProfiler : public VBoxContainer {
public:
void add_frame_metric(const Metric &p_metric);
void set_enabled(bool p_enable);
void set_pressed(bool p_pressed);
bool is_profiling();
bool is_seeking() { return seeking; }
void disable_seeking();
Expand Down
12 changes: 11 additions & 1 deletion editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
tabs->set_current_tab(0);
}
profiler->set_enabled(false, false);
visual_profiler->set_enabled(false);
inspector->clear_cache(); // Take a chance to force remote objects update.

} else if (p_msg == "debug_exit") {
Expand All @@ -328,8 +329,12 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
_update_buttons_state();
_set_reason_text(TTR("Execution resumed."), MESSAGE_SUCCESS);
emit_signal(SNAME("breaked"), false, false, "", false);

profiler->set_enabled(true, false);
profiler->disable_seeking();

visual_profiler->set_enabled(true);

} else if (p_msg == "set_pid") {
ERR_FAIL_COND(p_data.size() < 1);
remote_pid = p_data[0];
Expand Down Expand Up @@ -901,6 +906,7 @@ void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) {
stop();

profiler->set_enabled(true, true);
visual_profiler->set_enabled(true);

peer = p_peer;
ERR_FAIL_COND(p_peer.is_null());
Expand Down Expand Up @@ -957,7 +963,11 @@ void ScriptEditorDebugger::stop() {
res_path_cache.clear();
profiler_signature.clear();

profiler->set_enabled(true, false);
profiler->set_enabled(false, false);
profiler->set_pressed(false);

visual_profiler->set_enabled(false);
visual_profiler->set_pressed(false);

inspector->edit(nullptr);
_update_buttons_state();
Expand Down

0 comments on commit 6ff74f0

Please sign in to comment.