Add ability to export VRAM usage as CSV

This commit is contained in:
Pedro J. Estébanez 2020-03-17 12:49:31 +01:00 committed by Pedro J. Estébanez
parent ed27b7e6b9
commit 5cb2cfe655
2 changed files with 53 additions and 3 deletions

View file

@ -333,7 +333,7 @@ void ScriptEditorDebugger::_file_selected(const String &p_file) {
msg.push_back(p_file); msg.push_back(p_file);
ppeer->put_var(msg); ppeer->put_var(msg);
} break; } break;
case SAVE_CSV: { case SAVE_MONITORS_CSV: {
Error err; Error err;
FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err); FileAccessRef file = FileAccess::open(p_file, FileAccess::WRITE, &err);
@ -370,6 +370,36 @@ void ScriptEditorDebugger::_file_selected(const String &p_file) {
} }
} break; } 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<String> 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<String> 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); 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 ScriptEditorDebugger::get_minimum_size() const {
Size2 ms = MarginContainer::get_minimum_size(); 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_selected", this, "_error_selected");
error_tree->connect("item_activated", this, "_error_activated"); error_tree->connect("item_activated", this, "_error_activated");
vmem_refresh->set_icon(get_icon("Reload", "EditorIcons")); 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")); 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")); dobreak->set_icon(get_icon("Pause", "EditorIcons"));
docontinue->set_icon(get_icon("DebugContinue", "EditorIcons")); docontinue->set_icon(get_icon("DebugContinue", "EditorIcons"));
vmem_refresh->set_icon(get_icon("Reload", "EditorIcons")); vmem_refresh->set_icon(get_icon("Reload", "EditorIcons"));
vmem_export->set_icon(get_icon("Save", "EditorIcons"));
} break; } break;
} }
} }
@ -1627,7 +1668,8 @@ void ScriptEditorDebugger::_export_csv() {
file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE); file_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
file_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM); 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(); 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("_performance_select"), &ScriptEditorDebugger::_performance_select);
ClassDB::bind_method(D_METHOD("_scene_tree_request"), &ScriptEditorDebugger::_scene_tree_request); 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_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_set"), &ScriptEditorDebugger::_live_edit_set);
ClassDB::bind_method(D_METHOD("_live_edit_clear"), &ScriptEditorDebugger::_live_edit_clear); 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 = memnew(ToolButton);
vmem_refresh->set_disabled(true); vmem_refresh->set_disabled(true);
vmem_hb->add_child(vmem_refresh); 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_vb->add_child(vmem_hb);
vmem_refresh->connect("pressed", this, "_video_mem_request"); vmem_refresh->connect("pressed", this, "_video_mem_request");
vmem_export->connect("pressed", this, "_video_mem_export");
VBoxContainer *vmmc = memnew(VBoxContainer); VBoxContainer *vmmc = memnew(VBoxContainer);
vmem_tree = memnew(Tree); vmem_tree = memnew(Tree);

View file

@ -110,7 +110,8 @@ private:
EditorFileDialog *file_dialog; EditorFileDialog *file_dialog;
enum FileDialogMode { enum FileDialogMode {
SAVE_CSV, SAVE_MONITORS_CSV,
SAVE_VRAM_CSV,
SAVE_NODE, SAVE_NODE,
}; };
FileDialogMode file_dialog_mode; FileDialogMode file_dialog_mode;
@ -151,6 +152,7 @@ private:
Tree *vmem_tree; Tree *vmem_tree;
Button *vmem_refresh; Button *vmem_refresh;
Button *vmem_export;
LineEdit *vmem_total; LineEdit *vmem_total;
Tree *stack_dump; Tree *stack_dump;
@ -196,6 +198,7 @@ private:
int _update_scene_tree(TreeItem *parent, const Array &nodes, int current_index); int _update_scene_tree(TreeItem *parent, const Array &nodes, int current_index);
void _video_mem_request(); void _video_mem_request();
void _video_mem_export();
int _get_node_path_cache(const NodePath &p_path); int _get_node_path_cache(const NodePath &p_path);