MoReFEM
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
MoReFEM::TimeKeep Class Reference

Class used to profile crudely (through prints) the code. More...

#include <TimeKeep.hpp>

Inheritance diagram for MoReFEM::TimeKeep:
Collaboration diagram for MoReFEM::TimeKeep:

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 TimeKeepCreateOrGetInstance (const std::source_location location=std::source_location::current(), Args &&... args)
 Call instance of the singleton.
 
static TimeKeepGetInstance (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.
 

Private Attributes

std::ofstream stream_
 Stream into which the prints are logged.
 
const std::chrono::time_point< std::chrono::steady_clock > init_time_
 Time at which Init() has been called.
 
std::chrono::time_point< std::chrono::steady_clock > previous_call_time_
 Time of the previous call to PrintTimeElapsed.
 

Static Private Attributes

static TimeKeepinstance_
 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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TimeKeep()

MoReFEM::TimeKeep::TimeKeep ( std::ofstream && stream)
explicitprivate

Constructor.

Parameters
[in,out]streamStream upon which time information will be written.

Member Function Documentation

◆ ClassName()

static const std::string & MoReFEM::TimeKeep::ClassName ( )
static

Returns the name of the class (required for some Singleton-related errors).

Returns
Name of the class.

◆ TimeElapsedSinceBeginning()

std::string MoReFEM::TimeKeep::TimeElapsedSinceBeginning ( ) const

Return the time elapsed since the beginning of the simulation.

Returns
Time elapsed since the beginning of the simulation, under the format HH::MM::SS.

◆ PrintEndProgram()

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.

◆ CreateOrGetInstance()

static TimeKeep & MoReFEM::Utilities::Singleton< TimeKeep >::CreateOrGetInstance ( const std::source_location location = std::source_location::current(),
Args &&... args )
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:

  • If we do not know whether the instance already exists or not. The most typical example is when a value is registered within the singleton in an anonymous namespace.
  • If we know for sure it is the first call to the singleton. For instance the initialization of TimeKeep sinfgleton class that sets the initial time.

In all other cases, call instead GetInstance().

Template Parameters
ArgsVariadic template arguments.
Parameters
[in]argsArguments passed to the constructor if the object is to be built.
Parameters
[in]locationSTL object with relevant information about the calling site (usually to help when an exception is thrown.
Returns
Instance of the singleton.

◆ GetInstance()

static TimeKeep & MoReFEM::Utilities::Singleton< TimeKeep >::GetInstance ( const std::source_location location = std::source_location::current())
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.

Parameters
[in]locationSTL object with relevant information about the calling site (usually to help when an exception is thrown.
Returns
Instance of the singleton.

◆ Create()

static void MoReFEM::Utilities::Singleton< TimeKeep >::Create ( Args &&... args)
staticprivateinherited

Create the singleton in first invocation.

Template Parameters
ArgsVariadic template arguments.
Parameters
[in]argsArguments passed to the constructor.

◆ OnDeadReference()

static void MoReFEM::Utilities::Singleton< TimeKeep >::OnDeadReference ( const std::source_location location = std::source_location::current())
staticprivateinherited

Gets called if dead reference detected.

Parameters
[in]locationSTL object with relevant information about the calling site (usually to help when an exception is thrown.

Field Documentation

◆ destroyed_

bool MoReFEM::Utilities::Singleton< TimeKeep >::destroyed_
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.

◆ singleton_mutex_

std::mutex MoReFEM::Utilities::Singleton< TimeKeep >::singleton_mutex_
staticprivateinherited

Mutex object.

This follows item 16 of Scott Meyers's "Effective Modern C++", which advises to make const member functions thread safe.


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