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);
195 template <
typename Functor>
197 const unsigned int level = MOOSE_MAX_STACK_SIZE,
198 const bool heaviest =
false)
const;
290 std::chrono::time_point<std::chrono::steady_clock>
_time;
306 const std::chrono::time_point<std::chrono::steady_clock> time,
307 const long int memory);
362 std::array<PerfNode *, MOOSE_MAX_STACK_SIZE>
_stack;
435 template <
typename Functor>
438 const unsigned int level,
440 unsigned int current_depth)
const;
448template <
typename Functor>
452 const unsigned int level,
454 unsigned int current_depth)
const
459 if (current_section_info._level <= level)
462 act(node, current_section_info, current_depth++);
467 const PerfNode * heaviest_child =
nullptr;
468 for (
const auto & child_it : node.
children())
470 const auto & current_child = *child_it.second;
472 if (!heaviest_child || (current_child.totalTime() > heaviest_child->
totalTime()))
473 heaviest_child = ¤t_child;
481 for (
const auto & child_it : node.
children())
486template <
typename Functor>
489 const unsigned int level ,
490 const bool heaviest )
const
492 mooseAssert(
_root_node,
"Root node does not exist; calling this too early");
void dataLoad(std::istream &stream, PerfGraph &perf_graph, void *context)
void dataStore(std::ostream &stream, PerfGraph &perf_graph, void *context)
void ErrorVector unsigned int
An inteface for the _console for outputting to the Console object.
A helper class for re-directing output streams to Console output objects form MooseObjects.
Base class for MOOSE-based applications.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
This is effectively a functor that runs on a separate thread and watches the state of the call stack ...
Use to hold an increment of time and memory for a section This is used in the LivePrint capability.
unsigned long long int _beginning_num_printed
The _console numPrinted() at the time this section was created.
unsigned int _print_stack_level
How much to indent this section.
long int _memory
Either the starting memory or final memory depending on _state.
std::chrono::time_point< std::chrono::steady_clock > _time
Either the starting time or final time depending on _state.
unsigned int _num_dots
How many dots have been printed for this section.
IncrementState _state
Whether or not this increment is the start of an increment or the finishing of an increment.
The PerfGraph will hold the master list of all registered performance segments and the head PerfNode.
void treeRecurse(const Functor &act, const unsigned int level=MOOSE_MAX_STACK_SIZE, const bool heaviest=false) const
DataType
For retrieving values.
friend void dataLoad(std::istream &, PerfGraph &, void *)
std::promise< bool > _done
The promise to the print thread that will signal when to stop.
void recursivelyUpdate(const PerfNode ¤t_node)
Updates the cumulative self/children/total time and memory for each section across all nodes that con...
VariadicTable< std::string, unsigned long int, Real, Real, Real, long int, Real, Real, Real, long int > FullTable
std::unordered_map< std::string, CumulativeSectionInfo > _cumulative_section_info
The cumulative time and memory for each section.
void updateMaxMemory(const std::size_t current_memory)
Update _max_memory if current_memory > _max_memory.
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.
PerfGraphRegistry & _perf_graph_registry
The PerfGraphRegistry.
std::condition_variable _finished_section
The condition_variable to wake the print thread.
std::atomic< Real > _live_print_time_limit
The time limit before a message is printed (in seconds)
FullTable treeTable(const unsigned int level, const bool heaviest=false)
Helper for building a VariadicTable that represents the tree.
std::atomic< unsigned int > _execution_list_begin
Where the print thread should start reading the execution list.
const PerfID _root_node_id
The id for the root node.
std::atomic< unsigned int > _live_print_mem_limit
The memory limit before a message is printed (in MB)
std::mutex _destructing_mutex
The mutex to use with a condition_variable predicate to guard _destructing.
bool _active
Whether or not timing is active.
const std::unique_ptr< PerfGraphLivePrint > _live_print
The object that is doing live printing.
const libMesh::processor_id_type _pid
This processor id.
const PerfNode & rootNode() const
std::atomic< std::size_t > _max_memory
Maximum memory encountered during push and pop.
void setLiveMemoryLimit(unsigned int mem_limit)
Sert the memory limit before a message prints.
std::size_t getMaxMemory() const
Get the maximum memory allocation in MB.
void update()
Updates the time section_time and time for all currently running nodes.
Real sectionData(const DataType type, const std::string §ion_name, const bool must_exist=true)
Gets a PerfGraph result pertaining to a section.
int _current_position
The current node position in the stack.
void setLiveTimeLimit(Real time_limit)
Set the time limit before a message prints.
void enableLivePrint()
Enables Live Print.
void setActive(bool active)
Turn on or off timing.
MooseApp & _moose_app
The MooseApp.
const std::unique_ptr< PerfNode > _root_node
The root node of the graph.
IncrementState
The execution state of an increment.
@ PRINTED
This section has already started printing.
@ FINISHED
The section is complete.
@ STARTED
Section just started running.
void printHeaviestBranch(const ConsoleStream &console)
Print out the heaviest branch through the tree.
std::atomic< unsigned int > _execution_list_end
Where the print thread should stop reading the execution list.
void treeRecurseInternal(const PerfNode &node, const Functor &act, const unsigned int level, const bool heaviest, unsigned int current_depth) const
void disableLivePrint()
Completely disables Live Print (cannot be restarted)
std::array< PerfNode *, MOOSE_MAX_STACK_SIZE > _stack
The full callstack. Currently capped at a depth of 100.
VariadicTable< std::string, unsigned long int, Real, Real, Real, long int > HeaviestTable
static MooseEnum dataTypeEnum()
DataType in a MooseEnum for use in InputParameters in objects that query the PerfGraph with sectionDa...
void push(const PerfID id)
Add a Node onto the end of the end of the current callstack.
void print(const ConsoleStream &console, unsigned int level)
Print the tree out.
friend void dataStore(std::ostream &, PerfGraph &, void *)
std::vector< CumulativeSectionInfo * > _cumulative_section_info_ptrs
Pointers into _cumulative_section_info indexed on PerfID This is here for convenience and speed so we...
bool active() const
Whether or not timing is active.
bool _disable_live_print
Whether or not live print is disabled (cannot be turned on again)
void setLivePrintAll(bool active)
Forces all sections to be output live.
void pop()
Remove a Node from the end of the current scope.
void printHeaviestSections(const ConsoleStream &console, const unsigned int num_sections)
Print out the heaviest sections that were timed.
std::thread _print_thread
The thread for printing sections as they execute.
bool _live_print_all
Whether or not to put everything in the perf graph.
std::array< SectionIncrement, MAX_EXECUTION_LIST_SIZE > _execution_list
A circular buffer for holding the execution list, this is read by the printing loop.
bool _destructing
Tell the print thread to teardown.
const std::string _root_name
Name of the root node.
Scope guard for starting and stopping timing for a node.
std::chrono::steady_clock::duration totalTime() const
The time this Node plus all of it's children took.
const std::map< PerfID, std::unique_ptr< PerfNode > > & children() const
Get the children.
PerfID id() const
Get the ID of this Node.
A class for "pretty printing" a table of data.
The place where all timed sections will be stored.
const PerfGraphSectionInfo & readSectionInfo(PerfID section_id) const
Special accessor just for PerfGraph so that no locking is needed in PerfGraph.
bool sectionExists(const std::string §ion_name) const
Whether or not a section with that name has been registered @section_name The name of the section.
uint8_t processor_id_type
Use to hold the cumulative time and memory for each section, which comes from all of the PerfNodes th...
unsigned long int _num_calls
Number of times this section has been called.
Real _total
Total amount of time used.
Real _self
Amount of time used within this section (without children)
long int _children_memory
Amount of memory gained by children.
Real _children
Amount of time used by children.
long int _self_memory
Amount of memory gained within this section (without children)
long int _total_memory
Total memory gain for this section.