#include "CTBtraceClock.hxx"
Public Methods | |
CTBtraceClock () | |
CTBtraceClock (const char *c_text, bool b_start=false, bool b_print=false) | |
~CTBtraceClock () | |
void | Start () |
void | Stop () |
void | Reset () |
bool | IsStarted () const |
double | CpuTime () |
double | ElapsedTime () |
CTBint | NInterval () |
void | ToStream (ostream &os=cout) |
Private Types | |
enum | { e_cputime = 0x1, e_elatime = 0x2 } |
Private Methods | |
void | Init (const char *c_text, bool b_start=false, bool b_print=false) |
void | Update (int i_flags) |
Private Attributes | |
const char * | mc_text |
bool | mb_started |
bool | mb_autoprint |
double | md_cputime |
double | md_elatime |
double | md_cpustart |
double | md_elastart |
CTBint | mi_intervals |
Related Functions | |
(Note that these are not member functions.) | |
ostream & | operator<< (ostream &os, CTBtraceClock &obj) |
A CTBtraceClock
object accumulates the CPU and elapsed time summed over an arbritary number of Start/Stop intervals. The times can be either accessed through the CpuTime()
and ElapsedTime()
member functions or directly printed by dropping the object into an ostream
.
One form of the constructor allows to associate a name with the object, optionally start it at creation time and print it to cout
at destruction time. This allows to determine the CPU and elapsed time of a code block with just one additional line of code. For example
{ CTBtraceClock tc("Initialization",true,true); ... }
will print for each activation of the code block a line like
Initialization CPU 0.390s elapsed 0.548s ( 71.17%)
The Start()
, Stop()
and Reset()
member functions do the obvious things and allow to selectively measure the time in parts of a program. For example
{ CTBtraceClock tc("Time in foo2()"); for (int i = 0; i < 100; i++) { foo1(); tc.Start(); foo2(); tc.Stop(); foo3(); } cout << tc; }
will selectively determine the time spent in foo2()
and ignore the time spent in foo1()
and foo3()
.
Note, that the resolution of CTBtraceClock
depends on the underlaying operating system. It is typically 10 msec for the CPU time and 1 msec for the elapsed time. A start/stop cycle is quite cheap, typically 10 usec on a 333 Mhz Pentium system under Linux.
Definition at line 16 of file CTBtraceClock.hxx.
|
Definition at line 36 of file CTBtraceClock.hxx. |
|
Default constructor.
Definition at line 77 of file CTBtraceClock.cxx. |
|
Construct with name and options.
A timer object with the name c_text is initialized and started if b_start is Definition at line 89 of file CTBtraceClock.cxx. |
|
Destructor.
The times are printed to Definition at line 101 of file CTBtraceClock.cxx. |
|
Start timer.
Definition at line 109 of file CTBtraceClock.cxx. Referenced by Init().
|
|
Stop timer.
Definition at line 122 of file CTBtraceClock.cxx. |
|
Reset timer.
Definition at line 133 of file CTBtraceClock.cxx. |
|
Returns
Definition at line 17 of file CTBtraceClock.icc. |
|
Returns CPU time in sec.
Definition at line 25 of file CTBtraceClock.icc. |
|
Returns elapsed time in sec.
Definition at line 34 of file CTBtraceClock.icc. |
|
Returns the number of start/stop intervals.
Definition at line 43 of file CTBtraceClock.icc. |
|
ostream insertion. A line of the form
**** CPU 0.390s elapsed 0.548s ( 71.17%)
is printed to os, including a trailing Definition at line 158 of file CTBtraceClock.cxx. Referenced by operator<<(), and ~CTBtraceClock().
|
|
Helper function for constructors.
Definition at line 177 of file CTBtraceClock.cxx. Referenced by CTBtraceClock().
|
|
Update integrated times.
Definition at line 191 of file CTBtraceClock.cxx. Referenced by CpuTime(), ElapsedTime(), Stop(), and ToStream().
|
|
ostream insertion operator.
Definition at line 54 of file CTBtraceClock.icc. |
|
prefix text.
Definition at line 45 of file CTBtraceClock.hxx. |
|
true if started.
Definition at line 46 of file CTBtraceClock.hxx. |
|
print on destruct.
Definition at line 47 of file CTBtraceClock.hxx. |
|
integrated CPU time.
Definition at line 48 of file CTBtraceClock.hxx. |
|
integrated elapsed time.
Definition at line 49 of file CTBtraceClock.hxx. |
|
CPU time at start.
Definition at line 50 of file CTBtraceClock.hxx. |
|
elapsed time at start.
Definition at line 51 of file CTBtraceClock.hxx. |
|
count accumulated intervals.
Definition at line 52 of file CTBtraceClock.hxx. |