Skip to content

Commit

Permalink
Prevent overlapping output from live printing refs idaholab#15444
Browse files Browse the repository at this point in the history
  • Loading branch information
friedmud committed Jun 30, 2020
1 parent 3c27278 commit d67e18e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
5 changes: 5 additions & 0 deletions framework/include/outputs/ConsoleStream.h
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions framework/include/outputs/OutputWarehouse.h
Expand Up @@ -12,6 +12,9 @@
// MOOSE includes
#include "Output.h"

// System includes
#include <atomic>

// Forward declarations
class FEProblemBase;
class InputParameters;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<unsigned long long int> _num_printed;

// Allow complete access:
// FEProblemBase for calling initial, timestepSetup, outputStep, etc. methods
friend class FEProblemBase;
Expand Down
6 changes: 6 additions & 0 deletions framework/include/utils/PerfGraphLivePrint.h
Expand Up @@ -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;
};
8 changes: 7 additions & 1 deletion framework/src/outputs/ConsoleStream.C
Expand Up @@ -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())
{
}

Expand Down Expand Up @@ -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();
}
5 changes: 4 additions & 1 deletion framework/src/outputs/OutputWarehouse.C
Expand Up @@ -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
Expand Down Expand Up @@ -208,6 +209,8 @@ OutputWarehouse::mooseConsole()
_last_message_ended_in_newline = this_message_ends_in_newline;
}
}

_num_printed++;
}

void
Expand Down
20 changes: 17 additions & 3 deletions framework/src/utils/PerfGraphLivePrint.C
Expand Up @@ -59,6 +59,8 @@ PerfGraphLivePrint::printLiveMessage(PerfGraph::SectionIncrement & section_incre
section_increment._state = PerfGraph::IncrementState::printed;

_last_printed_increment = &section_increment;

_printed = true;
}

void
Expand Down Expand Up @@ -89,6 +91,8 @@ PerfGraphLivePrint::printStats(PerfGraph::SectionIncrement & section_increment_s
_console << '\n';

_last_printed_increment = &section_increment_start;

_printed = true;
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit d67e18e

Please sign in to comment.