aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/debug
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-09-02 17:58:22 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-09-02 17:58:22 -0700
commitcd0a91e4e1ff40c66a8dd7b56a861203508112c6 (patch)
treebdfd6340a072e1f1abb909e10ec41ec41667fc3a /src/core/lib/debug
parente4605634a70fa67afaa593b1aa0465c5cf19c361 (diff)
Fix some rounding bugs
Diffstat (limited to 'src/core/lib/debug')
-rw-r--r--src/core/lib/debug/stats.c23
-rw-r--r--src/core/lib/debug/stats.h2
-rw-r--r--src/core/lib/debug/stats_data.c76
3 files changed, 58 insertions, 43 deletions
diff --git a/src/core/lib/debug/stats.c b/src/core/lib/debug/stats.c
index a65dfe49b1..91ca0aa76e 100644
--- a/src/core/lib/debug/stats.c
+++ b/src/core/lib/debug/stats.c
@@ -62,24 +62,21 @@ void grpc_stats_diff(const grpc_stats_data *b, const grpc_stats_data *a,
}
}
-int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx *exec_ctx, double value,
+int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx *exec_ctx, int value,
const int *table, int table_size) {
GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(exec_ctx);
- if (value < 0.0) return 0;
- if (value >= table[table_size - 1]) return table_size - 1;
- int a = 0;
- int b = table_size - 1;
- while (a < b) {
- int c = a + ((b - a) / 2);
- if (value < table[c]) {
- b = c - 1;
- } else if (value > table[c]) {
- a = c + 1;
+ const int *const start = table;
+ while (table_size > 0) {
+ int step = table_size / 2;
+ const int *it = table + step;
+ if (value >= *it) {
+ table = it + 1;
+ table_size -= step + 1;
} else {
- return c;
+ table_size = step;
}
}
- return a;
+ return (int)(table - start) - 1;
}
size_t grpc_stats_histo_count(const grpc_stats_data *stats,
diff --git a/src/core/lib/debug/stats.h b/src/core/lib/debug/stats.h
index 9d729c20f4..09d190d488 100644
--- a/src/core/lib/debug/stats.h
+++ b/src/core/lib/debug/stats.h
@@ -50,7 +50,7 @@ void grpc_stats_collect(grpc_stats_data *output);
void grpc_stats_diff(const grpc_stats_data *b, const grpc_stats_data *a,
grpc_stats_data *c);
char *grpc_stats_data_as_json(const grpc_stats_data *data);
-int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx *exec_ctx, double value,
+int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx *exec_ctx, int value,
const int *table, int table_size);
double grpc_stats_histo_percentile(const grpc_stats_data *data,
grpc_stats_histograms histogram,
diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c
index 4829f78579..57cbafc817 100644
--- a/src/core/lib/debug/stats_data.c
+++ b/src/core/lib/debug/stats_data.c
@@ -91,17 +91,20 @@ void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int value) {
union {
double dbl;
uint64_t uint;
- } _val;
+ } _val, _bkt;
_val.dbl = value;
if (_val.uint < 4682617712558473216ull) {
- GRPC_STATS_INC_HISTOGRAM(
- (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE,
- grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 4);
+ int bucket =
+ grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 5;
+ _bkt.dbl = grpc_stats_table_0[bucket];
+ bucket -= (_val.uint < _bkt.uint);
+ GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE,
+ bucket);
return;
}
GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE,
grpc_stats_histo_find_bucket_slow(
- (exec_ctx), _val.dbl, grpc_stats_table_0, 64));
+ (exec_ctx), value, grpc_stats_table_0, 64));
}
void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, int value) {
value = GPR_CLAMP(value, 0, 1024);
@@ -113,17 +116,20 @@ void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, int value) {
union {
double dbl;
uint64_t uint;
- } _val;
+ } _val, _bkt;
_val.dbl = value;
if (_val.uint < 4637300241308057600ull) {
- GRPC_STATS_INC_HISTOGRAM(
- (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE,
- grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 48)] + 11);
+ int bucket =
+ grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 48)] + 12;
+ _bkt.dbl = grpc_stats_table_2[bucket];
+ bucket -= (_val.uint < _bkt.uint);
+ GRPC_STATS_INC_HISTOGRAM((exec_ctx),
+ GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, bucket);
return;
}
GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE,
grpc_stats_histo_find_bucket_slow(
- (exec_ctx), _val.dbl, grpc_stats_table_2, 64));
+ (exec_ctx), value, grpc_stats_table_2, 64));
}
void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, int value) {
value = GPR_CLAMP(value, 0, 16777216);
@@ -135,17 +141,20 @@ void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, int value) {
union {
double dbl;
uint64_t uint;
- } _val;
+ } _val, _bkt;
_val.dbl = value;
if (_val.uint < 4682617712558473216ull) {
- GRPC_STATS_INC_HISTOGRAM(
- (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE,
- grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 4);
+ int bucket =
+ grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 5;
+ _bkt.dbl = grpc_stats_table_0[bucket];
+ bucket -= (_val.uint < _bkt.uint);
+ GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE,
+ bucket);
return;
}
GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE,
grpc_stats_histo_find_bucket_slow(
- (exec_ctx), _val.dbl, grpc_stats_table_0, 64));
+ (exec_ctx), value, grpc_stats_table_0, 64));
}
void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx *exec_ctx, int value) {
value = GPR_CLAMP(value, 0, 16777216);
@@ -157,17 +166,20 @@ void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx *exec_ctx, int value) {
union {
double dbl;
uint64_t uint;
- } _val;
+ } _val, _bkt;
_val.dbl = value;
if (_val.uint < 4682617712558473216ull) {
- GRPC_STATS_INC_HISTOGRAM(
- (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER,
- grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 4);
+ int bucket =
+ grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 5;
+ _bkt.dbl = grpc_stats_table_0[bucket];
+ bucket -= (_val.uint < _bkt.uint);
+ GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER,
+ bucket);
return;
}
GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER,
grpc_stats_histo_find_bucket_slow(
- (exec_ctx), _val.dbl, grpc_stats_table_0, 64));
+ (exec_ctx), value, grpc_stats_table_0, 64));
}
void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, int value) {
value = GPR_CLAMP(value, 0, 1024);
@@ -179,17 +191,20 @@ void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, int value) {
union {
double dbl;
uint64_t uint;
- } _val;
+ } _val, _bkt;
_val.dbl = value;
if (_val.uint < 4637300241308057600ull) {
- GRPC_STATS_INC_HISTOGRAM(
- (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE,
- grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 48)] + 11);
+ int bucket =
+ grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 48)] + 12;
+ _bkt.dbl = grpc_stats_table_2[bucket];
+ bucket -= (_val.uint < _bkt.uint);
+ GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE,
+ bucket);
return;
}
GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE,
grpc_stats_histo_find_bucket_slow(
- (exec_ctx), _val.dbl, grpc_stats_table_2, 64));
+ (exec_ctx), value, grpc_stats_table_2, 64));
}
void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx,
int value) {
@@ -202,18 +217,21 @@ void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx,
union {
double dbl;
uint64_t uint;
- } _val;
+ } _val, _bkt;
_val.dbl = value;
if (_val.uint < 4682617712558473216ull) {
+ int bucket =
+ grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 5;
+ _bkt.dbl = grpc_stats_table_0[bucket];
+ bucket -= (_val.uint < _bkt.uint);
GRPC_STATS_INC_HISTOGRAM(
- (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE,
- grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 4);
+ (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, bucket);
return;
}
GRPC_STATS_INC_HISTOGRAM((exec_ctx),
GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE,
grpc_stats_histo_find_bucket_slow(
- (exec_ctx), _val.dbl, grpc_stats_table_0, 64));
+ (exec_ctx), value, grpc_stats_table_0, 64));
}
const int grpc_stats_histo_buckets[6] = {64, 64, 64, 64, 64, 64};
const int grpc_stats_histo_start[6] = {0, 64, 128, 192, 256, 320};