From 5cb2cfe65544cee01bac00ac9f88f3bf74cfb325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Tue, 17 Mar 2020 12:49:31 +0100 Subject: [PATCH] Add ability to export VRAM usage as CSV --- editor/script_editor_debugger.cpp | 51 +++++++++++++++++++++++++++++-- editor/script_editor_debugger.h | 5 ++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index ab4501bb8a7..8ff3a2b3d75 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -333,7 +333,7 @@ void ScriptEditorDebugger::_file_selected(const String &p_file) { msg.push_back(p_file); ppeer->put_var(msg); } break; - case SAVE_CSV: { + case SAVE_MONITORS_CSV: { Error err; FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err); @@ -370,6 +370,36 @@ void ScriptEditorDebugger::_file_selected(const String &p_file) { } } break; + case SAVE_VRAM_CSV: { + Error err; + FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err); + + if (err != OK) { + ERR_PRINTS("Failed to open " + p_file); + return; + } + + Vector headers; + headers.resize(vmem_tree->get_columns()); + for (int i = 0; i < vmem_tree->get_columns(); ++i) { + headers.write[i] = vmem_tree->get_column_title(i); + } + file->store_csv_line(headers); + + if (vmem_tree->get_root()) { + TreeItem *ti = vmem_tree->get_root()->get_children(); + while (ti) { + Vector values; + values.resize(vmem_tree->get_columns()); + for (int i = 0; i < vmem_tree->get_columns(); ++i) { + values.write[i] = ti->get_text(i); + } + file->store_csv_line(values); + + ti = ti->get_next(); + } + } + } break; } } @@ -494,6 +524,15 @@ void ScriptEditorDebugger::_video_mem_request() { ppeer->put_var(msg); } +void ScriptEditorDebugger::_video_mem_export() { + + file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); + file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM); + file_dialog->clear_filters(); + file_dialog_mode = SAVE_VRAM_CSV; + file_dialog->popup_centered_ratio(); +} + Size2 ScriptEditorDebugger::get_minimum_size() const { Size2 ms = MarginContainer::get_minimum_size(); @@ -1207,6 +1246,7 @@ void ScriptEditorDebugger::_notification(int p_what) { error_tree->connect("item_selected", this, "_error_selected"); error_tree->connect("item_activated", this, "_error_activated"); vmem_refresh->set_icon(get_icon("Reload", "EditorIcons")); + vmem_export->set_icon(get_icon("Save", "EditorIcons")); reason->add_color_override("font_color", get_color("error_color", "Editor")); @@ -1446,6 +1486,7 @@ 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")); + vmem_export->set_icon(get_icon("Save", "EditorIcons")); } break; } } @@ -1627,7 +1668,8 @@ void ScriptEditorDebugger::_export_csv() { file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM); - file_dialog_mode = SAVE_CSV; + file_dialog->clear_filters(); + file_dialog_mode = SAVE_MONITORS_CSV; file_dialog->popup_centered_ratio(); } @@ -2216,6 +2258,7 @@ void ScriptEditorDebugger::_bind_methods() { ClassDB::bind_method(D_METHOD("_performance_select"), &ScriptEditorDebugger::_performance_select); ClassDB::bind_method(D_METHOD("_scene_tree_request"), &ScriptEditorDebugger::_scene_tree_request); ClassDB::bind_method(D_METHOD("_video_mem_request"), &ScriptEditorDebugger::_video_mem_request); + ClassDB::bind_method(D_METHOD("_video_mem_export"), &ScriptEditorDebugger::_video_mem_export); ClassDB::bind_method(D_METHOD("_live_edit_set"), &ScriptEditorDebugger::_live_edit_set); ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear); @@ -2537,8 +2580,12 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) { vmem_refresh = memnew(ToolButton); vmem_refresh->set_disabled(true); vmem_hb->add_child(vmem_refresh); + vmem_export = memnew(ToolButton); + vmem_export->set_tooltip(TTR("Export list to a CSV file")); + vmem_hb->add_child(vmem_export); vmem_vb->add_child(vmem_hb); vmem_refresh->connect("pressed", this, "_video_mem_request"); + vmem_export->connect("pressed", this, "_video_mem_export"); VBoxContainer *vmmc = memnew(VBoxContainer); vmem_tree = memnew(Tree); diff --git a/editor/script_editor_debugger.h b/editor/script_editor_debugger.h index 589a011bffe..2de1db6919c 100644 --- a/editor/script_editor_debugger.h +++ b/editor/script_editor_debugger.h @@ -110,7 +110,8 @@ private: EditorFileDialog *file_dialog; enum FileDialogMode { - SAVE_CSV, + SAVE_MONITORS_CSV, + SAVE_VRAM_CSV, SAVE_NODE, }; FileDialogMode file_dialog_mode; @@ -151,6 +152,7 @@ private: Tree *vmem_tree; Button *vmem_refresh; + Button *vmem_export; LineEdit *vmem_total; Tree *stack_dump; @@ -196,6 +198,7 @@ private: int _update_scene_tree(TreeItem *parent, const Array &nodes, int current_index); void _video_mem_request(); + void _video_mem_export(); int _get_node_path_cache(const NodePath &p_path);