Skip to content

How to add timers

Ye Luo edited this page Jun 28, 2019 · 5 revisions

In your class header file, add #include <Utilities/NewTimer.h> and add a timer enumeration and define the timer names in the header file. For example, put the following under "protected/private"

enum PSTimers
{
  PS_newpos,
  PS_donePbyP,
  PS_setActive,
  PS_update
};

TimerList_t myTimers;

Initialize timers in the constructor.

# if you have many timers;
const TimerNameList_t<PSTimers>
PSTimerNames = {{PS_newpos, "ParticleSet::computeNewPosDTandSK"},
                {PS_donePbyP, "ParticleSet::donePbyP"},
                {PS_setActive, "ParticleSet::setActive"},
                {PS_update, "ParticleSet::update"}};
setup_timers(myTimers, PSTimerNames, timer_level_fine);

# if you have just one timer
myTimers[PS_update] = TimerManager.createTimer("ParticleSet::update", timer_level_fine);

Two ways of using timers. Using ScopedTimer is recommended.

// RAII pattern
{
  ScopedTimer update_scope(myTimers[PS_update]);
  //timed body
}

// explicit controlling
myTimers[PS_update]->start();
//timed body
myTimers[PS_update]->stop();
Clone this wiki locally