aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/support/histogram.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lib/support/histogram.cc')
-rw-r--r--src/core/lib/support/histogram.cc51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/core/lib/support/histogram.cc b/src/core/lib/support/histogram.cc
index 6d5ead9aa6..73c821a28b 100644
--- a/src/core/lib/support/histogram.cc
+++ b/src/core/lib/support/histogram.cc
@@ -51,29 +51,29 @@ struct gpr_histogram {
/* number of buckets */
size_t num_buckets;
/* the buckets themselves */
- uint32_t *buckets;
+ uint32_t* buckets;
};
/* determine a bucket index given a value - does no bounds checking */
-static size_t bucket_for_unchecked(gpr_histogram *h, double x) {
+static size_t bucket_for_unchecked(gpr_histogram* h, double x) {
return (size_t)(log(x) * h->one_on_log_multiplier);
}
/* bounds checked version of the above */
-static size_t bucket_for(gpr_histogram *h, double x) {
+static size_t bucket_for(gpr_histogram* h, double x) {
size_t bucket = bucket_for_unchecked(h, GPR_CLAMP(x, 1.0, h->max_possible));
GPR_ASSERT(bucket < h->num_buckets);
return bucket;
}
/* at what value does a bucket start? */
-static double bucket_start(gpr_histogram *h, double x) {
+static double bucket_start(gpr_histogram* h, double x) {
return pow(h->multiplier, x);
}
-gpr_histogram *gpr_histogram_create(double resolution,
+gpr_histogram* gpr_histogram_create(double resolution,
double max_bucket_start) {
- gpr_histogram *h = (gpr_histogram *)gpr_malloc(sizeof(gpr_histogram));
+ 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;
@@ -87,16 +87,16 @@ gpr_histogram *gpr_histogram_create(double resolution,
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);
+ h->buckets = (uint32_t*)gpr_zalloc(sizeof(uint32_t) * h->num_buckets);
return h;
}
-void gpr_histogram_destroy(gpr_histogram *h) {
+void gpr_histogram_destroy(gpr_histogram* h) {
gpr_free(h->buckets);
gpr_free(h);
}
-void gpr_histogram_add(gpr_histogram *h, double x) {
+void gpr_histogram_add(gpr_histogram* h, double x) {
h->sum += x;
h->sum_of_squares += x * x;
h->count++;
@@ -109,7 +109,7 @@ void gpr_histogram_add(gpr_histogram *h, double x) {
h->buckets[bucket_for(h, x)]++;
}
-int gpr_histogram_merge(gpr_histogram *dst, const gpr_histogram *src) {
+int gpr_histogram_merge(gpr_histogram* dst, const gpr_histogram* src) {
if ((dst->num_buckets != src->num_buckets) ||
(dst->multiplier != src->multiplier)) {
/* Fail because these histograms don't match */
@@ -121,7 +121,7 @@ int gpr_histogram_merge(gpr_histogram *dst, const gpr_histogram *src) {
return 1;
}
-void gpr_histogram_merge_contents(gpr_histogram *dst, const uint32_t *data,
+void gpr_histogram_merge_contents(gpr_histogram* dst, const uint32_t* data,
size_t data_count, double min_seen,
double max_seen, double sum,
double sum_of_squares, double count) {
@@ -141,7 +141,7 @@ void gpr_histogram_merge_contents(gpr_histogram *dst, const uint32_t *data,
}
}
-static double threshold_for_count_below(gpr_histogram *h, double count_below) {
+static double threshold_for_count_below(gpr_histogram* h, double count_below) {
double count_so_far;
double lower_bound;
double upper_bound;
@@ -183,46 +183,45 @@ static double threshold_for_count_below(gpr_histogram *h, double count_below) {
should lie */
lower_bound = bucket_start(h, (double)lower_idx);
upper_bound = bucket_start(h, (double)(lower_idx + 1));
- return GPR_CLAMP(upper_bound -
- (upper_bound - lower_bound) *
- (count_so_far - count_below) /
- h->buckets[lower_idx],
+ return GPR_CLAMP(upper_bound - (upper_bound - lower_bound) *
+ (count_so_far - count_below) /
+ h->buckets[lower_idx],
h->min_seen, h->max_seen);
}
}
-double gpr_histogram_percentile(gpr_histogram *h, double percentile) {
+double gpr_histogram_percentile(gpr_histogram* h, double percentile) {
return threshold_for_count_below(h, h->count * percentile / 100.0);
}
-double gpr_histogram_mean(gpr_histogram *h) {
+double gpr_histogram_mean(gpr_histogram* h) {
GPR_ASSERT(h->count != 0);
return h->sum / h->count;
}
-double gpr_histogram_stddev(gpr_histogram *h) {
+double gpr_histogram_stddev(gpr_histogram* h) {
return sqrt(gpr_histogram_variance(h));
}
-double gpr_histogram_variance(gpr_histogram *h) {
+double gpr_histogram_variance(gpr_histogram* h) {
if (h->count == 0) return 0.0;
return (h->sum_of_squares * h->count - h->sum * h->sum) /
(h->count * h->count);
}
-double gpr_histogram_maximum(gpr_histogram *h) { return h->max_seen; }
+double gpr_histogram_maximum(gpr_histogram* h) { return h->max_seen; }
-double gpr_histogram_minimum(gpr_histogram *h) { return h->min_seen; }
+double gpr_histogram_minimum(gpr_histogram* h) { return h->min_seen; }
-double gpr_histogram_count(gpr_histogram *h) { return h->count; }
+double gpr_histogram_count(gpr_histogram* h) { return h->count; }
-double gpr_histogram_sum(gpr_histogram *h) { return h->sum; }
+double gpr_histogram_sum(gpr_histogram* h) { return h->sum; }
-double gpr_histogram_sum_of_squares(gpr_histogram *h) {
+double gpr_histogram_sum_of_squares(gpr_histogram* h) {
return h->sum_of_squares;
}
-const uint32_t *gpr_histogram_get_contents(gpr_histogram *h, size_t *size) {
+const uint32_t* gpr_histogram_get_contents(gpr_histogram* h, size_t* size) {
*size = h->num_buckets;
return h->buckets;
}