33 template <
class... Ts>
36 #define MOOSE_MAX_STACK_SIZE 100 37 #define MAX_EXECUTION_LIST_SIZE 10000 75 "SELF CHILDREN TOTAL SELF_AVG CHILDREN_AVG TOTAL_AVG SELF_PERCENT CHILDREN_PERCENT " 76 "TOTAL_PERCENT SELF_MEMORY CHILDREN_MEMORY TOTAL_MEMORY CALLS");
90 const bool perf_graph_live);
171 sectionData(
const DataType type,
const std::string & section_name,
const bool must_exist =
true);
188 template <
typename Functor>
190 const unsigned int level = MOOSE_MAX_STACK_SIZE,
191 const bool heaviest =
false)
const;
283 std::chrono::time_point<std::chrono::steady_clock>
_time;
299 const std::chrono::time_point<std::chrono::steady_clock> time,
300 const long int memory);
355 std::array<PerfNode *, MOOSE_MAX_STACK_SIZE>
_stack;
425 template <
typename Functor>
428 const unsigned int level,
430 unsigned int current_depth)
const;
433 template <
typename Functor>
437 const unsigned int level,
439 unsigned int current_depth)
const 444 if (current_section_info._level <= level)
447 act(node, current_section_info, current_depth++);
452 const PerfNode * heaviest_child =
nullptr;
453 for (
const auto & child_it : node.
children())
455 const auto & current_child = *child_it.second;
457 if (!heaviest_child || (current_child.totalTime() > heaviest_child->
totalTime()))
458 heaviest_child = ¤t_child;
466 for (
const auto & child_it : node.
children())
471 template <
typename Functor>
474 const unsigned int level ,
475 const bool heaviest )
const 477 mooseAssert(
_root_node,
"Root node does not exist; calling this too early");
void recursivelyUpdate(const PerfNode ¤t_node)
Updates the cumulative self/children/total time and memory for each section across all nodes that con...
long int _memory
Either the starting memory or final memory depending on _state.
PerfGraphRegistry & _perf_graph_registry
The PerfGraphRegistry.
A helper class for re-directing output streams to Console output objects form MooseObjects.
long int _total_memory
Total memory gain for this section.
long int _self_memory
Amount of memory gained within this section (without children)
unsigned long int _num_calls
Number of times this section has been called.
static MooseEnum dataTypeEnum()
DataType in a MooseEnum for use in InputParameters in objects that query the PerfGraph with sectionDa...
The place where all timed sections will be stored.
PerfGraph(const std::string &root_name, MooseApp &app, const bool live_all, const bool perf_graph_live)
Create a new PerfGraph.
bool sectionExists(const std::string §ion_name) const
Whether or not a section with that name has been registered The name of the section.
Real sectionData(const DataType type, const std::string §ion_name, const bool must_exist=true)
Gets a PerfGraph result pertaining to a section.
std::promise< bool > _done
The promise to the print thread that will signal when to stop.
std::thread _print_thread
The thread for printing sections as they execute.
friend void dataStore(std::ostream &, PerfGraph &, void *)
std::atomic< unsigned int > _live_print_mem_limit
The memory limit before a message is printed (in MB)
DataType
For retrieving values.
A class for "pretty printing" a table of data.
VariadicTable< std::string, unsigned long int, Real, Real, Real, long int, Real, Real, Real, long int > FullTable
std::atomic< unsigned int > _execution_list_begin
Where the print thread should start reading the execution list.
const std::unique_ptr< PerfGraphLivePrint > _live_print
The object that is doing live printing.
This section has already started printing.
Real _total
Total amount of time used.
Base class for MOOSE-based applications.
Use to hold an increment of time and memory for a section This is used in the LivePrint capability...
std::atomic< unsigned int > _execution_list_end
Where the print thread should stop reading the execution list.
unsigned int _print_stack_level
How much to indent this section.
IncrementState
The execution state of an increment.
bool _live_print_all
Whether or not to put everything in the perf graph.
Real _self
Amount of time used within this section (without children)
std::condition_variable _finished_section
The condition_variable to wake the print thread.
void update()
Updates the time section_time and time for all currently running nodes.
uint8_t processor_id_type
IncrementState _state
Whether or not this increment is the start of an increment or the finishing of an increment...
void addToExecutionList(const PerfID id, const IncrementState state, const std::chrono::time_point< std::chrono::steady_clock > time, const long int memory)
Add the information to the execution list.
std::vector< CumulativeSectionInfo * > _cumulative_section_info_ptrs
Pointers into _cumulative_section_info indexed on PerfID This is here for convenience and speed so we...
Scope guard for starting and stopping timing for a node.
void treeRecurse(const Functor &act, const unsigned int level=MOOSE_MAX_STACK_SIZE, const bool heaviest=false) const
const std::unique_ptr< PerfNode > _root_node
The root node of the graph.
const std::map< PerfID, std::unique_ptr< PerfNode > > & children() const
Get the children.
FunctorEnvelope< T > Functor
PerfID id() const
Get the ID of this Node.
unsigned long long int _beginning_num_printed
The _console numPrinted() at the time this section was created.
void setActive(bool active)
Turn on or off timing.
unsigned int _num_dots
How many dots have been printed for this section.
std::mutex _destructing_mutex
The mutex to use with a condition_variable predicate to guard _destructing.
std::unordered_map< std::string, CumulativeSectionInfo > _cumulative_section_info
The cumulative time and memory for each section.
void setLiveMemoryLimit(unsigned int mem_limit)
Sert the memory limit before a message prints.
An inteface for the _console for outputting to the Console object.
void dataStore(std::ostream &stream, PerfGraph &perf_graph, void *context)
bool active() const
Whether or not timing is active.
bool _active
Whether or not timing is active.
This is effectively a functor that runs on a separate thread and watches the state of the call stack ...
void disableLivePrint()
Completely disables Live Print (cannot be restarted)
MooseApp & _moose_app
The MooseApp.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
int _current_position
The current node position in the stack.
Real _children
Amount of time used by children.
std::chrono::steady_clock::duration totalTime() const
The time this Node plus all of it's children took.
void treeRecurseInternal(const PerfNode &node, const Functor &act, const unsigned int level, const bool heaviest, unsigned int current_depth) const
void pop()
Remove a Node from the end of the current scope.
bool _disable_live_print
Whether or not live print is disabled (cannot be turned on again)
void print(const ConsoleStream &console, unsigned int level)
Print the tree out.
std::chrono::time_point< std::chrono::steady_clock > _time
Either the starting time or final time depending on _state.
friend void dataLoad(std::istream &, PerfGraph &, void *)
std::array< PerfNode *, MOOSE_MAX_STACK_SIZE > _stack
The full callstack. Currently capped at a depth of 100.
void printHeaviestBranch(const ConsoleStream &console)
Print out the heaviest branch through the tree.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const std::string _root_name
Name of the root node.
Use to hold the cumulative time and memory for each section, which comes from all of the PerfNodes th...
VariadicTable< std::string, unsigned long int, Real, Real, Real, long int > HeaviestTable
const libMesh::processor_id_type _pid
This processor id.
long int _children_memory
Amount of memory gained by children.
bool _destructing
Tell the print thread to teardown.
void printHeaviestSections(const ConsoleStream &console, const unsigned int num_sections)
Print out the heaviest sections that were timed.
void setLiveTimeLimit(Real time_limit)
Set the time limit before a message prints.
void push(const PerfID id)
Add a Node onto the end of the end of the current callstack.
FullTable treeTable(const unsigned int level, const bool heaviest=false)
Helper for building a VariadicTable that represents the tree.
Section just started running.
The PerfGraph will hold the master list of all registered performance segments and the head PerfNode...
void setLivePrintAll(bool active)
Forces all sections to be output live.
const PerfGraphSectionInfo & readSectionInfo(PerfID section_id) const
Special accessor just for PerfGraph so that no locking is needed in PerfGraph.
std::atomic< Real > _live_print_time_limit
The time limit before a message is printed (in seconds)
void ErrorVector unsigned int
std::array< SectionIncrement, MAX_EXECUTION_LIST_SIZE > _execution_list
A circular buffer for holding the execution list, this is read by the printing loop.
void dataLoad(std::istream &stream, PerfGraph &perf_graph, void *context)
void enableLivePrint()
Enables Live Print.
const PerfNode & rootNode() const
const PerfID _root_node_id
The id for the root node.