Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBtraceClock Class Reference

Timer class for program tracing. More...

#include "CTBtraceClock.hxx"

List of all members.

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)


Detailed Description

Timer class for program tracing.

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.


Member Enumeration Documentation

anonymous enum [private]
 

Enumeration values:
e_cputime   update CPU time.
e_elatime   update elapsed time.

Definition at line 36 of file CTBtraceClock.hxx.


Constructor & Destructor Documentation

CTBtraceClock::CTBtraceClock
 

Default constructor.

Definition at line 77 of file CTBtraceClock.cxx.

CTBtraceClock::CTBtraceClock const char * c_text,
bool b_start = false,
bool b_print = false
 

Construct with name and options.

A timer object with the name c_text is initialized and started if b_start is true. If b_print is true, the timer object will be printed to cout at destruction time.

Definition at line 89 of file CTBtraceClock.cxx.

CTBtraceClock::~CTBtraceClock
 

Destructor.

The times are printed to cout if the b_print flag was true at construction time.

Definition at line 101 of file CTBtraceClock.cxx.


Member Function Documentation

void CTBtraceClock::Start
 

Start timer.

Definition at line 109 of file CTBtraceClock.cxx.

Referenced by Init().

void CTBtraceClock::Stop
 

Stop timer.

Definition at line 122 of file CTBtraceClock.cxx.

void CTBtraceClock::Reset
 

Reset timer.

Definition at line 133 of file CTBtraceClock.cxx.

bool CTBtraceClock::IsStarted const [inline]
 

Returns true if timer is started.

Definition at line 17 of file CTBtraceClock.icc.

double CTBtraceClock::CpuTime [inline]
 

Returns CPU time in sec.

Definition at line 25 of file CTBtraceClock.icc.

double CTBtraceClock::ElapsedTime [inline]
 

Returns elapsed time in sec.

Definition at line 34 of file CTBtraceClock.icc.

CTBint CTBtraceClock::NInterval [inline]
 

Returns the number of start/stop intervals.

Definition at line 43 of file CTBtraceClock.icc.

void CTBtraceClock::ToStream ostream & os = cout
 

ostream insertion.

A line of the form

****                            CPU     0.390s  elapsed     0.548s  ( 71.17%)

is printed to os, including a trailing endl. The prefix "****" is given by the c_text parameter at construction time.

Definition at line 158 of file CTBtraceClock.cxx.

Referenced by operator<<(), and ~CTBtraceClock().

void CTBtraceClock::Init const char * c_text,
bool b_start = false,
bool b_print = false
[private]
 

Helper function for constructors.

Definition at line 177 of file CTBtraceClock.cxx.

Referenced by CTBtraceClock().

void CTBtraceClock::Update int i_flags [private]
 

Update integrated times.

Definition at line 191 of file CTBtraceClock.cxx.

Referenced by CpuTime(), ElapsedTime(), Stop(), and ToStream().


Friends And Related Function Documentation

ostream & operator<< ostream & os,
CTBtraceClock & obj
[related]
 

ostream insertion operator.

Definition at line 54 of file CTBtraceClock.icc.


Member Data Documentation

const char* CTBtraceClock::mc_text [private]
 

prefix text.

Definition at line 45 of file CTBtraceClock.hxx.

bool CTBtraceClock::mb_started [private]
 

true if started.

Definition at line 46 of file CTBtraceClock.hxx.

bool CTBtraceClock::mb_autoprint [private]
 

print on destruct.

Definition at line 47 of file CTBtraceClock.hxx.

double CTBtraceClock::md_cputime [private]
 

integrated CPU time.

Definition at line 48 of file CTBtraceClock.hxx.

double CTBtraceClock::md_elatime [private]
 

integrated elapsed time.

Definition at line 49 of file CTBtraceClock.hxx.

double CTBtraceClock::md_cpustart [private]
 

CPU time at start.

Definition at line 50 of file CTBtraceClock.hxx.

double CTBtraceClock::md_elastart [private]
 

elapsed time at start.

Definition at line 51 of file CTBtraceClock.hxx.

CTBint CTBtraceClock::mi_intervals [private]
 

count accumulated intervals.

Definition at line 52 of file CTBtraceClock.hxx.


The documentation for this class was generated from the following files:
Generated at Fri Oct 24 18:14:11 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001