ls1-MarDyn
ls1-MarDyn molecular dynamics code
Classes | Public Types | Public Member Functions | List of all members
TimerProfiler Class Reference

Class for managing timers across the simulation. More...

#include <TimerProfiler.h>

Public Types

enum class  Displaymode { ALL , ACTIVE , NON_ZERO , NONE }
 

Public Member Functions

 TimerProfiler ()
 Constructor of TimerProfiler. More...
 
void readXML (XMLfileUnits &xmlconfig)
 Read in XML configuration for TimerProfiler. More...
 
void setDisplayMode (Displaymode mode)
 
Displaymode getDisplayMode ()
 
void registerTimer (std::string timerName, std::vector< std::string > parentTimerNames, Timer *timer=nullptr, bool activate=true)
 Adds a timer in the container. More...
 
TimergetTimer (std::string timerName)
 Gets a pointer to the timer with name "timerName". More...
 
void activateTimer (std::string timerName)
 Activates the timer "timerName". More...
 
void deactivateTimer (std::string timerName)
 Deactivates the timer "timerName". More...
 
void setSyncTimer (std::string timerName, bool sync)
 Sets sync mode of the timer "timerName". More...
 
void print (std::string timerName, std::string outputPrefix="")
 
void printTimers (std::string timerName=_baseTimerName, std::string outputPrefix="")
 Prints time collected by timer "timerName" and the time from all of its descendants. More...
 
void start (std::string timerName)
 Starts the timer "timerName". More...
 
void stop (std::string timerName)
 
void reset (std::string timerName)
 
void resetTimers (std::string timerName=_baseTimerName)
 Resets the timer "timerName" and all of its descendants. More...
 
void readInitialTimersFromFile (std::string fileName)
 Sets up initial configuration of the timers during the simulation. More...
 
void setOutputString (std::string timerName, std::string outputString)
 Sets the output string for the timer output. More...
 
std::string getOutputString (std::string timerName)
 
double getTime (std::string timerName)
 Gets the time collected by timer "timerName". More...
 
void incrementTimerTimestepCounter ()
 Increment the timestep-counter.
 
unsigned long getNumElapsedIterations () const
 get the number of iterations since the last resetting of all timers. More...
 

Detailed Description

Class for managing timers across the simulation.

This class is a manager for all timers in the simulation. There should only be one instance of this class across the simulation. This class supports a hierarchical structure of the timers and can output the time of the timers in a more user-friendly manner

Constructor & Destructor Documentation

◆ TimerProfiler()

TimerProfiler::TimerProfiler ( )

Constructor of TimerProfiler.

The constructor creates a "virtual" base timer (named "_baseTimer"), which is the top of the timer hierarchy. All other inserted timers are sub-timers of this _baseTimer. Also reads and initializes all timers in the timer config-file.

Member Function Documentation

◆ activateTimer()

void TimerProfiler::activateTimer ( std::string  timerName)

Activates the timer "timerName".

Parameters
timerNameThe name of the timer to be activated

◆ deactivateTimer()

void TimerProfiler::deactivateTimer ( std::string  timerName)

Deactivates the timer "timerName".

Gets the output string for the timer output.

Parameters
timerNameThe name of the timer to be deactivated
timerNameThe name of the timer whose output string is requested
Returns
The string to be displayed whenever the timer is printed

◆ getNumElapsedIterations()

unsigned long TimerProfiler::getNumElapsedIterations ( ) const
inline

get the number of iterations since the last resetting of all timers.

Returns
Number of iterations since last resetting of timers.

◆ getTime()

double TimerProfiler::getTime ( std::string  timerName)

Gets the time collected by timer "timerName".

Parameters
timerNameThe name of the timer whose collected time is requested
Returns
Time collected by timer "timerName"

◆ getTimer()

Timer * TimerProfiler::getTimer ( std::string  timerName)

Gets a pointer to the timer with name "timerName".

Parameters
timerNameThe name of the requested timer
Returns
A pointer to the requested timer or nullptr if the timer is not an actual timer

◆ printTimers()

void TimerProfiler::printTimers ( std::string  startingTimerName = _baseTimerName,
std::string  outputPrefix = "" 
)

Prints time collected by timer "timerName" and the time from all of its descendants.

Parameters
timerNameThe name of the timer from where to start the print; defaults to the base timer
outputPrefixString prefix for the hierarchical print

◆ readInitialTimersFromFile()

void TimerProfiler::readInitialTimersFromFile ( std::string  fileName)

Sets up initial configuration of the timers during the simulation.

Reads timers provided in the timer config-file and inserts them in the container, (de-)activates them and creates the hierarchical structure of the timers.

Parameters
fileNameThe name of the timer config-file

◆ readXML()

void TimerProfiler::readXML ( XMLfileUnits xmlconfig)

Read in XML configuration for TimerProfiler.

The following xml object structure is handled by this method:

<programtimers>
<displaymode>all|active|non-zero|none</displaymode>
</programtimers>

Display mode explanation:

  • all: display all registered timer
  • active: display all active timers
  • non-zero: display all timers which have non zero time
  • none: do not display timers

◆ registerTimer()

void TimerProfiler::registerTimer ( std::string  timerName,
std::vector< std::string >  parentTimerNames,
Timer timer = nullptr,
bool  activate = true 
)

Adds a timer in the container.

Parameters
timerNameThe name of the timer to be added
parentTimerNamesThe names of the timers of which this timer is a sub-timer of
timerA pointer to the timer to be added in the container or nullptr if this is just a "virtual" timer ("manager" of timers)
activateBoolean variable indicating whether the timer should be active or not. All calls to an inactive timer will have no effect on it

◆ resetTimers()

void TimerProfiler::resetTimers ( std::string  timerName = _baseTimerName)

Resets the timer "timerName" and all of its descendants.

Parameters
timerNameThe name of the timer to be deactivated; defaults to the base timer

◆ setOutputString()

void TimerProfiler::setOutputString ( std::string  timerName,
std::string  outputString 
)

Sets the output string for the timer output.

Parameters
timerNameThe name of the timer whose output string is to be modified
outputStringThe string to be displayed whenever the timer is printed

◆ setSyncTimer()

void TimerProfiler::setSyncTimer ( std::string  timerName,
bool  sync 
)

Sets sync mode of the timer "timerName".

Parameters
timerNameThe name of the timer whose sync mode is to be set
syncBoolean variable indicating whether the timer should be synced or not

◆ start()

void TimerProfiler::start ( std::string  timerName)

Starts the timer "timerName".

Parameters
timerNameThe name of the timer to be started

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