Permalink
Browse files

cleanup, fix test

  • Loading branch information...
1 parent f10e5bb commit 0fb81e0e65b875ed62874beb4ff3371d919e7763 @argv0 argv0 committed Aug 31, 2011
Showing with 23 additions and 17 deletions.
  1. +15 −15 c_src/histogram_metric.hpp
  2. +1 −1 c_src/sample.hpp
  3. +7 −1 src/basho_metrics_nifs.erl
View
30 c_src/histogram_metric.hpp
@@ -29,29 +29,29 @@
#include "sample.hpp"
-template <typename I=unsigned int>
+template <typename IntType=unsigned long>
class histogram
{
public:
histogram()
: sample_(1028),
- min_(std::numeric_limits<I>::max()),
- max_(std::numeric_limits<I>::min()),
+ min_(std::numeric_limits<IntType>::max()),
+ max_(std::numeric_limits<IntType>::min()),
sum_(0),
count_(0),
variance_(-1, 0) { }
public:
void clear()
{
sample_.clear();
- min_ = std::numeric_limits<I>::max(),
- max_ = std::numeric_limits<I>::min(),
+ min_ = std::numeric_limits<IntType>::max(),
+ max_ = std::numeric_limits<IntType>::min(),
sum_ = 0;
count_ = 0;
variance_ = std::make_pair(-1, 0);
}
- void update(I value)
+ void update(IntType value)
{
++count_;
sample_.update(value);
@@ -96,14 +96,14 @@ class histogram
}
- I count() const
+ IntType count() const
{
return count_;
}
struct calc_percentile
{
- calc_percentile(const std::vector<I>& values)
+ calc_percentile(const std::vector<IntType>& values)
: values_(values) { }
double operator()(double percentile) const
@@ -116,7 +116,7 @@ class histogram
return lower+(pos-std::floor(pos))*(upper-lower);
}
private:
- const std::vector<I>& values_;
+ const std::vector<IntType>& values_;
};
@@ -125,19 +125,19 @@ class histogram
std::vector<double> scores(pvec.size(), 0.0);
if (count_)
{
- std::vector<I> values = sample_.values();
+ std::vector<IntType> values = sample_.values();
std::sort(values.begin(), values.end());
std::transform(pvec.begin(), pvec.end(),
scores.begin(), calc_percentile(values));
}
return scores;
}
private:
- uniform_sample<I> sample_;
- I min_;
- I max_;
- I sum_;
- I count_;
+ uniform_sample<IntType> sample_;
+ IntType min_;
+ IntType max_;
+ IntType sum_;
+ IntType count_;
std::pair<double, double> variance_;
};
View
2 c_src/sample.hpp
@@ -30,7 +30,7 @@
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
-template <typename IntType=long>
+template <typename IntType=unsigned long>
struct exponentially_decaying_sample
{
exponentially_decaying_sample(std::size_t size=1024, double alpha=0.015)
View
8 src/basho_metrics_nifs.erl
@@ -83,6 +83,12 @@ meter_tick(_Ref) ->
simple_test() ->
{ok, H} = ?MODULE:histogram_new(),
[?MODULE:histogram_update(H, I) || I <- lists:seq(0, 1000000)],
- ?debugFmt("~p~n", [?MODULE:histogram_stats(H)]).
+ [{min,0},
+ {max,1000000},
+ {mean,500000},
+ {count,1000001},
+ {p50,514255},
+ {p95,956215},
+ {p99,991377}] = ?MODULE:histogram_stats(H).
-endif.

0 comments on commit 0fb81e0

Please sign in to comment.