Public Member Functions | Static Public Member Functions | List of all members
STimerList_< TimerType > Class Template Reference

#include <stattimer.hpp>

+ Collaboration diagram for STimerList_< TimerType >:

Public Member Functions

STimerRecords calcStat (int i)
 
STimerRecords calcStat (const char *label)
 
void initTimeBuf (int i, int len)
 
int initTimeBuf (const char *label, int len)
 
void laptime (int i)
 
int laptime (const char *label)
 
std::string report (int i, STimerReporterFunc fn=NULL)
 
std::string report (const char *label, STimerReporterFunc fn=NULL)
 
std::string report (STimerReporterFunc fn=NULL) const
 
void setLabel (int i, const char *label)
 
void setReporterFunc (int i, STimerReporterFunc fn)
 
int setReporterFunc (const char *label, STimerReporterFunc fn)
 
void setReporterFunc (STimerReporterFunc fn)
 
void start (int i)
 
int start (const char *label)
 
 STimerList_ (int n, const STimerReporterFunc rfunc=reporterDefault, const std::string &outfile="")
 
 STimerList_ (STimerReporterFunc const rfunc=reporterDefault, const std::string &outfile="")
 
void stop (int i)
 
int stop (const char *label)
 
 ~STimerList_ ()
 

Static Public Member Functions

static std::string reporterDefault (STimerRecords &rec)
 
static std::string reporterTSV (STimerRecords &rec)
 

Detailed Description

template<typename TimerType>
class STimerList_< TimerType >

Class that contains and manages multiple timers.

This is designed as a template class just for testability (i.e. to cope with a mock subclass of STimer). Users should always use STimerList, which is typedef of STimerList_<STimer>.

Definition at line 70 of file stattimer.hpp.

Constructor & Destructor Documentation

§ STimerList_() [1/2]

template<typename TimerType>
STimerList_< TimerType >::STimerList_ ( int  n,
const STimerReporterFunc  rfunc = reporterDefault,
const std::string &  outfile = "" 
)
inline

Constructor that generates n timers.

Parameters
n[in] number of timers initially generated
rfunc[in] reporter function, which defaults to reporterDefault
outfile[in] output file name, which defaults to stdout

Definition at line 219 of file stattimer.hpp.

§ STimerList_() [2/2]

template<typename TimerType>
STimerList_< TimerType >::STimerList_ ( STimerReporterFunc const  rfunc = reporterDefault,
const std::string &  outfile = "" 
)
inline

Constructor that generates ntimer_default (= 20) timers.

Parameters
rfunc[in] reporter function, which defaults to reporterDefault
outfile[in] output file name, which defaults to stdout

Definition at line 228 of file stattimer.hpp.

§ ~STimerList_()

template<typename TimerType>
STimerList_< TimerType >::~STimerList_ ( )
inline

Destructor that calls report() and put the result to stdout.

Definition at line 234 of file stattimer.hpp.

Member Function Documentation

§ calcStat() [1/2]

template<typename TimerType>
STimerRecords STimerList_< TimerType >::calcStat ( int  i)
inline

Generate and return STimerRecords object of the timer whose id = i. If the timer i does not exist, it is automatically generated (and an empty records are returned). This may be useful when a user wants the statistics in a form other than string.

Parameters
i[in] Timer id
Returns
Generated record object

Definition at line 468 of file stattimer.hpp.

§ calcStat() [2/2]

template<typename TimerType>
STimerRecords STimerList_< TimerType >::calcStat ( const char *  label)
inline

Generate and return STimerRecords object of the timer with the specified label. See description of calcStat(i).

Parameters
label[in] Timer label
Returns
Generated record object

Definition at line 481 of file stattimer.hpp.

§ initTimeBuf() [1/2]

template<typename TimerType>
void STimerList_< TimerType >::initTimeBuf ( int  i,
int  len 
)
inline

Initialize the buffer to record recent values of elapsed time of the timer whose id = i. If the timer does not exist, it is automatially generated.

After this is called, the timer starts recording the elapsed time between each start() and stop() (or consecutive laptime()) in addition to updating the statistics data. Only the recent len values at most are preserved. The recorded values can be accessed in the STimerReporterFunc function as rec.timebuf vector.

Parameters
i[in] Timer id
len[in] Length of the buffer

Definition at line 332 of file stattimer.hpp.

§ initTimeBuf() [2/2]

template<typename TimerType>
int STimerList_< TimerType >::initTimeBuf ( const char *  label,
int  len 
)
inline

Initialize the buffer to record recent values of elapsed time of the timer with the specified label. See description of initTimeBuf(i, len).

Parameters
label[in] Timer label
len[in] Length of the buffer
Returns
Timer id associated to the label

Definition at line 345 of file stattimer.hpp.

§ laptime() [1/2]

template<typename TimerType>
void STimerList_< TimerType >::laptime ( int  i)
inline

Record the lap time of the timer whose id = i. If the timer does not exist, it is automatially generated. It is equivalent to calling stop(i) followed by start(i) with zero delay.

Parameters
i[in] Timer id

Definition at line 299 of file stattimer.hpp.

§ laptime() [2/2]

