source: trunk/FACT++/src/Timers.h@ 13709

Last change on this file since 13709 was 10183, checked in by tbretz, 14 years ago
New import.
File size: 1.0 KB
Line 
1class Timers
2{
3private:
4 std::ostream &fOut;
5
6 Time fT[4];
7
8 int fSum[2];
9 int fCnt;
10
11 int fNwait;
12
13public:
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};
Note: See TracBrowser for help on using the repository browser.