FACT++  1.0
Timers.h
Go to the documentation of this file.
1 class Timers
2 {
3 private:
4  std::ostream &fOut;
5 
6  Time fT[4];
7 
8  int fSum[2];
9  int fCnt;
10 
11  int fNwait;
12 
13 public:
14  Timers(std::ostream &out=std::cout) : fOut(out) { fSum[0] = fSum[1] = fCnt = fNwait = 0;/*fT[0] = Time(); fT[1] = Time(); fT[2] = Time(); fT[3] = Time();*/ }
15 
16  void SetT() { fT[1] = Time(); }
17 
18  void Proc(bool cond, int maxwait=5000, int interval=10000)
19  {
20  fT[2] = Time();
21 
22  fSum[0] += (fT[2]-fT[1]).total_microseconds();
23  fSum[1] += (fT[1]-fT[3]).total_microseconds();
24  fCnt++;
25 
26  if (cond)
27  {
28  usleep(std::max(maxwait-(int)(fT[2]-fT[3]).total_microseconds(), 1));
29  fNwait++;
30  }
31 
32  const int diff = (fT[2]-fT[0]).total_milliseconds();
33  if (diff > interval)
34  {
35  fOut << "Rate(10s): poll=" << fSum[0]/fCnt << "us exec=" << fSum[1]/fCnt << "us (" << fNwait <<"/" << fCnt << ")" << std::endl;
36 
37  fSum[0] = fSum[1] = fCnt = fNwait = 0;
38  fT[0] = Time();
39  }
40 
41  fT[3] = Time();
42  }
43 };
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
int fCnt
Definition: Timers.h:9
Time fT[4]
Definition: Timers.h:6
int fSum[2]
Definition: Timers.h:8
Definition: Timers.h:1
int fNwait
Definition: Timers.h:11
Timers(std::ostream &out=std::cout)
Definition: Timers.h:14
void Proc(bool cond, int maxwait=5000, int interval=10000)
Definition: Timers.h:18
static pthread_cond_t cond
Definition: feeserver.c:242
void SetT()
Definition: Timers.h:16
std::ostream & fOut
Definition: Timers.h:4