diff options
Diffstat (limited to 'editor/script_editor_debugger.cpp')
-rw-r--r-- | editor/script_editor_debugger.cpp | 142 |
1 files changed, 92 insertions, 50 deletions
diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index 559ab32505..717d6bc8f6 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -303,12 +303,49 @@ void ScriptEditorDebugger::_scene_tree_rmb_selected(const Vector2 &p_position) { } void ScriptEditorDebugger::_file_selected(const String &p_file) { - if (file_dialog->get_mode() == EditorFileDialog::MODE_SAVE_FILE) { + if (file_dialog_mode == SAVE_NODE) { + Array msg; msg.push_back("save_node"); msg.push_back(inspected_object_id); msg.push_back(p_file); ppeer->put_var(msg); + } else if (file_dialog_mode == SAVE_CSV) { + + Error err; + FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err); + + if (err != OK) { + ERR_PRINTS("Failed to open " + p_file); + return; + } + Vector<String> line; + line.resize(Performance::MONITOR_MAX); + + // signatures + for (int i = 0; i < Performance::MONITOR_MAX; i++) { + line.write[i] = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)); + } + file->store_csv_line(line); + + // values + List<Vector<float> >::Element *E = perf_history.back(); + while (E) { + + Vector<float> &perf_data = E->get(); + for (int i = 0; i < perf_data.size(); i++) { + + line.write[i] = String::num_real(perf_data[i]); + } + file->store_csv_line(line); + E = E->prev(); + } + file->store_string("\n"); + + Vector<Vector<String> > profiler_data = profiler->get_data_as_csv(); + for (int i = 0; i < profiler_data.size(); i++) { + file->store_csv_line(profiler_data[i]); + } } } @@ -777,7 +814,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da for (int i = 0; i < scc; i += 3) { String script = p_data[2 + i]; - String method = p_data[3 + i]; + String method2 = p_data[3 + i]; int line = p_data[4 + i]; TreeItem *stack_trace = error_tree->create_item(error); @@ -791,7 +828,7 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da stack_trace->set_text_align(0, TreeItem::ALIGN_LEFT); error->set_metadata(0, meta); } - stack_trace->set_text(1, script.get_file() + ":" + itos(line) + " @ " + method + "()"); + stack_trace->set_text(1, script.get_file() + ":" + itos(line) + " @ " + method2 + "()"); } if (warning) @@ -859,18 +896,18 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da c.items.resize(values.size() / 2); c.total_time = 0; c.signature = "categ::" + name; - for (int i = 0; i < values.size(); i += 2) { + for (int j = 0; j < values.size(); j += 2) { EditorProfiler::Metric::Category::Item item; item.calls = 1; item.line = 0; - item.name = values[i]; - item.self = values[i + 1]; + item.name = values[j]; + item.self = values[j + 1]; item.total = item.self; item.signature = "categ::" + name + "::" + item.name; item.name = item.name.capitalize(); c.total_time += item.total; - c.items.write[i / 2] = item; + c.items.write[j / 2] = item; } metric.categories.push_back(c); } @@ -898,6 +935,10 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da item.name = strings[2]; item.script = strings[0]; item.line = strings[1].to_int(); + } else if (strings.size() == 4) { //Built-in scripts have an :: in their name + item.name = strings[3]; + item.script = strings[0] + "::" + strings[1]; + item.line = strings[2].to_int(); } } else { @@ -998,13 +1039,13 @@ void ScriptEditorDebugger::_performance_draw() { float m = perf_max[pi]; if (m == 0) m = 0.00001; - float h = E->get()[pi] / m; - h = (1.0 - h) * r.size.y; + float h2 = E->get()[pi] / m; + h2 = (1.0 - h2) * r.size.y; c.a = 0.7; if (E != perf_history.front()) - perf_draw->draw_line(r.position + Point2(from, h), r.position + Point2(from + spacing, prev), c, 2.0); - prev = h; + perf_draw->draw_line(r.position + Point2(from, h2), r.position + Point2(from + spacing, prev), c, 2.0); + prev = h2; E = E->next(); from -= spacing; } @@ -1036,17 +1077,6 @@ void ScriptEditorDebugger::_notification(int p_what) { reason->add_color_override("font_color", get_color("error_color", "Editor")); - bool enable_rl = EditorSettings::get_singleton()->get("docks/scene_tree/draw_relationship_lines"); - Color rl_color = EditorSettings::get_singleton()->get("docks/scene_tree/relationship_line_color"); - - if (enable_rl) { - inspect_scene_tree->add_constant_override("draw_relationship_lines", 1); - inspect_scene_tree->add_color_override("relationship_line_color", rl_color); - inspect_scene_tree->add_constant_override("draw_guides", 0); - } else { - inspect_scene_tree->add_constant_override("draw_relationship_lines", 0); - inspect_scene_tree->add_constant_override("draw_guides", 1); - } } break; case NOTIFICATION_PROCESS: { @@ -1080,19 +1110,19 @@ void ScriptEditorDebugger::_notification(int p_what) { if (error_count != last_error_count || warning_count != last_warning_count) { if (error_count == 0 && warning_count == 0) { - error_tree->set_name(TTR("Errors")); + errors_tab->set_name(TTR("Errors")); debugger_button->set_text(TTR("Debugger")); debugger_button->set_icon(Ref<Texture>()); - tabs->set_tab_icon(error_tree->get_index(), Ref<Texture>()); + tabs->set_tab_icon(errors_tab->get_index(), Ref<Texture>()); } else { - error_tree->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")"); + errors_tab->set_name(TTR("Errors") + " (" + itos(error_count + warning_count) + ")"); debugger_button->set_text(TTR("Debugger") + " (" + itos(error_count + warning_count) + ")"); if (error_count == 0) { debugger_button->set_icon(get_icon("Warning", "EditorIcons")); - tabs->set_tab_icon(error_tree->get_index(), get_icon("Warning", "EditorIcons")); + tabs->set_tab_icon(errors_tab->get_index(), get_icon("Warning", "EditorIcons")); } else { debugger_button->set_icon(get_icon("Error", "EditorIcons")); - tabs->set_tab_icon(error_tree->get_index(), get_icon("Error", "EditorIcons")); + tabs->set_tab_icon(errors_tab->get_index(), get_icon("Error", "EditorIcons")); } } last_error_count = error_count; @@ -1222,24 +1252,15 @@ void ScriptEditorDebugger::_notification(int p_what) { if (OS::get_singleton()->get_ticks_msec() > until) break; } - } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { + tabs->add_style_override("panel", editor->get_gui_base()->get_stylebox("DebuggerPanel", "EditorStyles")); tabs->add_style_override("tab_fg", editor->get_gui_base()->get_stylebox("DebuggerTabFG", "EditorStyles")); tabs->add_style_override("tab_bg", editor->get_gui_base()->get_stylebox("DebuggerTabBG", "EditorStyles")); tabs->set_margin(MARGIN_LEFT, -EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_LEFT)); tabs->set_margin(MARGIN_RIGHT, EditorNode::get_singleton()->get_gui_base()->get_stylebox("BottomPanelDebuggerOverride", "EditorStyles")->get_margin(MARGIN_RIGHT)); - bool enable_rl = EditorSettings::get_singleton()->get("docks/scene_tree/draw_relationship_lines"); - Color rl_color = EditorSettings::get_singleton()->get("docks/scene_tree/relationship_line_color"); - - if (enable_rl) { - inspect_scene_tree->add_constant_override("draw_relationship_lines", 1); - inspect_scene_tree->add_color_override("relationship_line_color", rl_color); - } else - inspect_scene_tree->add_constant_override("draw_relationship_lines", 0); - copy->set_icon(get_icon("ActionCopy", "EditorIcons")); step->set_icon(get_icon("DebugStep", "EditorIcons")); next->set_icon(get_icon("DebugNext", "EditorIcons")); @@ -1248,7 +1269,6 @@ void ScriptEditorDebugger::_notification(int p_what) { dobreak->set_icon(get_icon("Pause", "EditorIcons")); docontinue->set_icon(get_icon("DebugContinue", "EditorIcons")); vmem_refresh->set_icon(get_icon("Reload", "EditorIcons")); - } break; } } @@ -1391,6 +1411,13 @@ void ScriptEditorDebugger::_output_clear() { //output->push_color(Color(0,0,0)); } +void ScriptEditorDebugger::_export_csv() { + + file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); + file_dialog_mode = SAVE_CSV; + file_dialog->popup_centered_ratio(); +} + String ScriptEditorDebugger::get_var_value(const String &p_var) const { if (!breaked) return String(); @@ -1532,14 +1559,14 @@ void ScriptEditorDebugger::_property_changed(Object *p_base, const StringName &p int pathid = _get_res_path_cache(respath); if (p_value.is_ref()) { - Ref<Resource> res = p_value; - if (res.is_valid() && res->get_path() != String()) { + Ref<Resource> res2 = p_value; + if (res2.is_valid() && res2->get_path() != String()) { Array msg; msg.push_back("live_res_prop_res"); msg.push_back(pathid); msg.push_back(p_property); - msg.push_back(res->get_path()); + msg.push_back(res2->get_path()); ppeer->put_var(msg); } } else { @@ -1876,6 +1903,7 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) { file_dialog->set_access(EditorFileDialog::ACCESS_RESOURCES); file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); + file_dialog_mode = SAVE_NODE; List<String> extensions; Ref<PackedScene> sd = memnew(PackedScene); @@ -1901,6 +1929,7 @@ void ScriptEditorDebugger::_bind_methods() { ClassDB::bind_method(D_METHOD("debug_break"), &ScriptEditorDebugger::debug_break); ClassDB::bind_method(D_METHOD("debug_continue"), &ScriptEditorDebugger::debug_continue); ClassDB::bind_method(D_METHOD("_output_clear"), &ScriptEditorDebugger::_output_clear); + ClassDB::bind_method(D_METHOD("_export_csv"), &ScriptEditorDebugger::_export_csv); ClassDB::bind_method(D_METHOD("_performance_draw"), &ScriptEditorDebugger::_performance_draw); ClassDB::bind_method(D_METHOD("_performance_select"), &ScriptEditorDebugger::_performance_select); ClassDB::bind_method(D_METHOD("_scene_tree_request"), &ScriptEditorDebugger::_scene_tree_request); @@ -2050,11 +2079,11 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { } { //errors - VBoxContainer *errvb = memnew(VBoxContainer); - errvb->set_name(TTR("Errors")); + errors_tab = memnew(VBoxContainer); + errors_tab->set_name(TTR("Errors")); HBoxContainer *errhb = memnew(HBoxContainer); - errvb->add_child(errhb); + errors_tab->add_child(errhb); Button *expand_all = memnew(Button); expand_all->set_text(TTR("Expand All")); @@ -2089,13 +2118,13 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { error_tree->set_v_size_flags(SIZE_EXPAND_FILL); error_tree->set_allow_rmb_select(true); error_tree->connect("item_rmb_selected", this, "_error_tree_item_rmb_selected"); - errvb->add_child(error_tree); + errors_tab->add_child(error_tree); item_menu = memnew(PopupMenu); item_menu->connect("id_pressed", this, "_item_menu_id_pressed"); error_tree->add_child(item_menu); - tabs->add_child(errvb); + tabs->add_child(errors_tab); } { // remote scene tree @@ -2222,10 +2251,13 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { } { // misc + VBoxContainer *misc = memnew(VBoxContainer); + misc->set_name(TTR("Misc")); + tabs->add_child(misc); + GridContainer *info_left = memnew(GridContainer); info_left->set_columns(2); - info_left->set_name(TTR("Misc")); - tabs->add_child(info_left); + misc->add_child(info_left); clicked_ctrl = memnew(LineEdit); clicked_ctrl->set_h_size_flags(SIZE_EXPAND_FILL); info_left->add_child(memnew(Label(TTR("Clicked Control:")))); @@ -2250,6 +2282,16 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { le_set->set_disabled(true); le_clear->set_disabled(true); } + + misc->add_child(memnew(VSeparator)); + + HBoxContainer *buttons = memnew(HBoxContainer); + + export_csv = memnew(Button(TTR("Export measures as CSV"))); + export_csv->connect("pressed", this, "_export_csv"); + buttons->add_child(export_csv); + + misc->add_child(buttons); } msgdialog = memnew(AcceptDialog); |