BLRealTimeMonitor Class Reference

#include <BLRealTimeMonitor.hh>

List of all members.


Detailed Description

class BLRealTimeMonitor creates a versatile multi-state monitor of real time usage, with resolution of microseconds (or the system clock resolution).

This entire class is inline.

Public Member Functions

 BLRealTimeMonitor ()
 constructor and destructor.
 ~BLRealTimeMonitor ()
void setState (int newState)
 setState() stops accumulating in the previous state, and starts accumulating in the new state. state can range from 0 to 7; -1 means no accumulation. initial state is -1.
void incrState (int incr=1)
 incrState() adds the increment to the current state.
float getTime (int _state)
 getTime() returns the total elapsed time (in seconds) while in the specified state.

Static Public Member Functions

static float estimateResolution ()
 estimateResolution() will estimate the resolution of the real-time monitor.
static float estimateResolution1 ()
 estimateResolution1() will make a single estimate of the resolution of the real-time monitor.

Private Attributes

long long total [8]
int state
long long last


Constructor & Destructor Documentation

BLRealTimeMonitor::BLRealTimeMonitor (  )  [inline]

constructor and destructor.

References last, state, and total.

00036                             { for(int i=0; i<8; ++i) total[i]=0LL; state=-1; 
00037 last=0LL;
00038         }

BLRealTimeMonitor::~BLRealTimeMonitor (  )  [inline]

00039 { }


Member Function Documentation

void BLRealTimeMonitor::setState ( int  newState  )  [inline]

setState() stops accumulating in the previous state, and starts accumulating in the new state. state can range from 0 to 7; -1 means no accumulation. initial state is -1.

References last, state, BLTime::timeus(), and total.

Referenced by incrState().

00045                                     {
00046                 long long now = BLTime::timeus();
00047 if(now < last) fprintf(stderr,"now=%lld last=%lld\n",now,last);
00048 last = now;
00049                 if(state >= 0 && state < 8) total[state] += now;
00050 if(state>=0 && total[state] < 0LL) fprintf(stderr,"state=%d total=%lld now=%lld last=%lld\n",state,total[state],now,last);
00051                 state = newState;
00052                 if(state >= 0 && state < 8) total[state] -= now;
00053         }

void BLRealTimeMonitor::incrState ( int  incr = 1  )  [inline]

incrState() adds the increment to the current state.

References setState(), and state.

00056 { setState(state+incr); }

float BLRealTimeMonitor::getTime ( int  _state  )  [inline]

getTime() returns the total elapsed time (in seconds) while in the specified state.

References state, BLTime::timeus(), and total.

00060                                   {
00061                 if(_state < 0 || _state >= 8) return 0.0;
00062                 long long v=total[_state];
00063                 if(state == _state) v += BLTime::timeus();
00064                 return (float)v/1.0E6;
00065         }

static float BLRealTimeMonitor::estimateResolution (  )  [inline, static]

estimateResolution() will estimate the resolution of the real-time monitor.

References estimateResolution1().

00069                                           {
00070                 float v=0.0;
00071                 for(int i=0; i<100; ++i) {
00072                         v += estimateResolution1();
00073                         if(v > 0.1)
00074                                 return v/(i+1);
00075                 }
00076                 return v/100.0;
00077         }

static float BLRealTimeMonitor::estimateResolution1 (  )  [inline, static]

estimateResolution1() will make a single estimate of the resolution of the real-time monitor.

References BLTime::timeus().

Referenced by estimateResolution().

00081                                            {
00082                 long long now=0LL, prev=BLTime::timeus();
00083                 do {
00084                         now = BLTime::timeus();
00085                 } while(now == prev);
00086                 prev = now;
00087                 do {
00088                         now = BLTime::timeus();
00089                 } while(now == prev);
00090                 return (float)(now-prev)/1.0E6;
00091         }


Member Data Documentation

long long BLRealTimeMonitor::total[8] [private]

int BLRealTimeMonitor::state [private]

long long BLRealTimeMonitor::last [private]

Referenced by BLRealTimeMonitor(), and setState().


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