#include <BLRealTimeMonitor.hh>
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 |
BLRealTimeMonitor::BLRealTimeMonitor | ( | ) | [inline] |
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 state, BLTime::timeus(), and total.
Referenced by incrState().
00043 { 00044 long long now = BLTime::timeus(); 00045 if(state >= 0 && state < 8) total[state] += now; 00046 state = newState; 00047 if(state >= 0 && state < 8) total[state] -= now; 00048 }
void BLRealTimeMonitor::incrState | ( | int | incr = 1 |
) | [inline] |
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.
00055 { 00056 if(_state < 0 || _state >= 8) return 0.0; 00057 long long v=total[_state]; 00058 if(state == _state) v += BLTime::timeus(); 00059 return (float)v/1.0E6; 00060 }
static float BLRealTimeMonitor::estimateResolution | ( | ) | [inline, static] |
estimateResolution() will estimate the resolution of the real-time monitor.
References estimateResolution1().
00064 { 00065 float v=0.0; 00066 for(int i=0; i<100; ++i) { 00067 v += estimateResolution1(); 00068 if(v > 0.1) 00069 return v/(i+1); 00070 } 00071 return v/100.0; 00072 }
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().
00076 { 00077 long long now=0LL, prev=BLTime::timeus(); 00078 do { 00079 now = BLTime::timeus(); 00080 } while(now == prev); 00081 prev = now; 00082 do { 00083 now = BLTime::timeus(); 00084 } while(now == prev); 00085 return (float)(now-prev)/1.0E6; 00086 }
long long BLRealTimeMonitor::total[8] [private] |
Referenced by BLRealTimeMonitor(), getTime(), and setState().
int BLRealTimeMonitor::state [private] |
Referenced by BLRealTimeMonitor(), getTime(), incrState(), and setState().