https://mooseframework.inl.gov
PerfGraphInterface.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "PerfGraphInterface.h"
11 #include "PerfGraphRegistry.h"
12 
13 #include "MooseApp.h"
14 
17 {
19  return params;
20 }
21 
23  : _pg_moose_app(*moose_object->parameters().getCheckedPointerParam<MooseApp *>(
24  "_moose_app", "PerfGraphInterface is unable to retrieve the MooseApp pointer!")),
25  _prefix(moose_object->type())
26 {
27 }
28 
29 PerfGraphInterface::PerfGraphInterface(const MooseObject * moose_object, const std::string prefix)
30  : _pg_moose_app(*moose_object->parameters().getCheckedPointerParam<MooseApp *>(
31  "_moose_app", "PerfGraphInterface is unable to retrieve the MooseApp pointer!")),
32  _prefix(prefix)
33 {
34 }
35 
36 PerfGraphInterface::PerfGraphInterface(MooseApp & moose_app, const std::string prefix)
37  : _pg_moose_app(moose_app), _prefix(prefix)
38 {
39 }
40 
41 PerfGraphInterface::PerfGraphInterface(PerfGraph & perf_graph, const std::string prefix)
42  : _pg_moose_app(perf_graph.mooseApp()), _prefix(prefix)
43 {
44 }
45 
46 std::string
47 PerfGraphInterface::timedSectionName(const std::string & section_name) const
48 {
49  return _prefix.empty() ? "" : (_prefix + "::") + section_name;
50 }
51 
52 PerfID
53 PerfGraphInterface::registerTimedSection(const std::string & section_name,
54  const unsigned int level) const
55 {
56  const auto timed_section_name = timedSectionName(section_name);
57  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
58  return moose::internal::getPerfGraphRegistry().registerSection(timed_section_name, level);
59  else
60  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
61 }
62 
63 PerfID
64 PerfGraphInterface::registerTimedSection(const std::string & section_name,
65  const unsigned int level,
66  const std::string & live_message,
67  const bool print_dots) const
68 {
69  const auto timed_section_name = timedSectionName(section_name);
70  if (!moose::internal::getPerfGraphRegistry().sectionExists(timed_section_name))
72  timedSectionName(section_name), level, live_message, print_dots);
73  else
74  return moose::internal::getPerfGraphRegistry().sectionID(timed_section_name);
75 }
76 
77 PerfGraph &
79 {
80  return _pg_moose_app.perfGraph();
81 }
Base class for MOOSE-based applications.
Definition: MooseApp.h:96
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters emptyInputParameters()
unsigned int PerfID
Definition: MooseTypes.h:212
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
PerfID registerSection(const std::string &section_name, const unsigned int level)
Call to register a named section for timing.
std::string timedSectionName(const std::string &section_name) const
const std::string _prefix
A prefix to use for all sections.
PerfID sectionID(const std::string &section_name) const
Given a name return the PerfID The name of the section.
PerfID registerTimedSection(const std::string &section_name, const unsigned int level) const
Call to register a named section for timing.
static InputParameters validParams()
PerfGraph & perfGraph()
Get the PerfGraph.
PerfGraphInterface(const MooseObject *moose_object)
For objects that are MooseObjects with a default prefix of type()
The PerfGraph will hold the master list of all registered performance segments and the head PerfNode...
Definition: PerfGraph.h:43
PerfGraphRegistry & getPerfGraphRegistry()
Get the global PerfGraphRegistry singleton.
MooseApp & _pg_moose_app
The MooseApp that owns the PerfGraph.
PerfGraph & perfGraph()
Get the PerfGraph for this app.
Definition: MooseApp.h:172