~ubuntu-branches/ubuntu/quantal/ceph/quantal

« back to all changes in this revision

Viewing changes to src/test/old/testcounter.cc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-07-16 09:56:24 UTC
  • mfrom: (0.3.11)
  • mto: This revision was merged to the branch mainline in revision 17.
  • Revision ID: package-import@ubuntu.com-20120716095624-azr2w4hbhei1rxmx
Tags: upstream-0.48
ImportĀ upstreamĀ versionĀ 0.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "common/DecayCounter.h"
 
3
 
 
4
#include <list>
 
5
using namespace std;
 
6
 
 
7
struct RealCounter {
 
8
public:
 
9
  list<int> hits;
 
10
  
 
11
  void hit(int ms) {
 
12
        hits.push_back(ms);
 
13
  }
 
14
  
 
15
  int get(double hl, int now) {
 
16
        trim(now-hl);
 
17
        return hits.size();
 
18
  }
 
19
 
 
20
  void trim(int to) {
 
21
        while (!hits.empty() &&
 
22
                   hits.front() < to) 
 
23
          hits.pop_front();
 
24
  }
 
25
 
 
26
 
 
27
};
 
28
 
 
29
int main(int argc, char **argv)
 
30
{
 
31
  int target;
 
32
  double hl = atof(argv[1]);
 
33
  cerr << "halflife " << hl << endl;
 
34
 
 
35
  DecayCounter dc(hl);
 
36
  RealCounter rc;
 
37
 
 
38
  utime_t now = ceph_clock_now(g_ceph_context);
 
39
 
 
40
  for (int ms=0; ms < 300*1000; ms++) {
 
41
        if (ms % 30000 == 0) {
 
42
          target = 1 + (rand() % 10) * 10;
 
43
          if (ms > 200000) target = 0;
 
44
        }
 
45
 
 
46
        if (target &&
 
47
                (rand() % (1000/target) == 0)) {
 
48
          dc.hit();
 
49
          rc.hit(ms);
 
50
        }
 
51
 
 
52
        if (ms % 500 == 0) dc.get(now);
 
53
        if (ms % 100 == 0) {
 
54
          //dc.get(now);
 
55
          DecayCounter o = dc;
 
56
          cout << ms << "\t"
 
57
                   << target*hl << "\t"
 
58
                   << rc.get(hl*1000, ms) << "\t"
 
59
                   << o.get(now) << "\t" 
 
60
                   << dc.val << "\t"
 
61
                //                 << dc.delta << "\t"
 
62
                   << o.get_last_vel() << "\t"
 
63
                   << o.get_last() + o.get_last_vel() << "\t"
 
64
                   << endl;
 
65
        }
 
66
 
 
67
        now += .001;
 
68
  }
 
69
 
 
70
}