template<typename TimerType>
int STimerList_< TimerType >::laptime ( const char *  label)
inline

Record the lap time of the timer with the specified label. See description of laptime(int).

Parameters
label[in] Timer label
Returns
Timer id associated to the label

Definition at line 311 of file stattimer.hpp.

§ report() [1/3]

template<typename TimerType>
std::string STimerList_< TimerType >::report ( int  i,
STimerReporterFunc  fn = NULL 
)
inline

Generate the report of the timer i and return it as string. Reporter function to be used can optionally be specified. If the timer i does not exist, it is automatically generated (and an empty string is reported).

Parameters
i[in] Timer id
fn[in] Reporter function. If not specified, the function set by setReporterFunc is used.
Returns
Generated report

Definition at line 424 of file stattimer.hpp.

§ report() [2/3]

template<typename TimerType>
std::string STimerList_< TimerType >::report ( const char *  label,
STimerReporterFunc  fn = NULL 
)
inline

Generate the report of the timer with the specified label and return it as string. See description of report(i, fn).

Parameters
label[in] Timer label
fn[in] Reporter function. If not specified, the function set by setReporterFunc is used.
Returns
Generated report

Definition at line 437 of file stattimer.hpp.

§ report() [3/3]

template<typename TimerType>
std::string STimerList_< TimerType >::report ( STimerReporterFunc  fn = NULL) const
inline

Generate the reports of all the timer and return the concatenated string of the reports. Reporter function to be used can optionally be specified.

Parameters
fn[in] Reporter function. If not specified, the function set by setReporterFunc is used for each timer.
Returns
Generated report

Definition at line 450 of file stattimer.hpp.

§ reporterDefault()

template<typename TimerType>
static std::string STimerList_< TimerType >::reporterDefault ( STimerRecords rec)
inlinestatic

Definition at line 488 of file stattimer.hpp.

§ reporterTSV()

template<typename TimerType>
static std::string STimerList_< TimerType >::reporterTSV ( STimerRecords rec)
inlinestatic

Definition at line 505 of file stattimer.hpp.

§ setLabel()

template<typename TimerType>
void STimerList_< TimerType >::setLabel ( int  i,
const char *  label 
)
inline

Set the label to the timer whose id = i. If the same label already exists (for another timer), that old label is cleared in advance. If the timer i does not exist, it is automatically generated. If the timer i already has a label, the old label is cleared in advance.

Parameters
i[in] Timer id to which the label is set.
label[in] Timer label

Definition at line 360 of file stattimer.hpp.

§ setReporterFunc() [1/3]

template<typename TimerType>
void STimerList_< TimerType >::setReporterFunc ( int  i,
STimerReporterFunc  fn 
)
inline

Set the reporter function to the timer i. If the timer does not exist, it is automatially generated. The reporter functions of the other timers are unchanged.

Parameters
i[in] Timer id to which the reporter function is associated
fn[in] Reporter function. When fn = NULL, nothing is reported.

Definition at line 382 of file stattimer.hpp.

§ setReporterFunc() [2/3]

template<typename TimerType>
int STimerList_< TimerType >::setReporterFunc ( const char *  label,
STimerReporterFunc  fn 
)
inline

Set the reporter function to the timer specified with the label. If the timer does not exist, it is automatially generated. The reporter functions of the other timers are unchanged.

Parameters
label[in] Label of the timer to which the reporter function is associated
fn[in] Reporter function. When fn = NULL, nothing is reported.
Returns
Timer id associated to the label

Definition at line 395 of file stattimer.hpp.

§ setReporterFunc() [3/3]

template<typename TimerType>
void STimerList_< TimerType >::setReporterFunc ( STimerReporterFunc  fn)
inline

Set the reporter function to all the timers. This reporter function is also applied to the timers that will be generated in future.

Parameters
fn[in] Reporter function. When fn = NULL, nothing is reported.

Definition at line 407 of file stattimer.hpp.

§ start() [1/2]

template<typename TimerType>
void STimerList_< TimerType >::start ( int  i)
inline

Start the timer whose id = i. If the timer does not exist, it is automatially generated.

Parameters
i[in] Timer id

Definition at line 249 of file stattimer.hpp.

§ start() [2/2]

template<typename TimerType>
int STimerList_< TimerType >::start ( const char *  label)
inline

Start the timer with the specified label. If the timer does not exist, it is automatially generated.

Parameters
label[in] Timer label
Returns
Timer id associated to the label

Definition at line 260 of file stattimer.hpp.

§ stop() [1/2]

template<typename TimerType>
void STimerList_< TimerType >::stop ( int  i)
inline

Stop the timer whose id = i and update the statistics record. If the timer has not been started, nothing is done. If the timer does not exist, it is automatially generated (and of course nothing is recorded).

Parameters
i[in] Timer id

Definition at line 274 of file stattimer.hpp.

§ stop() [2/2]

template<typename TimerType>
int STimerList_< TimerType >::stop ( const char *  label)
inline

Stop the timer with the specified label. See description of stop(int).

Parameters
label[in] Timer label
Returns
Timer id associated to the label

Definition at line 286 of file stattimer.hpp.


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