diff --git a/framework/include/outputs/ConsoleStream.h b/framework/include/outputs/ConsoleStream.h index 850a766a5e10..beb07ea623ff 100644 --- a/framework/include/outputs/ConsoleStream.h +++ b/framework/include/outputs/ConsoleStream.h @@ -80,6 +80,11 @@ class ConsoleStream */ std::ios_base::fmtflags flags(std::ios_base::fmtflags new_flags) const; + /** + * The number of times something has been printed + */ + unsigned long long int numPrinted() const; + private: /// Reference to the OutputWarhouse that contains the Console output objects OutputWarehouse & _output_warehouse; diff --git a/framework/include/outputs/OutputWarehouse.h b/framework/include/outputs/OutputWarehouse.h index 53d372ab7eaa..c27216193797 100644 --- a/framework/include/outputs/OutputWarehouse.h +++ b/framework/include/outputs/OutputWarehouse.h @@ -12,6 +12,9 @@ // MOOSE includes #include "Output.h" +// System includes +#include + // Forward declarations class FEProblemBase; class InputParameters; @@ -194,6 +197,9 @@ class OutputWarehouse /// Reset the output system void reset(); + /// The number of times something has been printed + unsigned long long int numPrinted() const { return _num_printed; } + private: /** * Calls the outputStep method for each output object @@ -350,6 +356,9 @@ class OutputWarehouse /// Whether or not the last thing output by mooseConsole had a newline as the last character bool _last_message_ended_in_newline; + /// Number of times the stream has been printed to + std::atomic _num_printed; + // Allow complete access: // FEProblemBase for calling initial, timestepSetup, outputStep, etc. methods friend class FEProblemBase; diff --git a/framework/include/utils/PerfGraphLivePrint.h b/framework/include/utils/PerfGraphLivePrint.h index bb757aefff4c..9cb84f39bda6 100644 --- a/framework/include/utils/PerfGraphLivePrint.h +++ b/framework/include/utils/PerfGraphLivePrint.h @@ -61,4 +61,10 @@ class PerfGraphLivePrint : protected ConsoleStreamInterface unsigned int _last_execution_list_end; PerfGraph::SectionIncrement * _last_printed_increment; + + /// The output count from the console the last time we printed + unsigned long long int _last_num_printed; + + /// Whether or not printing happened in this iteration + bool _printed; }; diff --git a/framework/src/outputs/ConsoleStream.C b/framework/src/outputs/ConsoleStream.C index fe603e912164..9ad136635b8a 100644 --- a/framework/src/outputs/ConsoleStream.C +++ b/framework/src/outputs/ConsoleStream.C @@ -13,7 +13,7 @@ #include "OutputWarehouse.h" ConsoleStream::ConsoleStream(OutputWarehouse & output_warehouse) - : _output_warehouse(output_warehouse), _oss(output_warehouse.consoleBuffer()) + : _output_warehouse(output_warehouse), _oss(output_warehouse.consoleBuffer()) { } @@ -59,3 +59,9 @@ ConsoleStream::flags(std::ios_base::fmtflags new_flags) const { return _oss.flags(new_flags); } + +unsigned long long int +ConsoleStream::numPrinted() const +{ + return _output_warehouse.numPrinted(); +} diff --git a/framework/src/outputs/OutputWarehouse.C b/framework/src/outputs/OutputWarehouse.C index 6524815c5626..7734fe0884ea 100644 --- a/framework/src/outputs/OutputWarehouse.C +++ b/framework/src/outputs/OutputWarehouse.C @@ -28,7 +28,8 @@ OutputWarehouse::OutputWarehouse(MooseApp & app) _output_exec_flag(EXEC_CUSTOM), _force_output(false), _logging_requested(false), - _last_message_ended_in_newline(true) + _last_message_ended_in_newline(true), + _num_printed(0) { // Set the reserved names _reserved.insert("none"); // allows 'none' to be used as a keyword in 'outputs' parameter @@ -208,6 +209,8 @@ OutputWarehouse::mooseConsole() _last_message_ended_in_newline = this_message_ends_in_newline; } } + + _num_printed++; } void diff --git a/framework/src/utils/PerfGraphLivePrint.C b/framework/src/utils/PerfGraphLivePrint.C index 2b66cb107778..81851c471adb 100644 --- a/framework/src/utils/PerfGraphLivePrint.C +++ b/framework/src/utils/PerfGraphLivePrint.C @@ -59,6 +59,8 @@ PerfGraphLivePrint::printLiveMessage(PerfGraph::SectionIncrement & section_incre section_increment._state = PerfGraph::IncrementState::printed; _last_printed_increment = §ion_increment; + + _printed = true; } void @@ -89,6 +91,8 @@ PerfGraphLivePrint::printStats(PerfGraph::SectionIncrement & section_increment_s _console << '\n'; _last_printed_increment = §ion_increment_start; + + _printed = true; } @@ -138,9 +142,13 @@ PerfGraphLivePrint::printStackUpToLast() void PerfGraphLivePrint::inSamePlace() { - printStackUpToLast(); + // Only print if nothing else has been printed in the meantime + if (_last_num_printed == _console.numPrinted()) + { + printStackUpToLast(); - printLiveMessage(*_print_thread_stack[_stack_level - 1]); + printLiveMessage(*_print_thread_stack[_stack_level - 1]); + } } void @@ -220,6 +228,8 @@ PerfGraphLivePrint::start() if (_current_execution_list_end == 0 && _last_execution_list_end == _current_execution_list_end) continue; + _printed = false; + // Iterate from the last thing printed (begin) to the last thing in the list (end) // If the time or memory of any section is above the threshold, print everything inbetween and // update begin @@ -232,7 +242,11 @@ PerfGraphLivePrint::start() iterateThroughExecutionList(); // Make sure that everything comes out on the console - _console << std::flush; + if (_printed) + { + _console << std::flush; + _last_num_printed = _console.numPrinted(); + } _last_execution_list_end = _current_execution_list_end; }