From 7393c606ffe6bfb762a20dc710b73dbb3748ad82 Mon Sep 17 00:00:00 2001 From: Mikael Hermansson Date: Tue, 5 Aug 2025 14:45:01 +0200 Subject: [PATCH] Reduce log spam during headless import/export --- editor/editor_node.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index f91d4345cb8..8a454a554ba 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -5356,6 +5356,11 @@ bool EditorNode::is_object_of_custom_type(const Object *p_object, const StringNa // Used to track the progress of tasks in the CLI output (since we don't have any other frame of reference). static HashMap progress_total_steps; +static String last_progress_task; +static String last_progress_state; +static int last_progress_step = 0; +static double last_progress_time = 0; + void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) { if (!singleton) { return; @@ -5371,8 +5376,18 @@ bool EditorNode::progress_task_step(const String &p_task, const String &p_state, if (!singleton) { return false; } else if (singleton->cmdline_mode) { - const int percent = (p_step / float(progress_total_steps[p_task] + 1)) * 100; - print_line_rich(vformat("[%4d%% ] [color=gray][b]%s[/b] | %s[/color]", percent, p_task, p_state)); + double current_time = USEC_TO_SEC(OS::get_singleton()->get_ticks_usec()); + double elapsed_time = current_time - last_progress_time; + if (p_task != last_progress_task || p_state != last_progress_state || p_step != last_progress_step || elapsed_time >= 1.0) { + // Only print the progress if it's changed since the last print, or if one second has passed. + // This prevents multithreaded import from printing the same progress too often, which would bloat the log file. + const int percent = (p_step / float(progress_total_steps[p_task] + 1)) * 100; + print_line_rich(vformat("[%4d%% ] [color=gray][b]%s[/b] | %s[/color]", percent, p_task, p_state)); + last_progress_task = p_task; + last_progress_state = p_state; + last_progress_step = p_step; + last_progress_time = current_time; + } return false; } else if (singleton->progress_dialog) { return singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh);