https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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.
 
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.
 
PerfID sectionID (const std::string &section_name) const
 Given a name return the PerfID @section_name The name of the section.
 
const PerfGraphSectionInfosectionInfo (const PerfID section_id) const
 Given a PerfID return the PerfGraphSectionInfo @section_id The ID.
 
bool sectionExists (const std::string &section_name) const
 Whether or not a section with that name has been registered @section_name The name of the section.
 
bool sectionExists (const PerfID section_id) const
 Whether or not a section with that id has been registered @section_id The ID.
 
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.
 
const PerfGraphSectionInforeadSectionInfo (PerfID section_id) const
 Special accessor just for PerfGraph so that no locking is needed in PerfGraph.
 
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.
 

Private Attributes

friend PerfGraph
 This is only here so that PerfGraph can access readSectionInfo.
 
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.
 
std::deque< PerfGraphSectionInfo_id_to_item
 Vector of IDs to Items.
 
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::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.
 

Friends

PerfGraphRegistrygetPerfGraphRegistry ()
 So it can be constructed.
 

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

Definition at line 28 of file PerfGraphRegistry.C.

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.

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 registerItem(const std::string &key, CreateItem &create_item)
Registers an item with key key if said key does not exist.
std::size_t id(const std::string &key) const

Referenced by registerSection(), and registerSection().

◆ 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 32 of file GeneralRegistry.h.

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:311
std::unordered_map< std::string, std::size_t, std::hash< std::string > > _key_to_id
Map of keys to IDs.
const std::string _name
The name of this registry; used in error handling.
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...

◆ 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 41 of file GeneralRegistry.h.

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 46 of file GeneralRegistry.h.

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

◆ 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 52 of file GeneralRegistry.h.

133{
134 if (id >= _id_to_item.size())
135 mooseError(_name, ": ID '", id, "' is not registered");
136 return _id_to_item[id];
137}

◆ 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 37 of file GeneralRegistry.h.

109{
110 std::lock_guard<std::mutex> lock(_key_to_id_mutex);
111 return _key_to_id.count(key);
112}

◆ numSections()

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

Definition at line 140 of file PerfGraphRegistry.h.

140{ return size(); }

Referenced by PerfGraph::update().

◆ 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.

166 {
167 return itemNonLocking(section_id);
168 };

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

◆ 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 64 of file GeneralRegistry.h.

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}

◆ 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.

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.

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

◆ 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}

◆ sectionExists() [1/2]

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

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

Returns
Whether or not it exists

Definition at line 135 of file PerfGraphRegistry.h.

135{ return idExists(section_id); }

◆ sectionExists() [2/2]

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

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

Returns
Whether or not it exists

Definition at line 128 of file PerfGraphRegistry.h.

128{ return keyExists(section_name); }

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

◆ sectionID()

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

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

Returns
the ID

Definition at line 111 of file PerfGraphRegistry.h.

111{ return id(section_name); }

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

◆ sectionInfo()

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

Given a PerfID return the PerfGraphSectionInfo @section_id The ID.

Returns
The PerfGraphSectionInfo

Definition at line 118 of file PerfGraphRegistry.h.

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

Referenced by PerfGraphReporter::finalize(), PerfGraphLivePrint::inSamePlace(), PerfGraph::printHeaviestSections(), PerfGraphLivePrint::printLiveMessage(), and PerfGraphLivePrint::printStats().

◆ size()

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

Definition at line 27 of file GeneralRegistry.h.

90{
91 std::lock_guard<std::mutex> lock(_id_to_item_mutex);
92 return _id_to_item.size();
93}

◆ void::dataStore()

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

Friends And Related Symbol 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: