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

static const TimerNameList_t<PSTimers> PSTimerNames;

TimerList_t myTimers;

Define timer names in the cpp file.

const TimerNameList_t<ParticleSet::PSTimers>
ParticleSet::PSTimerNames = {{PS_newpos, "ParticleSet::computeNewPosDistTablesAndSK"},
                            {PS_donePbyP, "ParticleSet::donePbyP"},
                            {PS_setActive, "ParticleSet::setActive"},
                            {PS_update, "ParticleSet::update"}};

Initialize timers in the constructor.

setup_timers(myTimers, PSTimerNames, 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