https://mooseframework.inl.gov
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
moose::internal::PerfGraphRegistry Class Reference

The place where all timed sections will be stored. More...

#include <PerfGraphRegistry.h>

Inheritance diagram for moose::internal::PerfGraphRegistry:
[legend]

Public Member Functions

PerfID registerSection (const std::string &section_name, const unsigned int level)
 Call to register a named section for timing. More...
 
PerfID registerSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true)
 Call to register a named section for timing. More...
 
PerfID sectionID (const std::string &section_name) const
 Given a name return the PerfID The name of the section. More...
 
const PerfGraphSectionInfosectionInfo (const PerfID section_id) const
 Given a PerfID return the PerfGraphSectionInfo The ID. More...
 
bool sectionExists (const std::string &section_name) const
 Whether or not a section with that name has been registered The name of the section. More...
 
bool sectionExists (const PerfID section_id) const
 Whether or not a section with that id has been registered The ID. More...
 
std::size_t numSections () const
 

Private Member Functions

 PerfGraphRegistry ()
 
PerfID actuallyRegisterSection (const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true)
 The internal function that actually carries out the registration. More...
 
const PerfGraphSectionInforeadSectionInfo (PerfID section_id) const
 Special accessor just for PerfGraph so that no locking is needed in PerfGraph. More...
 
friend void ::dataStore (std::ostream &, PerfGraph &, void *)
 
std::size_t size () const
 
std::size_t id (const std::string &key) const
 
bool keyExists (const std::string &key) const
 
bool idExists (const std::size_t id) const
 
const PerfGraphSectionInfoitem (const std::size_t id) const
 
const PerfGraphSectionInfoitemNonLocking (const std::size_t id) const
 
std::size_t registerItem (const std::string &key, CreateItem &create_item)
 
Registers an item with key key if said key does not exist. More...
 

Private Attributes

friend PerfGraph
 This is only here so that PerfGraph can access readSectionInfo. More...
 
const std::string _name
 The name of this registry; used in error handling. More...
 
std::unordered_map< std::string, std::size_t, std::hash< std::string > > _key_to_id
 Map of keys to IDs. More...
 
std::deque< PerfGraphSectionInfo_id_to_item
 Vector of IDs to Items. More...
 
std::mutex _key_to_id_mutex
 Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17. More...
 
std::mutex _id_to_item_mutex
 Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++17. More...
 

Friends

PerfGraphRegistrygetPerfGraphRegistry ()
 So it can be constructed. More...
 

Detailed Description

The place where all timed sections will be stored.

Definition at line 80 of file PerfGraphRegistry.h.

Constructor & Destructor Documentation

◆ PerfGraphRegistry()

moose::internal::PerfGraphRegistry::PerfGraphRegistry ( )
private

Member Function Documentation

◆ actuallyRegisterSection()

PerfID moose::internal::PerfGraphRegistry::actuallyRegisterSection ( const std::string &  section_name,
const unsigned int  level,
const std::string &  live_message,
const bool  print_dots = true 
)
private

The internal function that actually carries out the registration.

Definition at line 55 of file PerfGraphRegistry.C.

Referenced by registerSection().

59 {
60  const auto create_item = [&section_name, &level, &live_message, &print_dots](const std::size_t id)
61  { return PerfGraphSectionInfo(id, section_name, level, live_message, print_dots); };
62  return registerItem(section_name, create_item);
63 }
std::size_t id(const std::string &key) const
std::size_t registerItem(const std::string &key, CreateItem &create_item)
Registers an item with key key if said key does not exist.

◆ id()

std::size_t GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::id ( const std::string &  key) const
inherited
Returns
The ID assocated with the key key

Definition at line 97 of file GeneralRegistry.h.

Referenced by actuallyRegisterSection(), and sectionID().

