Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

cleanup, fix test

  • Loading branch information...
commit 0fb81e0e65b875ed62874beb4ff3371d919e7763 1 parent f10e5bb
Andy Gross authored August 30, 2011
30  c_src/histogram_metric.hpp
@@ -29,14 +29,14 @@
29 29
 #include "sample.hpp"
30 30
 
31 31
 
32  
-template <typename I=unsigned int>
  32
+template <typename IntType=unsigned long>
33 33
 class histogram
34 34
 {
35 35
 public:
36 36
     histogram() 
37 37
     : sample_(1028), 
38  
-      min_(std::numeric_limits<I>::max()), 
39  
-      max_(std::numeric_limits<I>::min()), 
  38
+      min_(std::numeric_limits<IntType>::max()), 
  39
+      max_(std::numeric_limits<IntType>::min()), 
40 40
       sum_(0), 
41 41
       count_(0),
42 42
       variance_(-1, 0) { } 
@@ -44,14 +44,14 @@ class histogram
44 44
     void clear() 
45 45
     {
46 46
         sample_.clear();
47  
-        min_ = std::numeric_limits<I>::max(),
48  
-        max_ = std::numeric_limits<I>::min(),
  47
+        min_ = std::numeric_limits<IntType>::max(),
  48
+        max_ = std::numeric_limits<IntType>::min(),
49 49
         sum_ = 0;
50 50
         count_ = 0;
51 51
         variance_ = std::make_pair(-1, 0);
52 52
     }
53 53
         
54  
-    void update(I value)
  54
+    void update(IntType value)
55 55
     {
56 56
         ++count_;
57 57
         sample_.update(value);
@@ -96,14 +96,14 @@ class histogram
96 96
    }
97 97
 
98 98
 
99  
-   I count() const 
  99
+   IntType count() const 
100 100
    { 
101 101
        return count_; 
102 102
    }
103 103
 
104 104
    struct calc_percentile
105 105
    {
106  
-       calc_percentile(const std::vector<I>& values)
  106
+       calc_percentile(const std::vector<IntType>& values)
107 107
            : values_(values) { }
108 108
 
109 109
        double operator()(double percentile) const
@@ -116,7 +116,7 @@ class histogram
116 116
            return lower+(pos-std::floor(pos))*(upper-lower);
117 117
        }
118 118
    private:
119  
-       const std::vector<I>& values_;
  119
+       const std::vector<IntType>& values_;
120 120
    };
121 121
          
122 122
 
@@ -125,7 +125,7 @@ class histogram
125 125
        std::vector<double> scores(pvec.size(), 0.0);
126 126
        if (count_)
127 127
        {
128  
-           std::vector<I> values = sample_.values();
  128
+           std::vector<IntType> values = sample_.values();
129 129
            std::sort(values.begin(), values.end());
130 130
            std::transform(pvec.begin(), pvec.end(), 
131 131
                           scores.begin(), calc_percentile(values));
@@ -133,11 +133,11 @@ class histogram
133 133
        return scores;
134 134
    }
135 135
    private:
136  
-        uniform_sample<I> sample_;
137  
-        I min_;
138  
-        I max_;
139  
-        I sum_;
140  
-        I count_;
  136
+        uniform_sample<IntType> sample_;
  137
+        IntType min_;
  138
+        IntType max_;
  139
+        IntType sum_;
  140
+        IntType count_;
141 141
         std::pair<double, double> variance_;
142 142
 };
143 143
 
2  c_src/sample.hpp
@@ -30,7 +30,7 @@
30 30
 #include <boost/random/mersenne_twister.hpp>
31 31
 #include <boost/random/uniform_int_distribution.hpp>
32 32
 
33  
-template <typename IntType=long>
  33
+template <typename IntType=unsigned long>
34 34
 struct exponentially_decaying_sample
35 35
 {
36 36
     exponentially_decaying_sample(std::size_t size=1024, double alpha=0.015)
8  src/basho_metrics_nifs.erl
@@ -83,6 +83,12 @@ meter_tick(_Ref) ->
83 83
 simple_test() ->
84 84
     {ok, H} = ?MODULE:histogram_new(),
85 85
     [?MODULE:histogram_update(H, I) || I <- lists:seq(0, 1000000)],
86  
-    ?debugFmt("~p~n", [?MODULE:histogram_stats(H)]).
  86
+    [{min,0},
  87
+     {max,1000000},
  88
+     {mean,500000},
  89
+     {count,1000001},
  90
+     {p50,514255},
  91
+     {p95,956215},
  92
+     {p99,991377}] = ?MODULE:histogram_stats(H).
87 93
 
88 94
 -endif.

0 notes on commit 0fb81e0

Please sign in to comment.
Something went wrong with that request. Please try again.