Пример #1
0
gpr_histogram *gpr_histogram_create(double resolution,
                                    double max_bucket_start) {
  gpr_histogram *h = (gpr_histogram *)gpr_malloc(sizeof(gpr_histogram));
  GPR_ASSERT(resolution > 0.0);
  GPR_ASSERT(max_bucket_start > resolution);
  h->sum = 0.0;
  h->sum_of_squares = 0.0;
  h->multiplier = 1.0 + resolution;
  h->one_on_log_multiplier = 1.0 / log(1.0 + resolution);
  h->max_possible = max_bucket_start;
  h->count = 0.0;
  h->min_seen = max_bucket_start;
  h->max_seen = 0.0;
  h->num_buckets = bucket_for_unchecked(h, max_bucket_start) + 1;
  GPR_ASSERT(h->num_buckets > 1);
  GPR_ASSERT(h->num_buckets < 100000000);
  h->buckets = (uint32_t *)gpr_zalloc(sizeof(uint32_t) * h->num_buckets);
  return h;
}
Пример #2
0
/* bounds checked version of the above */
static size_t bucket_for(gpr_histogram *h, double x) {
  size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 0, h->max_possible));
  GPR_ASSERT(bucket < h->num_buckets);
  return bucket;
}