98 {
99  std::lock_guard<std::mutex> lock(_key_to_id_mutex);
100  const auto it = _key_to_id.find(key);
101  if (it == _key_to_id.end())
102  mooseError(_name, ": Key '", key, "' is not registered");
103  return it->second;
104 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
std::mutex _key_to_id_mutex
Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17...
const std::string _name
The name of this registry; used in error handling.
std::unordered_map< std::string, std::size_t, std::hash< std::string > > _key_to_id
Map of keys to IDs.

◆ idExists()

bool GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::idExists ( const std::size_t  id) const
inherited
Returns
Whether or not the id id is registered

Definition at line 116 of file GeneralRegistry.h.

Referenced by sectionExists().

117 {
118  std::lock_guard<std::mutex> lock(_id_to_item_mutex);
119  return id < _id_to_item.size();
120 }
std::deque< PerfGraphSectionInfo > _id_to_item
Vector of IDs to Items.
std::mutex _id_to_item_mutex
Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++1...

◆ item()

const PerfGraphSectionInfo & GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::item ( const std::size_t  id) const
inherited
Returns
The item associated with the key key (thread safe)

Definition at line 124 of file GeneralRegistry.h.

Referenced by sectionInfo().

125 {
126  std::lock_guard<std::mutex> lock(_id_to_item_mutex);
127  return itemNonLocking(id);
128 }
const PerfGraphSectionInfo & itemNonLocking(const std::size_t id) const
std::mutex _id_to_item_mutex
Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++1...

◆ itemNonLocking()

const PerfGraphSectionInfo & GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::itemNonLocking ( const std::size_t  id) const
protectedinherited
Returns
The item associated with the key key (not thread safe)

Definition at line 132 of file GeneralRegistry.h.

Referenced by readSectionInfo().

133 {
134  if (id >= _id_to_item.size())
135  mooseError(_name, ": ID '", id, "' is not registered");
136  return _id_to_item[id];
137 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
const std::string _name
The name of this registry; used in error handling.
std::size_t id(const std::string &key) const
std::deque< PerfGraphSectionInfo > _id_to_item
Vector of IDs to Items.

◆ keyExists()

bool GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::keyExists ( const std::string &  key) const
inherited
Returns
Whether or not the key key is registered

Definition at line 108 of file GeneralRegistry.h.

Referenced by sectionExists().

109 {
110  std::lock_guard<std::mutex> lock(_key_to_id_mutex);
111  return _key_to_id.count(key);
112 }
std::mutex _key_to_id_mutex
Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17...
std::unordered_map< std::string, std::size_t, std::hash< std::string > > _key_to_id
Map of keys to IDs.

◆ numSections()

std::size_t moose::internal::PerfGraphRegistry::numSections ( ) const
inline
Returns
number of registered sections

Definition at line 140 of file PerfGraphRegistry.h.

Referenced by PerfGraph::update().

140 { return size(); }

◆ readSectionInfo()

const PerfGraphSectionInfo& moose::internal::PerfGraphRegistry::readSectionInfo ( PerfID  section_id) const
inlineprivate

Special accessor just for PerfGraph so that no locking is needed in PerfGraph.

This could probably be removed once we have C++17 with shared_mutex

This function is NOT threadsafe - but it is ok for PerfGraph to call it because only the main thread will be registering sections and only the main thread will be running PerfGraph routines

Returns
the PerfGraphSectionInfo associated with the section_id

Definition at line 165 of file PerfGraphRegistry.h.

Referenced by PerfGraph::pop(), PerfGraph::push(), PerfGraph::recursivelyUpdate(), and PerfGraph::treeRecurseInternal().

166  {
167  return itemNonLocking(section_id);
168  };
const PerfGraphSectionInfo & itemNonLocking(const std::size_t id) const

◆ registerItem()

std::size_t GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::registerItem ( const std::string &  key,
CreateItem &  create_item 
)
protectedinherited


Registers an item with key key if said key does not exist.

Parameters
keyThe key
create_itemLambda called to create an item if the key does not exist. Takes a single argument std::size_t which is the

new ID and should return an Item

Returns
The ID of the item

Definition at line 142 of file GeneralRegistry.h.

Referenced by actuallyRegisterSection().

143 {
144  std::lock_guard<std::mutex> lock_key(_key_to_id_mutex);
145 
146  // Is it already registered?
147  const auto it = _key_to_id.find(key);
148  if (it != _key_to_id.end())
149  return it->second;
150 
151  // It's not registered
152  std::lock_guard<std::mutex> lock_id(_id_to_item_mutex);
153  const auto id = _id_to_item.size();
154  _key_to_id.emplace(key, id);
155  _id_to_item.emplace_back(std::move(create_item(id)));
156  return id;
157 }
std::mutex _key_to_id_mutex
Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17...
std::unordered_map< std::string, std::size_t, std::hash< std::string > > _key_to_id
Map of keys to IDs.
std::size_t id(const std::string &key) const
std::deque< PerfGraphSectionInfo > _id_to_item
Vector of IDs to Items.
std::mutex _id_to_item_mutex
Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++1...

◆ registerSection() [1/2]

unsigned int moose::internal::PerfGraphRegistry::registerSection ( const std::string &  section_name,
const unsigned int  level 
)

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
Returns
The ID of the section - use when starting timing

Definition at line 34 of file PerfGraphRegistry.C.

Referenced by dataLoad(), and PerfGraphInterface::registerTimedSection().

35 {
36  return actuallyRegisterSection(section_name, level, "", false);
37 }
PerfID actuallyRegisterSection(const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true)
The internal function that actually carries out the registration.

◆ registerSection() [2/2]

PerfID moose::internal::PerfGraphRegistry::registerSection ( const std::string &  section_name,
const unsigned int  level,
const std::string &  live_message,
const bool  print_dots = true 
)

Call to register a named section for timing.

Parameters
section_nameThe name of the code section to be timed
levelThe importance of the timer - lower is more important (0 will always come out)
live_messageThe message to be printed to the screen during execution
print_dotsWhether or not progress dots should be printed for this section
Returns
The ID of the section - use when starting timing

Definition at line 40 of file PerfGraphRegistry.C.

44 {
45  if (section_name == "")
46  mooseError("Section name not provided when registering timed section!");
47 
48  if (live_message == "")
49  mooseError("Live message not provided when registering timed section!");
50 
51  return actuallyRegisterSection(section_name, level, live_message, print_dots);
52 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
PerfID actuallyRegisterSection(const std::string &section_name, const unsigned int level, const std::string &live_message, const bool print_dots=true)
The internal function that actually carries out the registration.

◆ sectionExists() [1/2]

bool moose::internal::PerfGraphRegistry::sectionExists ( const std::string &  section_name) const
inline

Whether or not a section with that name has been registered The name of the section.

Returns
Whether or not it exists

Definition at line 128 of file PerfGraphRegistry.h.

Referenced by PerfGraphLivePrint::printStats(), PerfGraph::sectionData(), and PerfGraph::treeRecurseInternal().

128 { return keyExists(section_name); }
bool keyExists(const std::string &key) const

◆ sectionExists() [2/2]

bool moose::internal::PerfGraphRegistry::sectionExists ( const PerfID  section_id) const
inline

Whether or not a section with that id has been registered The ID.

Returns
Whether or not it exists

Definition at line 135 of file PerfGraphRegistry.h.

135 { return idExists(section_id); }

◆ sectionID()

PerfID moose::internal::PerfGraphRegistry::sectionID ( const std::string &  section_name) const
inline

Given a name return the PerfID The name of the section.

Returns
the ID

Definition at line 111 of file PerfGraphRegistry.h.

Referenced by dataLoad(), PerfGraphInterface::registerTimedSection(), and PerfGraph::update().

111 { return id(section_name); }
std::size_t id(const std::string &key) const

◆ sectionInfo()

const PerfGraphSectionInfo& moose::internal::PerfGraphRegistry::sectionInfo ( const PerfID  section_id) const
inline

Given a PerfID return the PerfGraphSectionInfo The ID.

Returns
The PerfGraphSectionInfo

Definition at line 118 of file PerfGraphRegistry.h.

Referenced by dataStore(), PerfGraphLivePrint::inSamePlace(), PerfGraph::printHeaviestSections(), PerfGraphLivePrint::printLiveMessage(), PerfGraphLivePrint::printStats(), and to_json().

119  {
120  return item(section_id);
121  }
const PerfGraphSectionInfo & item(const std::size_t id) const

◆ size()

std::size_t GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::size ( ) const
inherited
Returns
The number of registered items

Definition at line 89 of file GeneralRegistry.h.

Referenced by numSections().

90 {
91  std::lock_guard<std::mutex> lock(_id_to_item_mutex);
92  return _id_to_item.size();
93 }
std::deque< PerfGraphSectionInfo > _id_to_item
Vector of IDs to Items.
std::mutex _id_to_item_mutex
Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++1...

◆ void ::dataStore()

moose::internal::PerfGraphRegistry::void ::dataStore ( std::ostream &  ,
PerfGraph ,
void  
)
private

Friends And Related Function Documentation

◆ getPerfGraphRegistry

PerfGraphRegistry& getPerfGraphRegistry ( )
friend

So it can be constructed.

Definition at line 20 of file PerfGraphRegistry.C.

21 {
22  // In C++11 this is even thread safe! (Lookup "Static Initializers")
23  static PerfGraphRegistry perf_graph_registry_singleton;
24 
25  return perf_graph_registry_singleton;
26 }

Member Data Documentation

◆ _id_to_item

std::deque<PerfGraphSectionInfo > GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::_id_to_item
protectedinherited

Vector of IDs to Items.

Definition at line 72 of file GeneralRegistry.h.

◆ _id_to_item_mutex

std::mutex GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::_id_to_item_mutex
mutableprotectedinherited

Mutex for locking access to _id_to_item NOTE: These can be changed to shared_mutexes once we get C++17.

Definition at line 79 of file GeneralRegistry.h.

◆ _key_to_id

std::unordered_map<std::string , std::size_t, std::hash<std::string > > GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::_key_to_id
protectedinherited

Map of keys to IDs.

Definition at line 70 of file GeneralRegistry.h.

◆ _key_to_id_mutex

std::mutex GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::_key_to_id_mutex
mutableprotectedinherited

Mutex for locking access to _key_to_id NOTE: These can be changed to shared_mutexes once we get C++17.

Definition at line 76 of file GeneralRegistry.h.

◆ _name

const std::string GeneralRegistry< std::string , PerfGraphSectionInfo , std::hash<std::string > >::_name
protectedinherited

The name of this registry; used in error handling.

Definition at line 67 of file GeneralRegistry.h.

◆ PerfGraph

friend moose::internal::PerfGraphRegistry::PerfGraph
private

This is only here so that PerfGraph can access readSectionInfo.

Definition at line 173 of file PerfGraphRegistry.h.


The documentation for this class was generated from the following files: