MoReFEM
|
Class used to profile crudely (through prints) the code. More...
#include <TimeKeep.hpp>
Public Types | |
using | self |
Convenient alias. | |
Public Member Functions | |
std::string | TimeElapsedSinceBeginning () const |
void | PrintEndProgram () |
At the end of the program, write in the stream the time elapsed since beginning. | |
Static Public Member Functions | |
static const std::string & | ClassName () |
Returns the name of the class (required for some Singleton-related errors). | |
static TimeKeep & | CreateOrGetInstance (const std::source_location location=std::source_location::current(), Args &&... args) |
Call instance of the singleton. | |
static TimeKeep & | GetInstance (const std::source_location location=std::source_location::current()) |
Call an instance of the singleton that must already have been created. | |
static void | Destroy () |
Destroy the singleton. | |
Static Private Member Functions | |
static void | Create (Args &&... args) |
Create the singleton in first invocation. | |
static void | OnDeadReference (const std::source_location location=std::source_location::current()) |
Gets called if dead reference detected. | |
static std::mutex & | GetNonCstSingletonMutex () |
Get reference to the singleton mutex. | |
Static Private Attributes | |
static TimeKeep * | instance_ |
Internal pointer to the actual instance. | |
static bool | destroyed_ |
Used for protection against dead reference problem (invocation while the instance has been destroyed). | |
static std::mutex | singleton_mutex_ |
Mutex object. | |
Singleton requirements. | |
class | Utilities::Singleton< TimeKeep > |
Friendship declaration to Singleton template class (to enable call to constructor). | |
TimeKeep (std::ofstream &&stream) | |
Constructor. | |
virtual | ~TimeKeep () override |
Destructor. | |
Class used to profile crudely (through prints) the code.
In 'normal' release mode, this class should be kept at minimum: just keep in memory the starting date, and write the total elapsed time at the end of the simulation. If you define macro MOREFEM_EXTENDED_TIME_KEEP, an additional method named PrintTimeElapsed() is made available so that prints can be added to profile finely time elapsed between each call of this method.
|
explicitprivate |
Constructor.
[in,out] | stream | Stream upon which time information will be written. |
|
static |
Returns the name of the class (required for some Singleton-related errors).
std::string MoReFEM::TimeKeep::TimeElapsedSinceBeginning | ( | ) | const |
Return the time elapsed since the beginning of the simulation.
void MoReFEM::TimeKeep::PrintEndProgram | ( | ) |
At the end of the program, write in the stream the time elapsed since beginning.
Should be called at the end of a Model.
|
staticinherited |
Call instance of the singleton.
If not already existing it will be created on the fly, otherwise the existing one will be used. This method should be called in two cases:
In all other cases, call instead GetInstance().
Args | Variadic template arguments. |
[in] | args | Arguments passed to the constructor if the object is to be built. |
[in] | location | STL object with relevant information about the calling site (usually to help when an exception is thrown. |
|
staticinherited |
Call an instance of the singleton that must already have been created.
This must be called instead of CreateOrGetInstance(location) if T doesn't get a default constructor.
[in] | location | STL object with relevant information about the calling site (usually to help when an exception is thrown. |
|
staticprivateinherited |
Create the singleton in first invocation.
Args | Variadic template arguments. |
[in] | args | Arguments passed to the constructor. |
|
staticprivateinherited |
Gets called if dead reference detected.
[in] | location | STL object with relevant information about the calling site (usually to help when an exception is thrown. |
|
staticprivateinherited |
Used for protection against dead reference problem (invocation while the instance has been destroyed).
Should not occur in our case, but it is much safer to put the protection there anyway.
|
staticprivateinherited |
Mutex object.
This follows item 16 of Scott Meyers's "Effective Modern C++", which advises to make const member functions thread safe.