From 33aeabad66e8083d47f47ddc4bafa4483f1585f8 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 20 Jul 2017 16:02:24 -0700 Subject: begin building out histogram support --- src/core/lib/debug/stats_data.c | 14 ++++-- src/core/lib/debug/stats_data.h | 33 +++++++------ src/core/lib/debug/stats_data.yaml | 9 ++++ tools/codegen/core/gen_stats_data.py | 90 ++++++++++++++++++++++++++++++------ 4 files changed, 111 insertions(+), 35 deletions(-) diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index 2203358a7e..2cd6a9f130 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -1,12 +1,12 @@ /* * Copyright 2017 gRPC authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,6 +20,10 @@ #include "src/core/lib/debug/stats_data.h" const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { - "client_calls_created", "server_calls_created", "syscall_write", - "syscall_read", "syscall_poll", "syscall_wait", + "client_calls_created", + "server_calls_created", + "syscall_write", + "syscall_read", + "syscall_poll", + "syscall_wait", }; diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index c9c2f65c30..3c1d358c5f 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -1,12 +1,12 @@ /* * Copyright 2017 gRPC authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -30,18 +30,21 @@ typedef enum { GRPC_STATS_COUNTER_SYSCALL_WAIT, GRPC_STATS_COUNTER_COUNT } grpc_stats_counters; -#define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) -#define GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) -#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) -#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) -#define GRPC_STATS_INC_SYSCALL_POLL(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_POLL) -#define GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) +typedef enum { + GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, + GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + GRPC_STATS_HISTOGRAM_CLIENT_LATENCY, + GRPC_STATS_HISTOGRAM_COUNT +} grpc_stats_histograms; +#define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) +#define GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) +#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) +#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) +#define GRPC_STATS_INC_SYSCALL_POLL(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_POLL) +#define GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) +#define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE,None) +#define GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, value) GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE,None) +#define GRPC_STATS_INC_CLIENT_LATENCY(exec_ctx, value) GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CLIENT_LATENCY,None) extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]; #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index 8afe48f5cd..6aecbdee75 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -7,3 +7,12 @@ - counter: syscall_read - counter: syscall_poll - counter: syscall_wait +- histogram: tcp_write_size + max: 16777216 # 16 meg max write tracked + buckets: 64 +- histogram: tcp_read_size + max: 16777216 + buckets: 64 +- histogram: client_latency + max: 60e9 + buckets: 128 diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index bc601a89a7..c56e1f2608 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -15,21 +15,70 @@ # limitations under the License. import collections +import ctypes +import math import sys import yaml with open('src/core/lib/debug/stats_data.yaml') as f: attrs = yaml.load(f.read()) -Counter = collections.namedtuple('Counter', 'name') +types = ( + (collections.namedtuple('Counter', 'name'), []), + (collections.namedtuple('Histogram', 'name max buckets'), []), +) -counters = [] +inst_map = dict((t[0].__name__, t[1]) for t in types) + +stats = [] for attr in attrs: - if 'counter' in attr: - counters.append(Counter(name=attr['counter'])) - else: - print 'Error: bad attr %r' % attr + found = False + for t, lst in types: + t_name = t.__name__.lower() + if t_name in attr: + name = attr[t_name] + del attr[t_name] + lst.append(t(name=name, **attr)) + found = True + break + assert found, "Bad decl: %s" % attr + +def dbl2u64(d): + return ctypes.c_ulonglong.from_buffer(ctypes.c_double(d)).value + +def shift_works(mapped_bounds, shift_bits): + for a, b in zip(mapped_bounds, mapped_bounds[1:]): + if (a >> shift_bits) == (b >> shift_bits): + return False + return True + +def find_max_shift(mapped_bounds): + for shift_bits in reversed(range(0,64)): + if shift_works(mapped_bounds, shift_bits): + return shift_bits + return -1 + +def gen_bucket_code(histogram): + bounds = [0, 1] + done_trivial = False + done_unmapped = False + first_nontrivial = None + first_unmapped = None + while len(bounds) < histogram.buckets: + mul = math.pow(float(histogram.max) / bounds[-1], + 1.0 / (histogram.buckets - len(bounds))) + nextb = bounds[-1] * mul + if nextb < bounds[-1] + 1: + nextb = bounds[-1] + 1 + elif not done_trivial: + done_trivial = True + first_nontrivial = len(bounds) + bounds.append(nextb) + if done_trivial: + code_bounds = [dbl2u64(x - first_nontrivial) for x in bounds] + shift_bits = find_max_shift(code_bounds[first_nontrivial:]) + print first_nontrivial, shift_bits, bounds, [hex(x >> shift_bits) for x in code_bounds[first_nontrivial:]] # utility: print a big comment block into a set of files def put_banner(files, banner): @@ -62,14 +111,25 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "#define GRPC_CORE_LIB_DEBUG_STATS_DATA_H" print >>H - print >>H, "typedef enum {" - for ctr in counters: - print >>H, " GRPC_STATS_COUNTER_%s," % ctr.name.upper() - print >>H, " GRPC_STATS_COUNTER_COUNT" - print >>H, "} grpc_stats_counters;" - - for ctr in counters: - print >>H, "#define GRPC_STATS_INC_%s(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_%s)" % (ctr.name.upper(), ctr.name.upper()) + for typename, instances in sorted(inst_map.items()): + print >>H, "typedef enum {" + for inst in instances: + print >>H, " GRPC_STATS_%s_%s," % (typename.upper(), inst.name.upper()) + print >>H, " GRPC_STATS_%s_COUNT" % (typename.upper()) + print >>H, "} grpc_stats_%ss;" % (typename.lower()) + + for ctr in inst_map['Counter']: + print >>H, ("#define GRPC_STATS_INC_%s(exec_ctx) " + + "GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_%s)") % ( + ctr.name.upper(), ctr.name.upper()) + for histogram in inst_map['Histogram']: + print >>H, ("#define GRPC_STATS_INC_%s(exec_ctx, value) " + + "GRPC_STATS_INC_HISTOGRAM((exec_ctx), " + + "GRPC_STATS_HISTOGRAM_%s," + + "%s)") % ( + histogram.name.upper(), + histogram.name.upper(), + gen_bucket_code(histogram)) print >>H, "extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT];" @@ -97,6 +157,6 @@ with open('src/core/lib/debug/stats_data.c', 'w') as C: print >>C, "#include \"src/core/lib/debug/stats_data.h\"" print >>C, "const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = {"; - for ctr in counters: + for ctr in inst_map['Counter']: print >>C, " \"%s\"," % ctr.name print >>C, "};" -- cgit v1.2.3 From 640dfe499edd8e8f4fb2c106886e421dde22b638 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 30 Aug 2017 13:34:49 -0700 Subject: Histogram support --- src/core/lib/debug/stats.c | 43 +++++ src/core/lib/debug/stats.h | 9 + src/core/lib/debug/stats_data.c | 308 ++++++++++++++++++++++++++++++++++- src/core/lib/debug/stats_data.h | 149 +++++++++++++++-- src/core/lib/debug/stats_data.yaml | 4 + src/core/lib/iomgr/tcp_posix.c | 4 + tools/codegen/core/gen_stats_data.py | 152 ++++++++++++++--- 7 files changed, 625 insertions(+), 44 deletions(-) diff --git a/src/core/lib/debug/stats.c b/src/core/lib/debug/stats.c index 4dbd94c724..cb9c78c4f2 100644 --- a/src/core/lib/debug/stats.c +++ b/src/core/lib/debug/stats.c @@ -45,7 +45,31 @@ void grpc_stats_collect(grpc_stats_data *output) { output->counters[i] += gpr_atm_no_barrier_load( &grpc_stats_per_cpu_storage[core].counters[i]); } + for (size_t i = 0; i < GRPC_STATS_HISTOGRAM_BUCKETS; i++) { + output->histograms[i] += gpr_atm_no_barrier_load( + &grpc_stats_per_cpu_storage[core].histograms[i]); + } + } +} + +int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx *exec_ctx, double value, + const double *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; + } else { + return c; + } } + return a; } char *grpc_stats_data_as_json(const grpc_stats_data *data) { @@ -60,6 +84,25 @@ char *grpc_stats_data_as_json(const grpc_stats_data *data) { gpr_strvec_add(&v, tmp); is_first = false; } + for (size_t i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { + gpr_asprintf(&tmp, "%s\"%s\": [", is_first ? "" : ", ", + grpc_stats_histogram_name[i]); + gpr_strvec_add(&v, tmp); + for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) { + gpr_asprintf(&tmp, "%s%" PRIdPTR, j == 0 ? "" : ",", + data->histograms[grpc_stats_histo_start[i] + j]); + gpr_strvec_add(&v, tmp); + } + gpr_asprintf(&tmp, "], \"%s_bkt\": [", grpc_stats_histogram_name[i]); + gpr_strvec_add(&v, tmp); + for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) { + gpr_asprintf(&tmp, "%s%lf", j == 0 ? "" : ",", + grpc_stats_histo_bucket_boundaries[i][j]); + gpr_strvec_add(&v, tmp); + } + gpr_strvec_add(&v, gpr_strdup("]")); + is_first = false; + } gpr_strvec_add(&v, gpr_strdup("}")); tmp = gpr_strvec_flatten(&v, NULL); gpr_strvec_destroy(&v); diff --git a/src/core/lib/debug/stats.h b/src/core/lib/debug/stats.h index 563b108dff..c4086063bc 100644 --- a/src/core/lib/debug/stats.h +++ b/src/core/lib/debug/stats.h @@ -25,6 +25,7 @@ typedef struct grpc_stats_data { gpr_atm counters[GRPC_STATS_COUNTER_COUNT]; + gpr_atm histograms[GRPC_STATS_HISTOGRAM_BUCKETS]; } grpc_stats_data; extern grpc_stats_data *grpc_stats_per_cpu_storage; @@ -36,9 +37,17 @@ extern grpc_stats_data *grpc_stats_per_cpu_storage; (gpr_atm_no_barrier_fetch_add( \ &GRPC_THREAD_STATS_DATA((exec_ctx))->counters[(ctr)], 1)) +#define GRPC_STATS_INC_HISTOGRAM(exec_ctx, histogram, index) \ + (gpr_atm_no_barrier_fetch_add( \ + &GRPC_THREAD_STATS_DATA((exec_ctx)) \ + ->histograms[histogram##_FIRST_SLOT + (index)], \ + 1)) + void grpc_stats_init(void); void grpc_stats_shutdown(void); void grpc_stats_collect(grpc_stats_data *output); 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, + const double *table, int table_size); #endif diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index 2cd6a9f130..b137f1fe65 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -1,12 +1,12 @@ /* * Copyright 2017 gRPC authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,10 +20,300 @@ #include "src/core/lib/debug/stats_data.h" const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { - "client_calls_created", - "server_calls_created", - "syscall_write", - "syscall_read", - "syscall_poll", - "syscall_wait", + "client_calls_created", "server_calls_created", "syscall_write", + "syscall_read", "syscall_poll", "syscall_wait", + "histogram_slow_lookups", }; +const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = { + "tcp_write_size", "tcp_write_iov_size", "tcp_read_size", "client_latency", +}; +const double grpc_stats_table_0[64] = {0, + 1, + 2, + 3, + 4, + 5.17974600698, + 6.70744217421, + 8.68571170472, + 11.2474451301, + 14.5647272503, + 18.8603969544, + 24.4230164536, + 31.6262554885, + 40.9539926456, + 53.032819969, + 68.6741343683, + 88.9286433193, + 115.156946285, + 149.120933174, + 193.102139541, + 250.055009057, + 323.805358672, + 419.307378404, + 542.976429747, + 703.119998467, + 910.495751121, + 1179.03418281, + 1526.77440013, + 1977.07590065, + 2560.18775048, + 3315.28056941, + 4293.07782286, + 5559.26317765, + 7198.89281155, + 9322.10907382, + 12071.5393129, + 15631.8768886, + 20242.2879738, + 26212.4775761, + 33943.4940145, + 43954.6693961, + 56918.5058232, + 73705.8508152, + 95444.3966128, + 123594.433061, + 160046.942783, + 207250.628202, + 268376.403469, + 347530.401059, + 450029.801797, + 582760.01722, + 754637.218056, + 977207.279236, + 1265421.37565, + 1638640.32942, + 2121935.1758, + 2747771.31348, + 3558189.37227, + 4607629.29828, + 5966587.36485, + 7726351.7696, + 10005134.9318, + 12956014.428, + 16777216.0}; +const uint8_t grpc_stats_table_1[87] = { + 0, 1, 3, 3, 4, 6, 6, 7, 9, 9, 10, 12, 12, 13, 15, 15, 16, 18, + 18, 19, 21, 21, 22, 24, 24, 25, 27, 27, 28, 30, 30, 31, 32, 34, 34, 36, + 36, 37, 39, 39, 40, 42, 42, 43, 44, 46, 46, 47, 49, 49, 51, 51, 52, 53, + 55, 55, 56, 58, 58, 59, 61, 61, 63, 63, 64, 65, 67, 67, 68, 70, 70, 71, + 73, 73, 75, 75, 76, 77, 79, 79, 80, 82, 82, 83, 85, 85, 87}; +const double grpc_stats_table_2[64] = {0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12.0020736244, + 13.0954337532, + 14.2883963681, + 15.5900350167, + 17.0102498252, + 18.5598427974, + 20.2505999737, + 22.0953810747, + 24.1082173107, + 26.3044181014, + 28.7006875181, + 31.315251333, + 34.1679956422, + 37.2806181177, + 40.6767930374, + 44.3823513489, + 48.4254771375, + 52.8369219909, + 57.6502388927, + 62.902037423, + 68.6322622068, + 74.8844967285, + 81.7062948236, + 89.1495423679, + 97.2708519163, + 106.131993291, + 115.800363399, + 126.34949884, + 137.859635225, + 150.418317437, + 164.121065485, + 179.072101023, + 195.38514005, + 213.184257818, + 232.604832535, + 253.794575043, + 276.914652285, + 302.140913126, + 329.665225843, + 359.696937452, + 392.464465978, + 428.217037783, + 467.226583154, + 509.78980457, + 556.230433401, + 606.901692163, + 662.1889811, + 722.512809492, + 788.331994007, + 860.147148411, + 938.504491184, + 1024.0}; +const uint8_t grpc_stats_table_3[52] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52}; +const double grpc_stats_table_4[128] = {0, + 1, + 2, + 3, + 4, + 5, + 6.04764436132, + 7.3148004642, + 8.8474623563, + 10.7012611662, + 12.9434843502, + 15.6555180292, + 18.9358010666, + 22.9033981095, + 27.7023212864, + 33.5067574247, + 40.5273905211, + 49.0190489527, + 59.2899549993, + 71.7129124069, + 86.7388380702, + 104.913128993, + 126.895458596, + 153.483720931, + 185.642991889, + 224.540558623, + 271.588288649, + 328.493876489, + 397.322827976, + 480.573432046, + 581.267441303, + 703.059752763, + 850.371069894, + 1028.54836117, + 1244.05893936, + 1504.72520595, + 1820.00858143, + 2201.352927, + 2662.59992325, + 3220.49148246, + 3895.27743092, + 4711.45051817, + 5698.63543198, + 6892.66408748, + 8336.87622063, + 10083.6924933, + 12196.5172097, + 14752.0397062, + 17843.0179495, + 21581.6453782, + 26103.6231959, + 31573.0859261, + 38188.5590141, + 46190.1647178, + 55868.3378408, + 67574.3676638, + 81733.1487144, + 98858.6031911, + 119572.334831, + 144626.191302, + 174929.554066, + 211582.346255, + 255914.956657, + 309536.528921, + 374393.36875, + 452839.589087, + 547722.557505, + 662486.247293, + 801296.243578, + 969190.941845, + 1172264.4269, + 1417887.67026, + 1714976.07481, + 2074313.07772, + 2508941.55762, + 3034637.25277, + 3670481.37407, + 4439553.19704, + 5369767.77177, + 6494889.15731, + 7855755.95793, + 9501763.64457, + 11492657.4655, + 13900701.0236, + 16813299.2328, + 20336170.86, + 24597185.8065, + 29751006.4094, + 35984701.2311, + 43524535.0988, + 52644181.8539, + 63674657.909, + 77016337.1725, + 93153483.4461, + 112671827.78, + 136279828.791, + 164834387.63, + 199371950.98, + 241146131.03, + 291673207.915, + 352787166.24, + 426706263.331, + 516113545.475, + 624254234.618, + 755053520.404, + 913259033.033, + 1104613168.31, + 1336061519.75, + 1616004983.26, + 1954604684.98, + 2364150800.34, + 2859508651.4, + 3458658274.36, + 4183347042.13, + 5059879030.16, + 6120069777.14, + 7402401095.72, + 8953417849.36, + 10829417394.2, + 13098493008.1, + 15843005476.5, + 19162572547.2, + 23177684762.8, + 28034078912.8, + 33908027852.3, + 41012738688.9, + 49606091574.9, + 60000000000.0}; +const uint16_t grpc_stats_table_5[265] = { + 0, 2, 2, 4, 4, 6, 6, 8, 8, 11, 11, 11, 13, 13, 15, + 15, 17, 17, 20, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, + 30, 33, 33, 33, 35, 35, 37, 37, 39, 39, 42, 42, 42, 44, 44, + 46, 46, 48, 48, 51, 51, 51, 53, 53, 54, 57, 57, 57, 60, 60, + 60, 61, 63, 63, 66, 66, 66, 68, 68, 70, 70, 72, 72, 75, 75, + 75, 77, 77, 79, 79, 81, 81, 84, 84, 84, 85, 87, 87, 90, 90, + 90, 92, 92, 94, 94, 96, 96, 99, 99, 99, 101, 101, 103, 103, 105, + 105, 108, 108, 108, 109, 112, 112, 112, 114, 114, 116, 116, 118, 118, 120, + 120, 123, 123, 123, 125, 125, 127, 127, 129, 129, 132, 132, 132, 134, 134, + 136, 136, 138, 138, 140, 140, 142, 142, 145, 145, 145, 147, 147, 149, 149, + 151, 151, 154, 154, 154, 156, 156, 158, 158, 160, 160, 162, 162, 165, 165, + 165, 166, 169, 169, 169, 172, 172, 172, 173, 175, 175, 178, 178, 178, 180, + 180, 182, 182, 184, 184, 187, 187, 187, 189, 189, 191, 191, 193, 193, 196, + 196, 196, 197, 199, 199, 202, 202, 202, 204, 204, 206, 206, 208, 208, 211, + 211, 211, 213, 213, 215, 215, 217, 217, 220, 220, 220, 221, 224, 224, 224, + 226, 226, 228, 228, 230, 230, 232, 232, 235, 235, 235, 237, 237, 239, 239, + 241, 241, 244, 244, 244, 246, 246, 248, 248, 250, 250, 252, 252, 254, 254, + 257, 257, 257, 259, 259, 261, 261, 263, 263, 265}; +const int grpc_stats_histo_buckets[4] = {64, 64, 64, 128}; +const int grpc_stats_histo_start[4] = {0, 64, 128, 192}; +const double *const grpc_stats_histo_bucket_boundaries[4] = { + grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0, + grpc_stats_table_4}; diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 3c1d358c5f..2cf13190ad 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -1,12 +1,12 @@ /* * Copyright 2017 gRPC authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,6 +21,8 @@ #ifndef GRPC_CORE_LIB_DEBUG_STATS_DATA_H #define GRPC_CORE_LIB_DEBUG_STATS_DATA_H +#include + typedef enum { GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED, GRPC_STATS_COUNTER_SERVER_CALLS_CREATED, @@ -28,23 +30,144 @@ typedef enum { GRPC_STATS_COUNTER_SYSCALL_READ, GRPC_STATS_COUNTER_SYSCALL_POLL, GRPC_STATS_COUNTER_SYSCALL_WAIT, + GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS, GRPC_STATS_COUNTER_COUNT } grpc_stats_counters; +extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]; typedef enum { GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, + GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, GRPC_STATS_HISTOGRAM_CLIENT_LATENCY, GRPC_STATS_HISTOGRAM_COUNT } grpc_stats_histograms; -#define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) -#define GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) -#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) -#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) -#define GRPC_STATS_INC_SYSCALL_POLL(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_POLL) -#define GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx) GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) -#define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE,None) -#define GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, value) GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE,None) -#define GRPC_STATS_INC_CLIENT_LATENCY(exec_ctx, value) GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CLIENT_LATENCY,None) -extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]; +extern const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT]; +typedef enum { + GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE_FIRST_SLOT = 0, + GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE_BUCKETS = 64, + GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE_FIRST_SLOT = 64, + GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE_BUCKETS = 64, + GRPC_STATS_HISTOGRAM_TCP_READ_SIZE_FIRST_SLOT = 128, + GRPC_STATS_HISTOGRAM_TCP_READ_SIZE_BUCKETS = 64, + GRPC_STATS_HISTOGRAM_CLIENT_LATENCY_FIRST_SLOT = 192, + GRPC_STATS_HISTOGRAM_CLIENT_LATENCY_BUCKETS = 128, + GRPC_STATS_HISTOGRAM_BUCKETS = 320 +} grpc_stats_histogram_constants; +#define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) +#define GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) +#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) +#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) +#define GRPC_STATS_INC_SYSCALL_POLL(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_POLL) +#define GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) +#define GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS) +#define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \ + do { \ + double _hist_val = (double)(value); \ + if (_hist_val < 0) _hist_val = 0; \ + uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ + gpr_log(GPR_DEBUG, "tcp_write_size %lf %" PRId64 " %" PRId64, _hist_val, \ + _hist_idx, 4715268809856909312ull); \ + if (_hist_val < 5.000000) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, (int)_hist_val); \ + } else { \ + if (_hist_idx < 4715268809856909312ull) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, \ + grpc_stats_table_1[((_hist_idx - 4617315517961601024ull) >> 50)]); \ + } else { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, \ + grpc_stats_histo_find_bucket_slow((exec_ctx), (value), \ + grpc_stats_table_0, 64)); \ + } \ + } \ + } while (false) +#define GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, value) \ + do { \ + double _hist_val = (double)(value); \ + if (_hist_val < 0) _hist_val = 0; \ + uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ + gpr_log(GPR_DEBUG, "tcp_write_iov_size %lf %" PRId64 " %" PRId64, \ + _hist_val, _hist_idx, 4652218415073722368ull); \ + if (_hist_val < 12.000000) { \ + GRPC_STATS_INC_HISTOGRAM((exec_ctx), \ + GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ + (int)_hist_val); \ + } else { \ + if (_hist_idx < 4652218415073722368ull) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ + grpc_stats_table_3[((_hist_idx - 4622945017495814144ull) >> 49)]); \ + } else { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ + grpc_stats_histo_find_bucket_slow((exec_ctx), (value), \ + grpc_stats_table_2, 64)); \ + } \ + } \ + } while (false) +#define GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, value) \ + do { \ + double _hist_val = (double)(value); \ + if (_hist_val < 0) _hist_val = 0; \ + uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ + gpr_log(GPR_DEBUG, "tcp_read_size %lf %" PRId64 " %" PRId64, _hist_val, \ + _hist_idx, 4715268809856909312ull); \ + if (_hist_val < 5.000000) { \ + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, \ + (int)_hist_val); \ + } else { \ + if (_hist_idx < 4715268809856909312ull) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, \ + grpc_stats_table_1[((_hist_idx - 4617315517961601024ull) >> 50)]); \ + } else { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, \ + grpc_stats_histo_find_bucket_slow((exec_ctx), (value), \ + grpc_stats_table_0, 64)); \ + } \ + } \ + } while (false) +#define GRPC_STATS_INC_CLIENT_LATENCY(exec_ctx, value) \ + do { \ + double _hist_val = (double)(value); \ + if (_hist_val < 0) _hist_val = 0; \ + uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ + gpr_log(GPR_DEBUG, "client_latency %lf %" PRId64 " %" PRId64, _hist_val, \ + _hist_idx, 4767623155525091328ull); \ + if (_hist_val < 6.000000) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_CLIENT_LATENCY, (int)_hist_val); \ + } else { \ + if (_hist_idx < 4767623155525091328ull) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_CLIENT_LATENCY, \ + grpc_stats_table_5[((_hist_idx - 4618441417868443648ull) >> 49)]); \ + } else { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_CLIENT_LATENCY, \ + grpc_stats_histo_find_bucket_slow((exec_ctx), (value), \ + grpc_stats_table_4, 128)); \ + } \ + } \ + } while (false) +extern const double grpc_stats_table_0[64]; +extern const uint8_t grpc_stats_table_1[87]; +extern const double grpc_stats_table_2[64]; +extern const uint8_t grpc_stats_table_3[52]; +extern const double grpc_stats_table_4[128]; +extern const uint16_t grpc_stats_table_5[265]; +extern const int grpc_stats_histo_buckets[4]; +extern const int grpc_stats_histo_start[4]; +extern const double *const grpc_stats_histo_bucket_boundaries[4]; #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index 6aecbdee75..c5f62eddb4 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -7,9 +7,13 @@ - counter: syscall_read - counter: syscall_poll - counter: syscall_wait +- counter: histogram_slow_lookups - histogram: tcp_write_size max: 16777216 # 16 meg max write tracked buckets: 64 +- histogram: tcp_write_iov_size + max: 1024 + buckets: 64 - histogram: tcp_read_size max: 16777216 buckets: 64 diff --git a/src/core/lib/iomgr/tcp_posix.c b/src/core/lib/iomgr/tcp_posix.c index 7e789cc5b5..ccf328ec1c 100644 --- a/src/core/lib/iomgr/tcp_posix.c +++ b/src/core/lib/iomgr/tcp_posix.c @@ -287,6 +287,7 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { GRPC_ERROR_CREATE_FROM_STATIC_STRING("Socket closed"), tcp)); TCP_UNREF(exec_ctx, tcp, "read"); } else { + GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, read_bytes); add_to_estimate(tcp, (size_t)read_bytes); GPR_ASSERT((size_t)read_bytes <= tcp->incoming_buffer->length); if ((size_t)read_bytes < tcp->incoming_buffer->length) { @@ -403,6 +404,9 @@ static bool tcp_flush(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, msg.msg_controllen = 0; msg.msg_flags = 0; + GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, sending_length); + GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, iov_size); + GPR_TIMER_BEGIN("sendmsg", 1); do { /* TODO(klempner): Cork if this is a partial write */ diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index c56e1f2608..30e0072eec 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -47,17 +47,60 @@ for attr in attrs: def dbl2u64(d): return ctypes.c_ulonglong.from_buffer(ctypes.c_double(d)).value -def shift_works(mapped_bounds, shift_bits): - for a, b in zip(mapped_bounds, mapped_bounds[1:]): +def shift_works_until(mapped_bounds, shift_bits): + for i, ab in enumerate(zip(mapped_bounds, mapped_bounds[1:])): + a, b = ab if (a >> shift_bits) == (b >> shift_bits): - return False - return True + return i + return len(mapped_bounds) -def find_max_shift(mapped_bounds): +def find_ideal_shift(mapped_bounds, max_size): + best = None for shift_bits in reversed(range(0,64)): - if shift_works(mapped_bounds, shift_bits): - return shift_bits - return -1 + n = shift_works_until(mapped_bounds, shift_bits) + if n == 0: continue + table_size = mapped_bounds[n-1] >> shift_bits + if table_size > max_size: continue + if table_size > 65535: continue + if best is None: + best = (shift_bits, n, table_size) + elif best[1] < n: + best = (shift_bits, n, table_size) + print best + return best + +def gen_map_table(mapped_bounds, shift_data): + tbl = [] + cur = 0 + mapped_bounds = [x >> shift_data[0] for x in mapped_bounds] + for i in range(0, mapped_bounds[shift_data[1]-1]): + while i > mapped_bounds[cur]: + cur += 1 + tbl.append(mapped_bounds[cur]) + return tbl + +static_tables = [] + +def decl_static_table(values, type): + global static_tables + v = (type, values) + for i, vp in enumerate(static_tables): + if v == vp: return i + print "ADD TABLE: %s %r" % (type, values) + r = len(static_tables) + static_tables.append(v) + return r + +def type_for_uint_table(table): + mv = max(table) + if mv < 2**8: + return 'uint8_t' + elif mv < 2**16: + return 'uint16_t' + elif mv < 2**32: + return 'uint32_t' + else: + return 'uint64_t' def gen_bucket_code(histogram): bounds = [0, 1] @@ -75,10 +118,41 @@ def gen_bucket_code(histogram): done_trivial = True first_nontrivial = len(bounds) bounds.append(nextb) + bounds_idx = decl_static_table(bounds, 'double') if done_trivial: - code_bounds = [dbl2u64(x - first_nontrivial) for x in bounds] - shift_bits = find_max_shift(code_bounds[first_nontrivial:]) - print first_nontrivial, shift_bits, bounds, [hex(x >> shift_bits) for x in code_bounds[first_nontrivial:]] + first_nontrivial_code = dbl2u64(first_nontrivial) + code_bounds = [dbl2u64(x) - first_nontrivial_code for x in bounds] + shift_data = find_ideal_shift(code_bounds[first_nontrivial:], 256 * histogram.buckets) + print first_nontrivial, shift_data, bounds + if shift_data is not None: print [hex(x >> shift_data[0]) for x in code_bounds[first_nontrivial:]] + code = 'do {\\\n' + code += 'double _hist_val = (double)(value);\\\n' + code += 'if (_hist_val < 0) _hist_val = 0;\\\n' + code += 'uint64_t _hist_idx = *(uint64_t*)&_hist_val;\\\n' + map_table = gen_map_table(code_bounds[first_nontrivial:], shift_data) + code += 'gpr_log(GPR_DEBUG, "' + histogram.name + ' %lf %"PRId64 " %"PRId64, _hist_val, _hist_idx, ' + str((map_table[-1] << shift_data[0]) + first_nontrivial_code) + 'ull);\\\n' + if first_nontrivial is None: + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_hist_val);\\\n' + % histogram.name.upper()) + else: + code += 'if (_hist_val < %f) {\\\n' % first_nontrivial + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_hist_val);\\\n' + % histogram.name.upper()) + code += '} else {' + first_nontrivial_code = dbl2u64(first_nontrivial) + if shift_data is not None: + map_table_idx = decl_static_table(map_table, type_for_uint_table(map_table)) + code += 'if (_hist_idx < %dull) {\\\n' % ((map_table[-1] << shift_data[0]) + first_nontrivial_code) + code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, ' % histogram.name.upper() + code += 'grpc_stats_table_%d[((_hist_idx - %dull) >> %d)]);\\\n' % (map_table_idx, first_nontrivial_code, shift_data[0]) + code += '} else {\\\n' + code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() + code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), (value), grpc_stats_table_%d, %d));\\\n' % (bounds_idx, len(bounds)) + if shift_data is not None: + code += '}' + code += '}' + code += '} while (false)' + return (code, bounds_idx) # utility: print a big comment block into a set of files def put_banner(files, banner): @@ -110,6 +184,8 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "#ifndef GRPC_CORE_LIB_DEBUG_STATS_DATA_H" print >>H, "#define GRPC_CORE_LIB_DEBUG_STATS_DATA_H" print >>H + print >>H, "#include " + print >>H for typename, instances in sorted(inst_map.items()): print >>H, "typedef enum {" @@ -117,21 +193,41 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, " GRPC_STATS_%s_%s," % (typename.upper(), inst.name.upper()) print >>H, " GRPC_STATS_%s_COUNT" % (typename.upper()) print >>H, "} grpc_stats_%ss;" % (typename.lower()) + print >>H, "extern const char *grpc_stats_%s_name[GRPC_STATS_%s_COUNT];" % ( + typename.lower(), typename.upper()) + + histo_start = [] + histo_buckets = [] + histo_bucket_boundaries = [] + + print >>H, "typedef enum {" + first_slot = 0 + for histogram in inst_map['Histogram']: + histo_start.append(first_slot) + histo_buckets.append(histogram.buckets) + print >>H, " GRPC_STATS_HISTOGRAM_%s_FIRST_SLOT = %d," % (histogram.name.upper(), first_slot) + print >>H, " GRPC_STATS_HISTOGRAM_%s_BUCKETS = %d," % (histogram.name.upper(), histogram.buckets) + first_slot += histogram.buckets + print >>H, " GRPC_STATS_HISTOGRAM_BUCKETS = %d" % first_slot + print >>H, "} grpc_stats_histogram_constants;" for ctr in inst_map['Counter']: print >>H, ("#define GRPC_STATS_INC_%s(exec_ctx) " + "GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_%s)") % ( ctr.name.upper(), ctr.name.upper()) for histogram in inst_map['Histogram']: - print >>H, ("#define GRPC_STATS_INC_%s(exec_ctx, value) " + - "GRPC_STATS_INC_HISTOGRAM((exec_ctx), " + - "GRPC_STATS_HISTOGRAM_%s," + - "%s)") % ( - histogram.name.upper(), + code, bounds_idx = gen_bucket_code(histogram) + histo_bucket_boundaries.append(bounds_idx) + print >>H, ("#define GRPC_STATS_INC_%s(exec_ctx, value) %s") % ( histogram.name.upper(), - gen_bucket_code(histogram)) + code) - print >>H, "extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT];" + for i, tbl in enumerate(static_tables): + print >>H, "extern const %s grpc_stats_table_%d[%d];" % (tbl[0], i, len(tbl[1])) + + print >>H, "extern const int grpc_stats_histo_buckets[%d];" % len(inst_map['Histogram']) + print >>H, "extern const int grpc_stats_histo_start[%d];" % len(inst_map['Histogram']) + print >>H, "extern const double *const grpc_stats_histo_bucket_boundaries[%d];" % len(inst_map['Histogram']) print >>H print >>H, "#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */" @@ -156,7 +252,19 @@ with open('src/core/lib/debug/stats_data.c', 'w') as C: print >>C, "#include \"src/core/lib/debug/stats_data.h\"" - print >>C, "const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = {"; - for ctr in inst_map['Counter']: - print >>C, " \"%s\"," % ctr.name - print >>C, "};" + for typename, instances in sorted(inst_map.items()): + print >>C, "const char *grpc_stats_%s_name[GRPC_STATS_%s_COUNT] = {" % ( + typename.lower(), typename.upper()) + for inst in instances: + print >>C, " \"%s\"," % inst.name + print >>C, "};" + for i, tbl in enumerate(static_tables): + print >>C, "const %s grpc_stats_table_%d[%d] = {%s};" % ( + tbl[0], i, len(tbl[1]), ','.join('%s' % x for x in tbl[1])) + + print >>C, "const int grpc_stats_histo_buckets[%d] = {%s};" % ( + len(inst_map['Histogram']), ','.join('%s' % x for x in histo_buckets)) + print >>C, "const int grpc_stats_histo_start[%d] = {%s};" % ( + len(inst_map['Histogram']), ','.join('%s' % x for x in histo_start)) + print >>C, "const double *const grpc_stats_histo_bucket_boundaries[%d] = {%s};" % ( + len(inst_map['Histogram']), ','.join('grpc_stats_table_%d' % x for x in histo_bucket_boundaries)) -- cgit v1.2.3 From d1107834476e60545579913d33f5235b78241359 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 30 Aug 2017 13:37:13 -0700 Subject: Remove dummy --- src/core/lib/debug/stats_data.c | 158 ++----------------------------------- src/core/lib/debug/stats_data.h | 36 +-------- src/core/lib/debug/stats_data.yaml | 3 - 3 files changed, 9 insertions(+), 188 deletions(-) diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index b137f1fe65..177234ab5b 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -25,7 +25,7 @@ const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { "histogram_slow_lookups", }; const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = { - "tcp_write_size", "tcp_write_iov_size", "tcp_read_size", "client_latency", + "tcp_write_size", "tcp_write_iov_size", "tcp_read_size", }; const double grpc_stats_table_0[64] = {0, 1, @@ -165,155 +165,7 @@ const uint8_t grpc_stats_table_3[52] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52}; -const double grpc_stats_table_4[128] = {0, - 1, - 2, - 3, - 4, - 5, - 6.04764436132, - 7.3148004642, - 8.8474623563, - 10.7012611662, - 12.9434843502, - 15.6555180292, - 18.9358010666, - 22.9033981095, - 27.7023212864, - 33.5067574247, - 40.5273905211, - 49.0190489527, - 59.2899549993, - 71.7129124069, - 86.7388380702, - 104.913128993, - 126.895458596, - 153.483720931, - 185.642991889, - 224.540558623, - 271.588288649, - 328.493876489, - 397.322827976, - 480.573432046, - 581.267441303, - 703.059752763, - 850.371069894, - 1028.54836117, - 1244.05893936, - 1504.72520595, - 1820.00858143, - 2201.352927, - 2662.59992325, - 3220.49148246, - 3895.27743092, - 4711.45051817, - 5698.63543198, - 6892.66408748, - 8336.87622063, - 10083.6924933, - 12196.5172097, - 14752.0397062, - 17843.0179495, - 21581.6453782, - 26103.6231959, - 31573.0859261, - 38188.5590141, - 46190.1647178, - 55868.3378408, - 67574.3676638, - 81733.1487144, - 98858.6031911, - 119572.334831, - 144626.191302, - 174929.554066, - 211582.346255, - 255914.956657, - 309536.528921, - 374393.36875, - 452839.589087, - 547722.557505, - 662486.247293, - 801296.243578, - 969190.941845, - 1172264.4269, - 1417887.67026, - 1714976.07481, - 2074313.07772, - 2508941.55762, - 3034637.25277, - 3670481.37407, - 4439553.19704, - 5369767.77177, - 6494889.15731, - 7855755.95793, - 9501763.64457, - 11492657.4655, - 13900701.0236, - 16813299.2328, - 20336170.86, - 24597185.8065, - 29751006.4094, - 35984701.2311, - 43524535.0988, - 52644181.8539, - 63674657.909, - 77016337.1725, - 93153483.4461, - 112671827.78, - 136279828.791, - 164834387.63, - 199371950.98, - 241146131.03, - 291673207.915, - 352787166.24, - 426706263.331, - 516113545.475, - 624254234.618, - 755053520.404, - 913259033.033, - 1104613168.31, - 1336061519.75, - 1616004983.26, - 1954604684.98, - 2364150800.34, - 2859508651.4, - 3458658274.36, - 4183347042.13, - 5059879030.16, - 6120069777.14, - 7402401095.72, - 8953417849.36, - 10829417394.2, - 13098493008.1, - 15843005476.5, - 19162572547.2, - 23177684762.8, - 28034078912.8, - 33908027852.3, - 41012738688.9, - 49606091574.9, - 60000000000.0}; -const uint16_t grpc_stats_table_5[265] = { - 0, 2, 2, 4, 4, 6, 6, 8, 8, 11, 11, 11, 13, 13, 15, - 15, 17, 17, 20, 20, 20, 22, 22, 24, 24, 26, 26, 28, 28, 30, - 30, 33, 33, 33, 35, 35, 37, 37, 39, 39, 42, 42, 42, 44, 44, - 46, 46, 48, 48, 51, 51, 51, 53, 53, 54, 57, 57, 57, 60, 60, - 60, 61, 63, 63, 66, 66, 66, 68, 68, 70, 70, 72, 72, 75, 75, - 75, 77, 77, 79, 79, 81, 81, 84, 84, 84, 85, 87, 87, 90, 90, - 90, 92, 92, 94, 94, 96, 96, 99, 99, 99, 101, 101, 103, 103, 105, - 105, 108, 108, 108, 109, 112, 112, 112, 114, 114, 116, 116, 118, 118, 120, - 120, 123, 123, 123, 125, 125, 127, 127, 129, 129, 132, 132, 132, 134, 134, - 136, 136, 138, 138, 140, 140, 142, 142, 145, 145, 145, 147, 147, 149, 149, - 151, 151, 154, 154, 154, 156, 156, 158, 158, 160, 160, 162, 162, 165, 165, - 165, 166, 169, 169, 169, 172, 172, 172, 173, 175, 175, 178, 178, 178, 180, - 180, 182, 182, 184, 184, 187, 187, 187, 189, 189, 191, 191, 193, 193, 196, - 196, 196, 197, 199, 199, 202, 202, 202, 204, 204, 206, 206, 208, 208, 211, - 211, 211, 213, 213, 215, 215, 217, 217, 220, 220, 220, 221, 224, 224, 224, - 226, 226, 228, 228, 230, 230, 232, 232, 235, 235, 235, 237, 237, 239, 239, - 241, 241, 244, 244, 244, 246, 246, 248, 248, 250, 250, 252, 252, 254, 254, - 257, 257, 257, 259, 259, 261, 261, 263, 263, 265}; -const int grpc_stats_histo_buckets[4] = {64, 64, 64, 128}; -const int grpc_stats_histo_start[4] = {0, 64, 128, 192}; -const double *const grpc_stats_histo_bucket_boundaries[4] = { - grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0, - grpc_stats_table_4}; +const int grpc_stats_histo_buckets[3] = {64, 64, 64}; +const int grpc_stats_histo_start[3] = {0, 64, 128}; +const double *const grpc_stats_histo_bucket_boundaries[3] = { + grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0}; diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 2cf13190ad..51e1c5a533 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -38,7 +38,6 @@ typedef enum { GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, - GRPC_STATS_HISTOGRAM_CLIENT_LATENCY, GRPC_STATS_HISTOGRAM_COUNT } grpc_stats_histograms; extern const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT]; @@ -49,9 +48,7 @@ typedef enum { GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE_BUCKETS = 64, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE_FIRST_SLOT = 128, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE_BUCKETS = 64, - GRPC_STATS_HISTOGRAM_CLIENT_LATENCY_FIRST_SLOT = 192, - GRPC_STATS_HISTOGRAM_CLIENT_LATENCY_BUCKETS = 128, - GRPC_STATS_HISTOGRAM_BUCKETS = 320 + GRPC_STATS_HISTOGRAM_BUCKETS = 192 } grpc_stats_histogram_constants; #define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) @@ -137,37 +134,12 @@ typedef enum { } \ } \ } while (false) -#define GRPC_STATS_INC_CLIENT_LATENCY(exec_ctx, value) \ - do { \ - double _hist_val = (double)(value); \ - if (_hist_val < 0) _hist_val = 0; \ - uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ - gpr_log(GPR_DEBUG, "client_latency %lf %" PRId64 " %" PRId64, _hist_val, \ - _hist_idx, 4767623155525091328ull); \ - if (_hist_val < 6.000000) { \ - GRPC_STATS_INC_HISTOGRAM( \ - (exec_ctx), GRPC_STATS_HISTOGRAM_CLIENT_LATENCY, (int)_hist_val); \ - } else { \ - if (_hist_idx < 4767623155525091328ull) { \ - GRPC_STATS_INC_HISTOGRAM( \ - (exec_ctx), GRPC_STATS_HISTOGRAM_CLIENT_LATENCY, \ - grpc_stats_table_5[((_hist_idx - 4618441417868443648ull) >> 49)]); \ - } else { \ - GRPC_STATS_INC_HISTOGRAM( \ - (exec_ctx), GRPC_STATS_HISTOGRAM_CLIENT_LATENCY, \ - grpc_stats_histo_find_bucket_slow((exec_ctx), (value), \ - grpc_stats_table_4, 128)); \ - } \ - } \ - } while (false) extern const double grpc_stats_table_0[64]; extern const uint8_t grpc_stats_table_1[87]; extern const double grpc_stats_table_2[64]; extern const uint8_t grpc_stats_table_3[52]; -extern const double grpc_stats_table_4[128]; -extern const uint16_t grpc_stats_table_5[265]; -extern const int grpc_stats_histo_buckets[4]; -extern const int grpc_stats_histo_start[4]; -extern const double *const grpc_stats_histo_bucket_boundaries[4]; +extern const int grpc_stats_histo_buckets[3]; +extern const int grpc_stats_histo_start[3]; +extern const double *const grpc_stats_histo_bucket_boundaries[3]; #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index c5f62eddb4..714837f5f0 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -17,6 +17,3 @@ - histogram: tcp_read_size max: 16777216 buckets: 64 -- histogram: client_latency - max: 60e9 - buckets: 128 -- cgit v1.2.3 From 520d76d698f7f03038fd7fcfe1a2129acd0fa948 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 31 Aug 2017 11:26:30 -0700 Subject: Compile fix --- src/core/lib/debug/stats_data.h | 6 ------ src/core/lib/debug/stats_data.yaml | 27 +++++++++------------------ tools/codegen/core/gen_stats_data.py | 1 - 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 51e1c5a533..5d616c73c7 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -69,8 +69,6 @@ typedef enum { double _hist_val = (double)(value); \ if (_hist_val < 0) _hist_val = 0; \ uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ - gpr_log(GPR_DEBUG, "tcp_write_size %lf %" PRId64 " %" PRId64, _hist_val, \ - _hist_idx, 4715268809856909312ull); \ if (_hist_val < 5.000000) { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, (int)_hist_val); \ @@ -92,8 +90,6 @@ typedef enum { double _hist_val = (double)(value); \ if (_hist_val < 0) _hist_val = 0; \ uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ - gpr_log(GPR_DEBUG, "tcp_write_iov_size %lf %" PRId64 " %" PRId64, \ - _hist_val, _hist_idx, 4652218415073722368ull); \ if (_hist_val < 12.000000) { \ GRPC_STATS_INC_HISTOGRAM((exec_ctx), \ GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ @@ -116,8 +112,6 @@ typedef enum { double _hist_val = (double)(value); \ if (_hist_val < 0) _hist_val = 0; \ uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ - gpr_log(GPR_DEBUG, "tcp_read_size %lf %" PRId64 " %" PRId64, _hist_val, \ - _hist_idx, 4715268809856909312ull); \ if (_hist_val < 5.000000) { \ GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, \ (int)_hist_val); \ diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index 714837f5f0..ded3e89cb2 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -1,19 +1,10 @@ -# Stats data declaration -# use tools/codegen/core/gen_stats_data.py to turn this into stats_data.h +#Stats data declaration +#use tools / codegen / core / gen_stats_data.py to turn this into stats_data.h -- counter: client_calls_created -- counter: server_calls_created -- counter: syscall_write -- counter: syscall_read -- counter: syscall_poll -- counter: syscall_wait -- counter: histogram_slow_lookups -- histogram: tcp_write_size - max: 16777216 # 16 meg max write tracked - buckets: 64 -- histogram: tcp_write_iov_size - max: 1024 - buckets: 64 -- histogram: tcp_read_size - max: 16777216 - buckets: 64 +- counter:client_calls_created - + counter:server_calls_created - counter:syscall_write - + counter:syscall_read - counter:syscall_poll - counter:syscall_wait - + counter:histogram_slow_lookups - + histogram:tcp_write_size max:16777216 #16 meg max write tracked buckets:64 - + histogram:tcp_write_iov_size max:1024 buckets:64 - + histogram:tcp_read_size max:16777216 buckets:64 diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 30e0072eec..e599378690 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -130,7 +130,6 @@ def gen_bucket_code(histogram): code += 'if (_hist_val < 0) _hist_val = 0;\\\n' code += 'uint64_t _hist_idx = *(uint64_t*)&_hist_val;\\\n' map_table = gen_map_table(code_bounds[first_nontrivial:], shift_data) - code += 'gpr_log(GPR_DEBUG, "' + histogram.name + ' %lf %"PRId64 " %"PRId64, _hist_val, _hist_idx, ' + str((map_table[-1] << shift_data[0]) + first_nontrivial_code) + 'ull);\\\n' if first_nontrivial is None: code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_hist_val);\\\n' % histogram.name.upper()) -- cgit v1.2.3 From 5489d41c15926abbf12a5b8d27b24d1d605d7f0f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 31 Aug 2017 12:20:04 -0700 Subject: Expose histograms via microbenchmarks --- src/core/lib/debug/stats.c | 67 ++++++++++++++++++++++++++++++++++++ src/core/lib/debug/stats.h | 8 +++++ src/core/lib/debug/stats_data.h | 60 ++++++++++++++++++-------------- src/core/lib/debug/stats_data.yaml | 23 +++++++++---- test/cpp/microbenchmarks/helpers.cc | 13 +++++-- tools/codegen/core/gen_stats_data.py | 18 +++++----- 6 files changed, 144 insertions(+), 45 deletions(-) diff --git a/src/core/lib/debug/stats.c b/src/core/lib/debug/stats.c index cb9c78c4f2..5079ed2ffa 100644 --- a/src/core/lib/debug/stats.c +++ b/src/core/lib/debug/stats.c @@ -52,6 +52,16 @@ 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) { + for (size_t i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { + c->counters[i] = b->counters[i] - a->counters[i]; + } + for (size_t i = 0; i < GRPC_STATS_HISTOGRAM_BUCKETS; i++) { + c->histograms[i] = b->histograms[i] - a->histograms[i]; + } +} + int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx *exec_ctx, double value, const double *table, int table_size) { GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(exec_ctx); @@ -72,6 +82,63 @@ int grpc_stats_histo_find_bucket_slow(grpc_exec_ctx *exec_ctx, double value, return a; } +size_t grpc_stats_histo_count(const grpc_stats_data *stats, + grpc_stats_histograms histogram) { + size_t sum = 0; + for (int i = 0; i < grpc_stats_histo_buckets[histogram]; i++) { + sum += (size_t)stats->histograms[grpc_stats_histo_start[histogram] + i]; + } + return sum; +} + +static double threshold_for_count_below(const gpr_atm *bucket_counts, + const double *bucket_boundaries, + int num_buckets, double count_below) { + double count_so_far; + double lower_bound; + double upper_bound; + int lower_idx; + int upper_idx; + + /* find the lowest bucket that gets us above count_below */ + count_so_far = 0.0; + for (lower_idx = 0; lower_idx < num_buckets; lower_idx++) { + count_so_far += (double)bucket_counts[lower_idx]; + if (count_so_far >= count_below) { + break; + } + } + if (count_so_far == count_below) { + /* this bucket hits the threshold exactly... we should be midway through + any run of zero values following the bucket */ + for (upper_idx = lower_idx + 1; upper_idx < num_buckets; upper_idx++) { + if (bucket_counts[upper_idx]) { + break; + } + } + return (bucket_boundaries[lower_idx] + bucket_boundaries[upper_idx]) / 2.0; + } else { + /* treat values as uniform throughout the bucket, and find where this value + should lie */ + lower_bound = bucket_boundaries[lower_idx]; + upper_bound = bucket_boundaries[lower_idx + 1]; + return upper_bound - + (upper_bound - lower_bound) * (count_so_far - count_below) / + (double)bucket_counts[lower_idx]; + } +} + +double grpc_stats_histo_percentile(const grpc_stats_data *stats, + grpc_stats_histograms histogram, + double percentile) { + size_t count = grpc_stats_histo_count(stats, histogram); + if (count == 0) return 0.0; + return threshold_for_count_below( + stats->histograms + grpc_stats_histo_start[histogram], + grpc_stats_histo_bucket_boundaries[histogram], + grpc_stats_histo_buckets[histogram], (double)count * percentile / 100.0); +} + char *grpc_stats_data_as_json(const grpc_stats_data *data) { gpr_strvec v; char *tmp; diff --git a/src/core/lib/debug/stats.h b/src/core/lib/debug/stats.h index c4086063bc..c440ab3b66 100644 --- a/src/core/lib/debug/stats.h +++ b/src/core/lib/debug/stats.h @@ -46,8 +46,16 @@ extern grpc_stats_data *grpc_stats_per_cpu_storage; void grpc_stats_init(void); void grpc_stats_shutdown(void); void grpc_stats_collect(grpc_stats_data *output); +// c = b-a +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, const double *table, int table_size); +double grpc_stats_histo_percentile(const grpc_stats_data *data, + grpc_stats_histograms histogram, + double percentile); +size_t grpc_stats_histo_count(const grpc_stats_data *data, + grpc_stats_histograms histogram); #endif diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 5d616c73c7..9a4ba68655 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -66,64 +66,72 @@ typedef enum { GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS) #define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \ do { \ - double _hist_val = (double)(value); \ - if (_hist_val < 0) _hist_val = 0; \ - uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ - if (_hist_val < 5.000000) { \ + union { \ + double dbl; \ + uint64_t uint; \ + } _val; \ + _val.dbl = (double)(value); \ + if (_val.dbl < 0) _val.dbl = 0; \ + if (_val.dbl < 5.000000) { \ GRPC_STATS_INC_HISTOGRAM( \ - (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, (int)_hist_val); \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, (int)_val.dbl); \ } else { \ - if (_hist_idx < 4715268809856909312ull) { \ + if (_val.uint < 4715268809856909312ull) { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, \ - grpc_stats_table_1[((_hist_idx - 4617315517961601024ull) >> 50)]); \ + grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)]); \ } else { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, \ - grpc_stats_histo_find_bucket_slow((exec_ctx), (value), \ + grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, \ grpc_stats_table_0, 64)); \ } \ } \ } while (false) #define GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, value) \ do { \ - double _hist_val = (double)(value); \ - if (_hist_val < 0) _hist_val = 0; \ - uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ - if (_hist_val < 12.000000) { \ - GRPC_STATS_INC_HISTOGRAM((exec_ctx), \ - GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ - (int)_hist_val); \ + union { \ + double dbl; \ + uint64_t uint; \ + } _val; \ + _val.dbl = (double)(value); \ + if (_val.dbl < 0) _val.dbl = 0; \ + if (_val.dbl < 12.000000) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, (int)_val.dbl); \ } else { \ - if (_hist_idx < 4652218415073722368ull) { \ + if (_val.uint < 4652218415073722368ull) { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ - grpc_stats_table_3[((_hist_idx - 4622945017495814144ull) >> 49)]); \ + grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 49)]); \ } else { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ - grpc_stats_histo_find_bucket_slow((exec_ctx), (value), \ + grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, \ grpc_stats_table_2, 64)); \ } \ } \ } while (false) #define GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, value) \ do { \ - double _hist_val = (double)(value); \ - if (_hist_val < 0) _hist_val = 0; \ - uint64_t _hist_idx = *(uint64_t *)&_hist_val; \ - if (_hist_val < 5.000000) { \ + union { \ + double dbl; \ + uint64_t uint; \ + } _val; \ + _val.dbl = (double)(value); \ + if (_val.dbl < 0) _val.dbl = 0; \ + if (_val.dbl < 5.000000) { \ GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, \ - (int)_hist_val); \ + (int)_val.dbl); \ } else { \ - if (_hist_idx < 4715268809856909312ull) { \ + if (_val.uint < 4715268809856909312ull) { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, \ - grpc_stats_table_1[((_hist_idx - 4617315517961601024ull) >> 50)]); \ + grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)]); \ } else { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, \ - grpc_stats_histo_find_bucket_slow((exec_ctx), (value), \ + grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, \ grpc_stats_table_0, 64)); \ } \ } \ diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index ded3e89cb2..b8d5f71991 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -1,10 +1,19 @@ #Stats data declaration #use tools / codegen / core / gen_stats_data.py to turn this into stats_data.h -- counter:client_calls_created - - counter:server_calls_created - counter:syscall_write - - counter:syscall_read - counter:syscall_poll - counter:syscall_wait - - counter:histogram_slow_lookups - - histogram:tcp_write_size max:16777216 #16 meg max write tracked buckets:64 - - histogram:tcp_write_iov_size max:1024 buckets:64 - - histogram:tcp_read_size max:16777216 buckets:64 +- counter: client_calls_created +- counter: server_calls_created +- counter: syscall_write +- counter: syscall_read +- counter: syscall_poll +- counter: syscall_wait +- counter: histogram_slow_lookups +- histogram: tcp_write_size + max: 16777216 # 16 meg max write tracked + buckets: 64 +- histogram: tcp_write_iov_size + max: 1024 + buckets: 64 +- histogram: tcp_read_size + max: 16777216 + buckets: 64 diff --git a/test/cpp/microbenchmarks/helpers.cc b/test/cpp/microbenchmarks/helpers.cc index 415d27445f..b0caa48cd0 100644 --- a/test/cpp/microbenchmarks/helpers.cc +++ b/test/cpp/microbenchmarks/helpers.cc @@ -31,10 +31,17 @@ void TrackCounters::Finish(benchmark::State &state) { void TrackCounters::AddToLabel(std::ostream &out, benchmark::State &state) { grpc_stats_data stats_end; grpc_stats_collect(&stats_end); + grpc_stats_data stats; + grpc_stats_diff(&stats_end, &stats_begin_, &stats); for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { - out << " " << grpc_stats_counter_name[i] << "/iter:" - << ((double)(stats_end.counters[i] - stats_begin_.counters[i]) / - (double)state.iterations()); + out << " " << grpc_stats_counter_name[i] + << "/iter:" << ((double)stats.counters[i] / (double)state.iterations()); + } + for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { + out << " " << grpc_stats_histogram_name[i] << "-median:" + << grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 50.0) + << " " << grpc_stats_histogram_name[i] << "-99p:" + << grpc_stats_histo_percentile(&stats, (grpc_stats_histograms)i, 99.0); } #ifdef GPR_LOW_LEVEL_COUNTERS grpc_memory_counters counters_at_end = grpc_memory_counters_snapshot(); diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index e599378690..85489eb7dc 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -126,27 +126,27 @@ def gen_bucket_code(histogram): print first_nontrivial, shift_data, bounds if shift_data is not None: print [hex(x >> shift_data[0]) for x in code_bounds[first_nontrivial:]] code = 'do {\\\n' - code += 'double _hist_val = (double)(value);\\\n' - code += 'if (_hist_val < 0) _hist_val = 0;\\\n' - code += 'uint64_t _hist_idx = *(uint64_t*)&_hist_val;\\\n' + code += ' union { double dbl; uint64_t uint; } _val;\\\n' + code += '_val.dbl = (double)(value);\\\n' + code += 'if (_val.dbl < 0) _val.dbl = 0;\\\n' map_table = gen_map_table(code_bounds[first_nontrivial:], shift_data) if first_nontrivial is None: - code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_hist_val);\\\n' + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_val.dbl);\\\n' % histogram.name.upper()) else: - code += 'if (_hist_val < %f) {\\\n' % first_nontrivial - code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_hist_val);\\\n' + code += 'if (_val.dbl < %f) {\\\n' % first_nontrivial + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_val.dbl);\\\n' % histogram.name.upper()) code += '} else {' first_nontrivial_code = dbl2u64(first_nontrivial) if shift_data is not None: map_table_idx = decl_static_table(map_table, type_for_uint_table(map_table)) - code += 'if (_hist_idx < %dull) {\\\n' % ((map_table[-1] << shift_data[0]) + first_nontrivial_code) + code += 'if (_val.uint < %dull) {\\\n' % ((map_table[-1] << shift_data[0]) + first_nontrivial_code) code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, ' % histogram.name.upper() - code += 'grpc_stats_table_%d[((_hist_idx - %dull) >> %d)]);\\\n' % (map_table_idx, first_nontrivial_code, shift_data[0]) + code += 'grpc_stats_table_%d[((_val.uint - %dull) >> %d)]);\\\n' % (map_table_idx, first_nontrivial_code, shift_data[0]) code += '} else {\\\n' code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() - code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), (value), grpc_stats_table_%d, %d));\\\n' % (bounds_idx, len(bounds)) + code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, grpc_stats_table_%d, %d));\\\n' % (bounds_idx, len(bounds)) if shift_data is not None: code += '}' code += '}' -- cgit v1.2.3 From 289723560948e8ec422e659febc73a766845f9ed Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 31 Aug 2017 15:52:57 -0700 Subject: Expose stats into qps_driver --- CMakeLists.txt | 66 ++++++++++++ Makefile | 117 ++++++++++++++++----- build.yaml | 14 +++ grpc.gyp | 12 +++ src/cpp/util/core_stats.cc | 90 ++++++++++++++++ src/cpp/util/core_stats.h | 35 ++++++ src/proto/grpc/core/stats.proto | 38 +++++++ src/proto/grpc/testing/stats.proto | 8 ++ test/cpp/qps/client.h | 5 + test/cpp/qps/report.cc | 28 +++++ test/cpp/qps/report.h | 3 + test/cpp/qps/server.h | 5 + tools/run_tests/generated/sources_and_headers.json | 28 ++++- 13 files changed, 423 insertions(+), 26 deletions(-) create mode 100644 src/cpp/util/core_stats.cc create mode 100644 src/cpp/util/core_stats.h create mode 100644 src/proto/grpc/core/stats.proto diff --git a/CMakeLists.txt b/CMakeLists.txt index efc33c0a6c..ecfc8c8c30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2770,6 +2770,68 @@ if (gRPC_INSTALL) ) endif() +if (gRPC_BUILD_TESTS) + +add_library(grpc++_core_stats + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/core/stats.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/core/stats.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/core/stats.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/core/stats.grpc.pb.h + src/cpp/util/core_stats.cc +) + +if(WIN32 AND MSVC) + set_target_properties(grpc++_core_stats PROPERTIES COMPILE_PDB_NAME "grpc++_core_stats" + COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" + ) + if (gRPC_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/grpc++_core_stats.pdb + DESTINATION ${gRPC_INSTALL_LIBDIR} OPTIONAL + ) + endif() +endif() + +protobuf_generate_grpc_cpp( + src/proto/grpc/core/stats.proto +) + +target_include_directories(grpc++_core_stats + PUBLIC $ $ + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${BENCHMARK}/include + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CARES_BUILD_INCLUDE_DIR} + PRIVATE ${CARES_INCLUDE_DIR} + PRIVATE ${CARES_PLATFORM_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(grpc++_core_stats + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc++ +) + +foreach(_hdr + src/cpp/util/core_stats.h +) + string(REPLACE "include/" "" _path ${_hdr}) + get_filename_component(_path ${_path} PATH) + install(FILES ${_hdr} + DESTINATION "${gRPC_INSTALL_INCLUDEDIR}/${_path}" + ) +endforeach() + +endif (gRPC_BUILD_TESTS) add_library(grpc++_cronet src/cpp/client/cronet_credentials.cc @@ -4596,6 +4658,7 @@ target_link_libraries(qps ${_gRPC_ALLTARGETS_LIBRARIES} grpc_test_util grpc++_test_util + grpc++_core_stats grpc++ grpc ) @@ -10398,6 +10461,7 @@ target_include_directories(codegen_test_full target_link_libraries(codegen_test_full ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} + grpc++_core_stats grpc++ grpc gpr @@ -10473,6 +10537,7 @@ target_include_directories(codegen_test_minimal target_link_libraries(codegen_test_minimal ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} + grpc++_core_stats grpc gpr ${_gRPC_GFLAGS_LIBRARIES} @@ -12044,6 +12109,7 @@ target_link_libraries(qps_json_driver ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} qps + grpc++_core_stats grpc++_test_util grpc_test_util grpc++ diff --git a/Makefile b/Makefile index 4fd534df09..78451e2bda 100644 --- a/Makefile +++ b/Makefile @@ -1328,9 +1328,9 @@ pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc ifeq ($(EMBED_OPENSSL),true) -privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_proto_reflection_desc_db.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_cli_libs.a $(LIBDIR)/$(CONFIG)/libhttp2_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_lib.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl_aes_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_asn1_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_base64_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bio_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bn_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bytestring_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_aead_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cipher_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_constant_time_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ed25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_digest_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_p256-x86_64_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_extra_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pbkdf_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_hkdf_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_hmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_lhash_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_gcm_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs12_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs8_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_poly1305_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pool_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_refcount_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x509_test_lib.a $(LIBDIR)/$(CONFIG)/libbenchmark.a +privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_proto_reflection_desc_db.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_cli_libs.a $(LIBDIR)/$(CONFIG)/libhttp2_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_lib.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl_aes_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_asn1_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_base64_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bio_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bn_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bytestring_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_aead_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cipher_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_constant_time_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ed25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_digest_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_p256-x86_64_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_extra_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pbkdf_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_hkdf_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_hmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_lhash_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_gcm_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs12_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs8_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_poly1305_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pool_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_refcount_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x509_test_lib.a $(LIBDIR)/$(CONFIG)/libbenchmark.a else -privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_proto_reflection_desc_db.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_cli_libs.a $(LIBDIR)/$(CONFIG)/libhttp2_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_lib.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libbenchmark.a +privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_proto_reflection_desc_db.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_cli_libs.a $(LIBDIR)/$(CONFIG)/libhttp2_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_lib.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libbenchmark.a endif @@ -2240,6 +2240,22 @@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc: $(Q) mkdir -p $(@D) $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@ +ifeq ($(NO_PROTOC),true) +$(GENDIR)/src/proto/grpc/core/stats.pb.cc: protoc_dep_error +$(GENDIR)/src/proto/grpc/core/stats.grpc.pb.cc: protoc_dep_error +else + +$(GENDIR)/src/proto/grpc/core/stats.pb.cc: src/proto/grpc/core/stats.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) + $(E) "[PROTOC] Generating protobuf CC file from $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $< + +$(GENDIR)/src/proto/grpc/core/stats.grpc.pb.cc: src/proto/grpc/core/stats.proto $(GENDIR)/src/proto/grpc/core/stats.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) + $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" + $(Q) mkdir -p `dirname $@` + $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< +endif + ifeq ($(NO_PROTOC),true) $(GENDIR)/src/proto/grpc/health/v1/health.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/health/v1/health.grpc.pb.cc: protoc_dep_error @@ -2471,12 +2487,12 @@ $(GENDIR)/src/proto/grpc/testing/stats.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc: protoc_dep_error else -$(GENDIR)/src/proto/grpc/testing/stats.pb.cc: src/proto/grpc/testing/stats.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) +$(GENDIR)/src/proto/grpc/testing/stats.pb.cc: src/proto/grpc/testing/stats.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/core/stats.pb.cc $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $< -$(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc: src/proto/grpc/testing/stats.proto $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) +$(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc: src/proto/grpc/testing/stats.proto $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/core/stats.pb.cc $(GENDIR)/src/proto/grpc/core/stats.grpc.pb.cc $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" $(Q) mkdir -p `dirname $@` $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< @@ -4659,6 +4675,58 @@ endif endif +LIBGRPC++_CORE_STATS_SRC = \ + $(GENDIR)/src/proto/grpc/core/stats.pb.cc $(GENDIR)/src/proto/grpc/core/stats.grpc.pb.cc \ + src/cpp/util/core_stats.cc \ + +PUBLIC_HEADERS_CXX += \ + src/cpp/util/core_stats.h \ + +LIBGRPC++_CORE_STATS_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC++_CORE_STATS_SRC)))) + + +ifeq ($(NO_SECURE),true) + +# You can't build secure libraries if you don't have OpenSSL. + +$(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a: openssl_dep_error + + +else + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(PROTOBUF_DEP) $(LIBGRPC++_CORE_STATS_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBGRPC++_CORE_STATS_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a +endif + + + + +endif + +endif + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(LIBGRPC++_CORE_STATS_OBJS:.o=.dep) +endif +endif +$(OBJDIR)/$(CONFIG)/src/cpp/util/core_stats.o: $(GENDIR)/src/proto/grpc/core/stats.pb.cc $(GENDIR)/src/proto/grpc/core/stats.grpc.pb.cc + + LIBGRPC++_CRONET_SRC = \ src/cpp/client/cronet_credentials.cc \ src/cpp/client/insecure_credentials.cc \ @@ -14441,26 +14509,26 @@ $(BINDIR)/$(CONFIG)/codegen_test_full: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/codegen_test_full: $(PROTOBUF_DEP) $(CODEGEN_TEST_FULL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/codegen_test_full: $(PROTOBUF_DEP) $(CODEGEN_TEST_FULL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(CODEGEN_TEST_FULL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/codegen_test_full + $(Q) $(LDXX) $(LDFLAGS) $(CODEGEN_TEST_FULL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/codegen_test_full endif endif -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/control.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/control.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/messages.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/messages.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/payloads.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/payloads.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/services.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/services.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/stats.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/stats.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/test/cpp/codegen/codegen_test_full.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/cpp/codegen/codegen_test_full.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_codegen_test_full: $(CODEGEN_TEST_FULL_OBJS:.o=.dep) @@ -14501,28 +14569,28 @@ $(BINDIR)/$(CONFIG)/codegen_test_minimal: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/codegen_test_minimal: $(PROTOBUF_DEP) $(CODEGEN_TEST_MINIMAL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(BINDIR)/$(CONFIG)/codegen_test_minimal: $(PROTOBUF_DEP) $(CODEGEN_TEST_MINIMAL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(CODEGEN_TEST_MINIMAL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/codegen_test_minimal + $(Q) $(LDXX) $(LDFLAGS) $(CODEGEN_TEST_MINIMAL_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/codegen_test_minimal endif endif -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/control.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/control.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/messages.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/messages.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/payloads.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/payloads.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/services.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/services.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/stats.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/stats.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/test/cpp/codegen/codegen_test_minimal.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/test/cpp/codegen/codegen_test_minimal.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a -$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a +$(OBJDIR)/$(CONFIG)/src/cpp/codegen/codegen_init.o: $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a deps_codegen_test_minimal: $(CODEGEN_TEST_MINIMAL_OBJS:.o=.dep) @@ -16018,16 +16086,16 @@ $(BINDIR)/$(CONFIG)/qps_json_driver: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/qps_json_driver: $(PROTOBUF_DEP) $(QPS_JSON_DRIVER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(BINDIR)/$(CONFIG)/qps_json_driver: $(PROTOBUF_DEP) $(QPS_JSON_DRIVER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(QPS_JSON_DRIVER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_json_driver + $(Q) $(LDXX) $(LDFLAGS) $(QPS_JSON_DRIVER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_json_driver endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_json_driver.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_json_driver.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a deps_qps_json_driver: $(QPS_JSON_DRIVER_OBJS:.o=.dep) @@ -19766,6 +19834,7 @@ src/cpp/common/secure_create_auth_context.cc: $(OPENSSL_DEP) src/cpp/ext/proto_server_reflection.cc: $(OPENSSL_DEP) src/cpp/ext/proto_server_reflection_plugin.cc: $(OPENSSL_DEP) src/cpp/server/secure_server_credentials.cc: $(OPENSSL_DEP) +src/cpp/util/core_stats.cc: $(OPENSSL_DEP) src/cpp/util/error_details.cc: $(OPENSSL_DEP) src/csharp/ext/grpc_csharp_ext.c: $(OPENSSL_DEP) test/core/bad_client/bad_client.c: $(OPENSSL_DEP) diff --git a/build.yaml b/build.yaml index a43ad6ae31..00d34292fc 100644 --- a/build.yaml +++ b/build.yaml @@ -1323,6 +1323,16 @@ libs: - grpc++_codegen_base_src secure: check vs_project_guid: '{C187A093-A0FE-489D-A40A-6E33DE0F9FEB}' +- name: grpc++_core_stats + build: private + language: c++ + public_headers: + - src/cpp/util/core_stats.h + src: + - src/proto/grpc/core/stats.proto + - src/cpp/util/core_stats.cc + deps: + - grpc++ - name: grpc++_cronet build: all language: c++ @@ -1665,6 +1675,7 @@ libs: deps: - grpc_test_util - grpc++_test_util + - grpc++_core_stats - grpc++ - grpc - name: grpc_csharp_ext @@ -3796,6 +3807,7 @@ targets: - src/proto/grpc/testing/stats.proto - test/cpp/codegen/codegen_test_full.cc deps: + - grpc++_core_stats - grpc++ - grpc - gpr @@ -3813,6 +3825,7 @@ targets: - src/proto/grpc/testing/stats.proto - test/cpp/codegen/codegen_test_minimal.cc deps: + - grpc++_core_stats - grpc - gpr filegroups: @@ -4303,6 +4316,7 @@ targets: - test/cpp/qps/qps_json_driver.cc deps: - qps + - grpc++_core_stats - grpc++_test_util - grpc_test_util - grpc++ diff --git a/grpc.gyp b/grpc.gyp index 40938a4564..39f68766ed 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -1226,6 +1226,17 @@ 'src/cpp/codegen/codegen_init.cc', ], }, + { + 'target_name': 'grpc++_core_stats', + 'type': 'static_library', + 'dependencies': [ + 'grpc++', + ], + 'sources': [ + 'src/proto/grpc/core/stats.proto', + 'src/cpp/util/core_stats.cc', + ], + }, { 'target_name': 'grpc++_error_details', 'type': 'static_library', @@ -1508,6 +1519,7 @@ 'dependencies': [ 'grpc_test_util', 'grpc++_test_util', + 'grpc++_core_stats', 'grpc++', 'grpc', ], diff --git a/src/cpp/util/core_stats.cc b/src/cpp/util/core_stats.cc new file mode 100644 index 0000000000..edf0b1bb67 --- /dev/null +++ b/src/cpp/util/core_stats.cc @@ -0,0 +1,90 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/cpp/util/core_stats.h" + +#include + +using grpc::core::Bucket; +using grpc::core::Histogram; +using grpc::core::Metric; +using grpc::core::Stats; + +namespace grpc { + +void CoreStatsToProto(const grpc_stats_data& core, Stats* proto) { + for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { + Metric* m = proto->add_metrics(); + m->set_name(grpc_stats_counter_name[i]); + m->set_count(core.counters[i]); + } + for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { + Metric* m = proto->add_metrics(); + m->set_name(grpc_stats_histogram_name[i]); + Histogram* h = m->mutable_histogram(); + for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) { + Bucket* b = h->add_buckets(); + b->set_start(grpc_stats_histo_bucket_boundaries[i][j]); + b->set_count(core.histograms[grpc_stats_histo_start[i] + j]); + } + } +} + +void ProtoToCoreStats(const grpc::core::Stats& proto, grpc_stats_data* core) { + memset(core, 0, sizeof(*core)); + for (const auto& m : proto.metrics()) { + switch (m.value_case()) { + case Metric::VALUE_NOT_SET: + break; + case Metric::kCount: + for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { + if (m.name() == grpc_stats_counter_name[i]) { + core->counters[i] = m.count(); + break; + } + } + break; + case Metric::kHistogram: + for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { + if (m.name() == grpc_stats_histogram_name[i]) { + const auto& h = m.histogram(); + bool valid = true; + if (grpc_stats_histo_buckets[i] != h.buckets_size()) valid = false; + for (int j = 0; valid && j < h.buckets_size(); j++) { + if (grpc_stats_histo_bucket_boundaries[i][j] != + h.buckets(j).start()) { + valid = false; + } + } + if (!valid) { + gpr_log(GPR_ERROR, + "Found histogram %s but shape is different from proto", + m.name().c_str()); + } + for (int j = 0; valid && j < h.buckets_size(); j++) { + core->histograms[grpc_stats_histo_start[i] + j] = + h.buckets(j).count(); + } + } + } + break; + } + } +} + +} // namespace grpc diff --git a/src/cpp/util/core_stats.h b/src/cpp/util/core_stats.h new file mode 100644 index 0000000000..00e38bf266 --- /dev/null +++ b/src/cpp/util/core_stats.h @@ -0,0 +1,35 @@ +/* + * + * Copyright 2016 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_INTERNAL_CPP_UTIL_CORE_STATS_H +#define GRPC_INTERNAL_CPP_UTIL_CORE_STATS_H + +#include "src/proto/grpc/core/stats.pb.h" + +extern "C" { +#include "src/core/lib/debug/stats.h" +} + +namespace grpc { + +void CoreStatsToProto(const grpc_stats_data& core, grpc::core::Stats* proto); +void ProtoToCoreStats(const grpc::core::Stats& proto, grpc_stats_data* core); + +} // namespace grpc + +#endif // GRPC_INTERNAL_CPP_UTIL_CORE_STATS_H diff --git a/src/proto/grpc/core/stats.proto b/src/proto/grpc/core/stats.proto new file mode 100644 index 0000000000..ac181b0439 --- /dev/null +++ b/src/proto/grpc/core/stats.proto @@ -0,0 +1,38 @@ +// Copyright 2017 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package grpc.core; + +message Bucket { + double start = 1; + uint64 count = 2; +} + +message Histogram { + repeated Bucket buckets = 1; +} + +message Metric { + string name = 1; + oneof value { + uint64 count = 10; + Histogram histogram = 11; + } +} + +message Stats { + repeated Metric metrics = 1; +} diff --git a/src/proto/grpc/testing/stats.proto b/src/proto/grpc/testing/stats.proto index c738c4f895..a0f84ddbce 100644 --- a/src/proto/grpc/testing/stats.proto +++ b/src/proto/grpc/testing/stats.proto @@ -16,6 +16,8 @@ syntax = "proto3"; package grpc.testing; +import "src/proto/grpc/core/stats.proto"; + message ServerStats { // wall clock time change in seconds since last reset double time_elapsed = 1; @@ -35,6 +37,9 @@ message ServerStats { // Number of polls called inside completion queue uint64 cq_poll_count = 6; + + // Core library stats + grpc.core.Stats core_stats = 7; } // Histogram params based on grpc/support/histogram.c @@ -72,4 +77,7 @@ message ClientStats { // Number of polls called inside completion queue uint64 cq_poll_count = 6; + + // Core library stats + grpc.core.Stats core_stats = 7; } diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index b1d90aa9c4..7fbaf63492 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -34,6 +34,7 @@ #include "src/proto/grpc/testing/payloads.pb.h" #include "src/proto/grpc/testing/services.grpc.pb.h" +#include "src/cpp/util/core_stats.h" #include "test/cpp/qps/histogram.h" #include "test/cpp/qps/interarrival.h" #include "test/cpp/qps/usage_timer.h" @@ -172,6 +173,9 @@ class Client { timer_result = timer_->Mark(); } + grpc_stats_data core_stats; + grpc_stats_collect(&core_stats); + ClientStats stats; latencies.FillProto(stats.mutable_latencies()); for (StatusHistogram::const_iterator it = statuses.begin(); @@ -184,6 +188,7 @@ class Client { stats.set_time_system(timer_result.system); stats.set_time_user(timer_result.user); stats.set_cq_poll_count(poll_count); + CoreStatsToProto(core_stats, stats.mutable_core_stats()); return stats; } diff --git a/test/cpp/qps/report.cc b/test/cpp/qps/report.cc index a45b10bcb8..3c99bda144 100644 --- a/test/cpp/qps/report.cc +++ b/test/cpp/qps/report.cc @@ -26,6 +26,7 @@ #include "test/cpp/qps/stats.h" #include +#include "src/cpp/util/core_stats.h" #include "src/proto/grpc/testing/services.grpc.pb.h" namespace grpc { @@ -85,6 +86,33 @@ void GprLogReporter::ReportQPS(const ScenarioResult& result) { gpr_log(GPR_INFO, "successful requests/second: %.1f", result.summary().successful_requests_per_second()); } + for (int i = 0; i < result.client_stats_size(); i++) { + if (result.client_stats(i).has_core_stats()) { + ReportCoreStats("CLIENT", i, result.client_stats(i).core_stats()); + } + } + for (int i = 0; i < result.server_stats_size(); i++) { + if (result.server_stats(i).has_core_stats()) { + ReportCoreStats("SERVER", i, result.server_stats(i).core_stats()); + } + } +} + +void GprLogReporter::ReportCoreStats(const char* name, int idx, + const grpc::core::Stats& stats) { + grpc_stats_data data; + ProtoToCoreStats(stats, &data); + for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { + gpr_log(GPR_DEBUG, "%s[%d].%s = %" PRIdPTR, name, idx, + grpc_stats_counter_name[i], data.counters[i]); + } + for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { + gpr_log(GPR_DEBUG, "%s[%d].%s = %lf/%lf/%lf (50/95/99%%-ile)", name, idx, + grpc_stats_histogram_name[i], + grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 50), + grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 95), + grpc_stats_histo_percentile(&data, (grpc_stats_histograms)i, 99)); + } } void GprLogReporter::ReportQPSPerCore(const ScenarioResult& result) { diff --git a/test/cpp/qps/report.h b/test/cpp/qps/report.h index 321be2a97f..1d7b2b54e7 100644 --- a/test/cpp/qps/report.h +++ b/test/cpp/qps/report.h @@ -104,6 +104,9 @@ class GprLogReporter : public Reporter { void ReportCpuUsage(const ScenarioResult& result) override; void ReportPollCount(const ScenarioResult& result) override; void ReportQueriesPerCpuSec(const ScenarioResult& result) override; + + void ReportCoreStats(const char* name, int idx, + const grpc::core::Stats& stats); }; /** Dumps the report to a JSON file. */ diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index 3d6f347cae..16d101d5e6 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -26,6 +26,7 @@ #include #include +#include "src/cpp/util/core_stats.h" #include "src/proto/grpc/testing/control.pb.h" #include "src/proto/grpc/testing/messages.pb.h" #include "test/core/end2end/data/ssl_test_data.h" @@ -63,6 +64,9 @@ class Server { timer_result = timer_->Mark(); } + grpc_stats_data core_stats; + grpc_stats_collect(&core_stats); + ServerStats stats; stats.set_time_elapsed(timer_result.wall); stats.set_time_system(timer_result.system); @@ -70,6 +74,7 @@ class Server { stats.set_total_cpu_time(timer_result.total_cpu_time); stats.set_idle_cpu_time(timer_result.idle_cpu_time); stats.set_cq_poll_count(poll_count); + CoreStatsToProto(core_stats, stats.mutable_core_stats()); return stats; } diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 5ce25dc14a..ecfb96ee8d 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -2969,7 +2969,8 @@ "gpr", "grpc", "grpc++", - "grpc++_codegen_base" + "grpc++_codegen_base", + "grpc++_core_stats" ], "headers": [ "src/proto/grpc/testing/control.grpc.pb.h", @@ -3002,7 +3003,8 @@ "gpr", "grpc", "grpc++_codegen_base", - "grpc++_codegen_base_src" + "grpc++_codegen_base_src", + "grpc++_core_stats" ], "headers": [ "src/proto/grpc/testing/control.grpc.pb.h", @@ -3702,6 +3704,7 @@ "gpr_test_util", "grpc", "grpc++", + "grpc++_core_stats", "grpc++_test_config", "grpc++_test_util", "grpc_test_util", @@ -6022,6 +6025,26 @@ "third_party": false, "type": "lib" }, + { + "deps": [ + "grpc++" + ], + "headers": [ + "src/cpp/util/core_stats.h", + "src/proto/grpc/core/stats.grpc.pb.h", + "src/proto/grpc/core/stats.pb.h", + "src/proto/grpc/core/stats_mock.grpc.pb.h" + ], + "is_filegroup": false, + "language": "c++", + "name": "grpc++_core_stats", + "src": [ + "src/cpp/util/core_stats.cc", + "src/cpp/util/core_stats.h" + ], + "third_party": false, + "type": "lib" + }, { "deps": [ "census", @@ -6518,6 +6541,7 @@ "deps": [ "grpc", "grpc++", + "grpc++_core_stats", "grpc++_test_util", "grpc_test_util" ], -- cgit v1.2.3 From 57bb9a9c35f0ae18b749512d168608f55a40ff71 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 31 Aug 2017 16:44:15 -0700 Subject: Expose more stats --- .../transport/chttp2/transport/chttp2_transport.c | 12 ++ src/core/ext/transport/chttp2/transport/writing.c | 4 + src/core/lib/debug/stats_data.c | 38 ++++-- src/core/lib/debug/stats_data.h | 140 +++++++++++++++++++-- src/core/lib/debug/stats_data.yaml | 35 +++++- src/core/lib/iomgr/combiner.c | 5 + src/core/lib/iomgr/executor.c | 6 + src/core/lib/iomgr/tcp_posix.c | 7 +- 8 files changed, 224 insertions(+), 23 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 7541bd5c92..3277cefc2d 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -34,6 +34,7 @@ #include "src/core/ext/transport/chttp2/transport/varint.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/compression/stream_compression.h" +#include "src/core/lib/debug/stats.h" #include "src/core/lib/http/parser.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/timer.h" @@ -1258,6 +1259,8 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, grpc_transport_stream_op_batch_payload *op_payload = op->payload; grpc_chttp2_transport *t = s->t; + GRPC_STATS_INC_HTTP2_OP_BATCHES(exec_ctx); + if (GRPC_TRACER_ON(grpc_http_trace)) { char *str = grpc_transport_stream_op_batch_string(op); gpr_log(GPR_DEBUG, "perform_stream_op_locked: %s; on_complete = %p", str, @@ -1291,11 +1294,13 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, } if (op->cancel_stream) { + GRPC_STATS_INC_HTTP2_OP_CANCEL(exec_ctx); grpc_chttp2_cancel_stream(exec_ctx, t, s, op_payload->cancel_stream.cancel_error); } if (op->send_initial_metadata) { + GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA(exec_ctx); GPR_ASSERT(s->send_initial_metadata_finished == NULL); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; @@ -1373,6 +1378,9 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, } if (op->send_message) { + GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE(exec_ctx); + GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE( + exec_ctx, op->payload->send_message.send_message->length); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->fetching_send_message_finished = add_closure_barrier(op->on_complete); if (s->write_closed) { @@ -1410,6 +1418,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, } if (op->send_trailing_metadata) { + GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA(exec_ctx); GPR_ASSERT(s->send_trailing_metadata_finished == NULL); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->send_trailing_metadata_finished = add_closure_barrier(on_complete); @@ -1459,6 +1468,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, } if (op->recv_initial_metadata) { + GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA(exec_ctx); GPR_ASSERT(s->recv_initial_metadata_ready == NULL); s->recv_initial_metadata_ready = op_payload->recv_initial_metadata.recv_initial_metadata_ready; @@ -1470,6 +1480,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, } if (op->recv_message) { + GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE(exec_ctx); size_t already_received; GPR_ASSERT(s->recv_message_ready == NULL); GPR_ASSERT(!s->pending_byte_stream); @@ -1491,6 +1502,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, } if (op->recv_trailing_metadata) { + GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA(exec_ctx); GPR_ASSERT(s->recv_trailing_metadata_finished == NULL); s->recv_trailing_metadata_finished = add_closure_barrier(on_complete); s->recv_trailing_metadata = diff --git a/src/core/ext/transport/chttp2/transport/writing.c b/src/core/ext/transport/chttp2/transport/writing.c index 80eb51ff0d..c16ffaa5ef 100644 --- a/src/core/ext/transport/chttp2/transport/writing.c +++ b/src/core/ext/transport/chttp2/transport/writing.c @@ -22,6 +22,7 @@ #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/http2_errors.h" @@ -116,6 +117,7 @@ static void maybe_initiate_ping(grpc_exec_ctx *exec_ctx, &pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]); grpc_slice_buffer_add(&t->outbuf, grpc_chttp2_ping_create(false, pq->inflight_id)); + GRPC_STATS_INC_HTTP2_PINGS_SENT(exec_ctx); t->ping_state.last_ping_sent_time = now; t->ping_state.pings_before_data_required -= (t->ping_state.pings_before_data_required != 0); @@ -171,6 +173,8 @@ grpc_chttp2_begin_write_result grpc_chttp2_begin_write( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t) { grpc_chttp2_stream *s; + GRPC_STATS_INC_HTTP2_WRITES_BEGUN(exec_ctx); + GPR_TIMER_BEGIN("grpc_chttp2_begin_write", 0); if (t->dirtied_local_settings && !t->sent_local_settings) { diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index 177234ab5b..792ca14ac9 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -20,12 +20,35 @@ #include "src/core/lib/debug/stats_data.h" const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { - "client_calls_created", "server_calls_created", "syscall_write", - "syscall_read", "syscall_poll", "syscall_wait", + "client_calls_created", + "server_calls_created", + "syscall_poll", + "syscall_wait", "histogram_slow_lookups", + "syscall_write", + "syscall_read", + "http2_op_batches", + "http2_op_cancel", + "http2_op_send_initial_metadata", + "http2_op_send_message", + "http2_op_send_trailing_metadata", + "http2_op_recv_initial_metadata", + "http2_op_recv_message", + "http2_op_recv_trailing_metadata", + "http2_pings_sent", + "http2_writes_begun", + "combiner_locks_initiated", + "combiner_locks_scheduled_items", + "combiner_locks_scheduled_final_items", + "combiner_locks_offloaded", + "executor_scheduled_items", + "executor_scheduled_to_self", + "executor_wakeup_initiated", + "executor_queue_drained", }; const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = { - "tcp_write_size", "tcp_write_iov_size", "tcp_read_size", + "tcp_write_size", "tcp_write_iov_size", "tcp_read_size", + "tcp_read_iov_size", "http2_send_message_size", }; const double grpc_stats_table_0[64] = {0, 1, @@ -165,7 +188,8 @@ const uint8_t grpc_stats_table_3[52] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52}; -const int grpc_stats_histo_buckets[3] = {64, 64, 64}; -const int grpc_stats_histo_start[3] = {0, 64, 128}; -const double *const grpc_stats_histo_bucket_boundaries[3] = { - grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0}; +const int grpc_stats_histo_buckets[5] = {64, 64, 64, 64, 64}; +const int grpc_stats_histo_start[5] = {0, 64, 128, 192, 256}; +const double *const grpc_stats_histo_bucket_boundaries[5] = { + grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0, + grpc_stats_table_2, grpc_stats_table_0}; diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 9a4ba68655..a3122bd871 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -26,11 +26,29 @@ typedef enum { GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED, GRPC_STATS_COUNTER_SERVER_CALLS_CREATED, - GRPC_STATS_COUNTER_SYSCALL_WRITE, - GRPC_STATS_COUNTER_SYSCALL_READ, GRPC_STATS_COUNTER_SYSCALL_POLL, GRPC_STATS_COUNTER_SYSCALL_WAIT, GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS, + GRPC_STATS_COUNTER_SYSCALL_WRITE, + GRPC_STATS_COUNTER_SYSCALL_READ, + GRPC_STATS_COUNTER_HTTP2_OP_BATCHES, + GRPC_STATS_COUNTER_HTTP2_OP_CANCEL, + GRPC_STATS_COUNTER_HTTP2_OP_SEND_INITIAL_METADATA, + GRPC_STATS_COUNTER_HTTP2_OP_SEND_MESSAGE, + GRPC_STATS_COUNTER_HTTP2_OP_SEND_TRAILING_METADATA, + GRPC_STATS_COUNTER_HTTP2_OP_RECV_INITIAL_METADATA, + GRPC_STATS_COUNTER_HTTP2_OP_RECV_MESSAGE, + GRPC_STATS_COUNTER_HTTP2_OP_RECV_TRAILING_METADATA, + GRPC_STATS_COUNTER_HTTP2_PINGS_SENT, + GRPC_STATS_COUNTER_HTTP2_WRITES_BEGUN, + GRPC_STATS_COUNTER_COMBINER_LOCKS_INITIATED, + GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_ITEMS, + GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS, + GRPC_STATS_COUNTER_COMBINER_LOCKS_OFFLOADED, + GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_ITEMS, + GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_TO_SELF, + GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED, + GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED, GRPC_STATS_COUNTER_COUNT } grpc_stats_counters; extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT]; @@ -38,6 +56,8 @@ typedef enum { GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, + GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, GRPC_STATS_HISTOGRAM_COUNT } grpc_stats_histograms; extern const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT]; @@ -48,22 +68,73 @@ typedef enum { GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE_BUCKETS = 64, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE_FIRST_SLOT = 128, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE_BUCKETS = 64, - GRPC_STATS_HISTOGRAM_BUCKETS = 192 + GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE_FIRST_SLOT = 192, + GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE_BUCKETS = 64, + GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE_FIRST_SLOT = 256, + GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE_BUCKETS = 64, + GRPC_STATS_HISTOGRAM_BUCKETS = 320 } grpc_stats_histogram_constants; #define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) #define GRPC_STATS_INC_SERVER_CALLS_CREATED(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SERVER_CALLS_CREATED) -#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) -#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) \ - GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) #define GRPC_STATS_INC_SYSCALL_POLL(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_POLL) #define GRPC_STATS_INC_SYSCALL_WAIT(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) #define GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS) +#define GRPC_STATS_INC_SYSCALL_WRITE(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WRITE) +#define GRPC_STATS_INC_SYSCALL_READ(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_READ) +#define GRPC_STATS_INC_HTTP2_OP_BATCHES(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_BATCHES) +#define GRPC_STATS_INC_HTTP2_OP_CANCEL(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_CANCEL) +#define GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_OP_SEND_INITIAL_METADATA) +#define GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_SEND_MESSAGE) +#define GRPC_STATS_INC_HTTP2_OP_SEND_TRAILING_METADATA(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_OP_SEND_TRAILING_METADATA) +#define GRPC_STATS_INC_HTTP2_OP_RECV_INITIAL_METADATA(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_OP_RECV_INITIAL_METADATA) +#define GRPC_STATS_INC_HTTP2_OP_RECV_MESSAGE(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_OP_RECV_MESSAGE) +#define GRPC_STATS_INC_HTTP2_OP_RECV_TRAILING_METADATA(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_HTTP2_OP_RECV_TRAILING_METADATA) +#define GRPC_STATS_INC_HTTP2_PINGS_SENT(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_PINGS_SENT) +#define GRPC_STATS_INC_HTTP2_WRITES_BEGUN(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HTTP2_WRITES_BEGUN) +#define GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_COMBINER_LOCKS_INITIATED) +#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_ITEMS) +#define GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(exec_ctx) \ + GRPC_STATS_INC_COUNTER( \ + (exec_ctx), GRPC_STATS_COUNTER_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS) +#define GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_COMBINER_LOCKS_OFFLOADED) +#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_ITEMS(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_ITEMS) +#define GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_EXECUTOR_SCHEDULED_TO_SELF) +#define GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), \ + GRPC_STATS_COUNTER_EXECUTOR_WAKEUP_INITIATED) +#define GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(exec_ctx) \ + GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_EXECUTOR_QUEUE_DRAINED) #define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \ do { \ union { \ @@ -136,12 +207,61 @@ typedef enum { } \ } \ } while (false) +#define GRPC_STATS_INC_TCP_READ_IOV_SIZE(exec_ctx, value) \ + do { \ + union { \ + double dbl; \ + uint64_t uint; \ + } _val; \ + _val.dbl = (double)(value); \ + if (_val.dbl < 0) _val.dbl = 0; \ + if (_val.dbl < 12.000000) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, (int)_val.dbl); \ + } else { \ + if (_val.uint < 4652218415073722368ull) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, \ + grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 49)]); \ + } else { \ + 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)); \ + } \ + } \ + } while (false) +#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE(exec_ctx, value) \ + do { \ + union { \ + double dbl; \ + uint64_t uint; \ + } _val; \ + _val.dbl = (double)(value); \ + if (_val.dbl < 0) _val.dbl = 0; \ + if (_val.dbl < 5.000000) { \ + GRPC_STATS_INC_HISTOGRAM((exec_ctx), \ + GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, \ + (int)_val.dbl); \ + } else { \ + if (_val.uint < 4715268809856909312ull) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, \ + grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)]); \ + } else { \ + 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)); \ + } \ + } \ + } while (false) extern const double grpc_stats_table_0[64]; extern const uint8_t grpc_stats_table_1[87]; extern const double grpc_stats_table_2[64]; extern const uint8_t grpc_stats_table_3[52]; -extern const int grpc_stats_histo_buckets[3]; -extern const int grpc_stats_histo_start[3]; -extern const double *const grpc_stats_histo_bucket_boundaries[3]; +extern const int grpc_stats_histo_buckets[5]; +extern const int grpc_stats_histo_start[5]; +extern const double *const grpc_stats_histo_bucket_boundaries[5]; #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index b8d5f71991..780142b9db 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -1,13 +1,17 @@ #Stats data declaration #use tools / codegen / core / gen_stats_data.py to turn this into stats_data.h +# overall - counter: client_calls_created - counter: server_calls_created -- counter: syscall_write -- counter: syscall_read +# polling - counter: syscall_poll - counter: syscall_wait +# stats system - counter: histogram_slow_lookups +# tcp +- counter: syscall_write +- counter: syscall_read - histogram: tcp_write_size max: 16777216 # 16 meg max write tracked buckets: 64 @@ -17,3 +21,30 @@ - histogram: tcp_read_size max: 16777216 buckets: 64 +- histogram: tcp_read_iov_size + max: 1024 + buckets: 64 +# chttp2 +- counter: http2_op_batches +- counter: http2_op_cancel +- counter: http2_op_send_initial_metadata +- counter: http2_op_send_message +- counter: http2_op_send_trailing_metadata +- counter: http2_op_recv_initial_metadata +- counter: http2_op_recv_message +- counter: http2_op_recv_trailing_metadata +- histogram: http2_send_message_size + max: 16777216 + buckets: 64 +- counter: http2_pings_sent +- counter: http2_writes_begun +# combiner locks +- counter: combiner_locks_initiated +- counter: combiner_locks_scheduled_items +- counter: combiner_locks_scheduled_final_items +- counter: combiner_locks_offloaded +# executor +- counter: executor_scheduled_items +- counter: executor_scheduled_to_self +- counter: executor_wakeup_initiated +- counter: executor_queue_drained diff --git a/src/core/lib/iomgr/combiner.c b/src/core/lib/iomgr/combiner.c index 9b66987b68..4c1503bddb 100644 --- a/src/core/lib/iomgr/combiner.c +++ b/src/core/lib/iomgr/combiner.c @@ -24,6 +24,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/profiling/timers.h" @@ -153,6 +154,7 @@ static void push_first_on_exec_ctx(grpc_exec_ctx *exec_ctx, static void combiner_exec(grpc_exec_ctx *exec_ctx, grpc_closure *cl, grpc_error *error) { + GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_ITEMS(exec_ctx); GPR_TIMER_BEGIN("combiner.execute", 0); grpc_combiner *lock = COMBINER_FROM_CLOSURE_SCHEDULER(cl, scheduler); gpr_atm last = gpr_atm_full_fetch_add(&lock->state, STATE_ELEM_COUNT_LOW_BIT); @@ -160,6 +162,7 @@ static void combiner_exec(grpc_exec_ctx *exec_ctx, grpc_closure *cl, "C:%p grpc_combiner_execute c=%p last=%" PRIdPTR, lock, cl, last)); if (last == 1) { + GRPC_STATS_INC_COMBINER_LOCKS_INITIATED(exec_ctx); gpr_atm_no_barrier_store(&lock->initiating_exec_ctx_or_null, (gpr_atm)exec_ctx); // first element on this list: add it to the list of combiner locks @@ -195,6 +198,7 @@ static void offload(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { } static void queue_offload(grpc_exec_ctx *exec_ctx, grpc_combiner *lock) { + GRPC_STATS_INC_COMBINER_LOCKS_OFFLOADED(exec_ctx); move_next(exec_ctx); GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, "C:%p queue_offload", lock)); GRPC_CLOSURE_SCHED(exec_ctx, &lock->offload, GRPC_ERROR_NONE); @@ -325,6 +329,7 @@ static void enqueue_finally(grpc_exec_ctx *exec_ctx, void *closure, static void combiner_finally_exec(grpc_exec_ctx *exec_ctx, grpc_closure *closure, grpc_error *error) { + GRPC_STATS_INC_COMBINER_LOCKS_SCHEDULED_FINAL_ITEMS(exec_ctx); grpc_combiner *lock = COMBINER_FROM_CLOSURE_SCHEDULER(closure, finally_scheduler); GRPC_COMBINER_TRACE(gpr_log(GPR_DEBUG, diff --git a/src/core/lib/iomgr/executor.c b/src/core/lib/iomgr/executor.c index 7621a7fe75..dd5cb2a64e 100644 --- a/src/core/lib/iomgr/executor.c +++ b/src/core/lib/iomgr/executor.c @@ -28,6 +28,7 @@ #include #include +#include "src/core/lib/debug/stats.h" #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/support/spinlock.h" @@ -145,6 +146,7 @@ static void executor_thread(void *arg) { gpr_mu_unlock(&ts->mu); break; } + GRPC_STATS_INC_EXECUTOR_QUEUE_DRAINED(&exec_ctx); grpc_closure_list exec = ts->elems; ts->elems = (grpc_closure_list)GRPC_CLOSURE_LIST_INIT; gpr_mu_unlock(&ts->mu); @@ -158,6 +160,7 @@ static void executor_thread(void *arg) { static void executor_push(grpc_exec_ctx *exec_ctx, grpc_closure *closure, grpc_error *error) { size_t cur_thread_count = (size_t)gpr_atm_no_barrier_load(&g_cur_threads); + GRPC_STATS_INC_EXECUTOR_SCHEDULED_ITEMS(exec_ctx); if (cur_thread_count == 0) { grpc_closure_list_append(&exec_ctx->closure_list, closure, error); return; @@ -165,9 +168,12 @@ static void executor_push(grpc_exec_ctx *exec_ctx, grpc_closure *closure, thread_state *ts = (thread_state *)gpr_tls_get(&g_this_thread_state); if (ts == NULL) { ts = &g_thread_state[GPR_HASH_POINTER(exec_ctx, cur_thread_count)]; + } else { + GRPC_STATS_INC_EXECUTOR_SCHEDULED_TO_SELF(exec_ctx); } gpr_mu_lock(&ts->mu); if (grpc_closure_list_empty(ts->elems)) { + GRPC_STATS_INC_EXECUTOR_WAKEUP_INITIATED(exec_ctx); gpr_cv_signal(&ts->cv); } grpc_closure_list_append(&ts->elems, closure, error); diff --git a/src/core/lib/iomgr/tcp_posix.c b/src/core/lib/iomgr/tcp_posix.c index ccf328ec1c..59a4012add 100644 --- a/src/core/lib/iomgr/tcp_posix.c +++ b/src/core/lib/iomgr/tcp_posix.c @@ -67,7 +67,6 @@ typedef struct { grpc_fd *em_fd; int fd; bool finished_edge; - msg_iovlen_type iov_size; /* Number of slices to allocate per read attempt */ double target_length; double bytes_read_this_round; gpr_refcount refcount; @@ -240,7 +239,6 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { size_t i; GPR_ASSERT(!tcp->finished_edge); - GPR_ASSERT(tcp->iov_size <= MAX_READ_IOVEC); GPR_ASSERT(tcp->incoming_buffer->count <= MAX_READ_IOVEC); GPR_TIMER_BEGIN("tcp_continue_read", 0); @@ -252,11 +250,13 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_iov = iov; - msg.msg_iovlen = tcp->iov_size; + msg.msg_iovlen = tcp->incoming_buffer->count; msg.msg_control = NULL; msg.msg_controllen = 0; msg.msg_flags = 0; + GRPC_STATS_INC_TCP_READ_IOV_SIZE(exec_ctx, tcp->incoming_buffer->count); + GPR_TIMER_BEGIN("recvmsg", 0); do { GRPC_STATS_INC_SYSCALL_READ(exec_ctx); @@ -625,7 +625,6 @@ grpc_endpoint *grpc_tcp_create(grpc_exec_ctx *exec_ctx, grpc_fd *em_fd, tcp->min_read_chunk_size = tcp_min_read_chunk_size; tcp->max_read_chunk_size = tcp_max_read_chunk_size; tcp->bytes_read_this_round = 0; - tcp->iov_size = 1; tcp->finished_edge = true; /* paired with unref in grpc_tcp_destroy */ gpr_ref_init(&tcp->refcount, 1); -- cgit v1.2.3 From c92f18ce86ecd8950e5faa2545fbcb24c5c9afb5 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 31 Aug 2017 16:46:32 -0700 Subject: Expose more stats --- src/core/lib/debug/stats_data.c | 12 ++++++------ src/core/lib/debug/stats_data.h | 39 ++++++++++++++++++++++++++++++++------ src/core/lib/debug/stats_data.yaml | 3 +++ src/core/lib/iomgr/tcp_posix.c | 1 + 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index 792ca14ac9..9277ee57b2 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -47,8 +47,8 @@ const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { "executor_queue_drained", }; const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = { - "tcp_write_size", "tcp_write_iov_size", "tcp_read_size", - "tcp_read_iov_size", "http2_send_message_size", + "tcp_write_size", "tcp_write_iov_size", "tcp_read_size", + "tcp_read_offer", "tcp_read_iov_size", "http2_send_message_size", }; const double grpc_stats_table_0[64] = {0, 1, @@ -188,8 +188,8 @@ const uint8_t grpc_stats_table_3[52] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52}; -const int grpc_stats_histo_buckets[5] = {64, 64, 64, 64, 64}; -const int grpc_stats_histo_start[5] = {0, 64, 128, 192, 256}; -const double *const grpc_stats_histo_bucket_boundaries[5] = { +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}; +const double *const grpc_stats_histo_bucket_boundaries[6] = { grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0, - grpc_stats_table_2, grpc_stats_table_0}; + grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0}; diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index a3122bd871..4d1078dfdb 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -56,6 +56,7 @@ typedef enum { GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, GRPC_STATS_HISTOGRAM_COUNT @@ -68,11 +69,13 @@ typedef enum { GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE_BUCKETS = 64, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE_FIRST_SLOT = 128, GRPC_STATS_HISTOGRAM_TCP_READ_SIZE_BUCKETS = 64, - GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE_FIRST_SLOT = 192, + GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_FIRST_SLOT = 192, + GRPC_STATS_HISTOGRAM_TCP_READ_OFFER_BUCKETS = 64, + GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE_FIRST_SLOT = 256, GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE_BUCKETS = 64, - GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE_FIRST_SLOT = 256, + GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE_FIRST_SLOT = 320, GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE_BUCKETS = 64, - GRPC_STATS_HISTOGRAM_BUCKETS = 320 + GRPC_STATS_HISTOGRAM_BUCKETS = 384 } grpc_stats_histogram_constants; #define GRPC_STATS_INC_CLIENT_CALLS_CREATED(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED) @@ -207,6 +210,30 @@ typedef enum { } \ } \ } while (false) +#define GRPC_STATS_INC_TCP_READ_OFFER(exec_ctx, value) \ + do { \ + union { \ + double dbl; \ + uint64_t uint; \ + } _val; \ + _val.dbl = (double)(value); \ + if (_val.dbl < 0) _val.dbl = 0; \ + if (_val.dbl < 5.000000) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, (int)_val.dbl); \ + } else { \ + if (_val.uint < 4715268809856909312ull) { \ + GRPC_STATS_INC_HISTOGRAM( \ + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, \ + grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)]); \ + } else { \ + 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)); \ + } \ + } \ + } while (false) #define GRPC_STATS_INC_TCP_READ_IOV_SIZE(exec_ctx, value) \ do { \ union { \ @@ -260,8 +287,8 @@ extern const double grpc_stats_table_0[64]; extern const uint8_t grpc_stats_table_1[87]; extern const double grpc_stats_table_2[64]; extern const uint8_t grpc_stats_table_3[52]; -extern const int grpc_stats_histo_buckets[5]; -extern const int grpc_stats_histo_start[5]; -extern const double *const grpc_stats_histo_bucket_boundaries[5]; +extern const int grpc_stats_histo_buckets[6]; +extern const int grpc_stats_histo_start[6]; +extern const double *const grpc_stats_histo_bucket_boundaries[6]; #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index 780142b9db..18269a252b 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -21,6 +21,9 @@ - histogram: tcp_read_size max: 16777216 buckets: 64 +- histogram: tcp_read_offer + max: 16777216 + buckets: 64 - histogram: tcp_read_iov_size max: 1024 buckets: 64 diff --git a/src/core/lib/iomgr/tcp_posix.c b/src/core/lib/iomgr/tcp_posix.c index 59a4012add..793147f30a 100644 --- a/src/core/lib/iomgr/tcp_posix.c +++ b/src/core/lib/iomgr/tcp_posix.c @@ -255,6 +255,7 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { msg.msg_controllen = 0; msg.msg_flags = 0; + GRPC_STATS_INC_TCP_READ_OFFER(exec_ctx, tcp->incoming_buffer->length); GRPC_STATS_INC_TCP_READ_IOV_SIZE(exec_ctx, tcp->incoming_buffer->count); GPR_TIMER_BEGIN("recvmsg", 0); -- cgit v1.2.3 From d8a5ece8ee903fb0b7088004c2c300bf0d19590f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 1 Sep 2017 09:03:00 -0700 Subject: Cleanup comment --- src/core/lib/debug/stats_data.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index 18269a252b..178e47722f 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -1,5 +1,5 @@ -#Stats data declaration -#use tools / codegen / core / gen_stats_data.py to turn this into stats_data.h +# Stats data declaration +# use tools / codegen / core / gen_stats_data.py to turn this into stats_data.h # overall - counter: client_calls_created -- cgit v1.2.3 From 86115cd114171a087fb3cb8ecf1bed2d9fd37e44 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 1 Sep 2017 09:03:21 -0700 Subject: Add copyright --- src/core/lib/debug/stats_data.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core/lib/debug/stats_data.yaml b/src/core/lib/debug/stats_data.yaml index 178e47722f..a0d042a688 100644 --- a/src/core/lib/debug/stats_data.yaml +++ b/src/core/lib/debug/stats_data.yaml @@ -1,3 +1,17 @@ +# Copyright 2017 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # Stats data declaration # use tools / codegen / core / gen_stats_data.py to turn this into stats_data.h -- cgit v1.2.3 From da5cd59ed3f383318fb01b1bf461489cc828d453 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 1 Sep 2017 10:03:40 -0700 Subject: Restrict histograms to integral boundaries --- src/core/lib/debug/stats.c | 6 +- src/core/lib/debug/stats.h | 2 +- src/core/lib/debug/stats_data.c | 166 ++++++----------------------------- src/core/lib/debug/stats_data.h | 12 +-- tools/codegen/core/gen_stats_data.py | 17 ++-- 5 files changed, 48 insertions(+), 155 deletions(-) diff --git a/src/core/lib/debug/stats.c b/src/core/lib/debug/stats.c index 5079ed2ffa..a65dfe49b1 100644 --- a/src/core/lib/debug/stats.c +++ b/src/core/lib/debug/stats.c @@ -63,7 +63,7 @@ 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, - const double *table, int table_size) { + 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; @@ -92,7 +92,7 @@ size_t grpc_stats_histo_count(const grpc_stats_data *stats, } static double threshold_for_count_below(const gpr_atm *bucket_counts, - const double *bucket_boundaries, + const int *bucket_boundaries, int num_buckets, double count_below) { double count_so_far; double lower_bound; @@ -163,7 +163,7 @@ char *grpc_stats_data_as_json(const grpc_stats_data *data) { gpr_asprintf(&tmp, "], \"%s_bkt\": [", grpc_stats_histogram_name[i]); gpr_strvec_add(&v, tmp); for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) { - gpr_asprintf(&tmp, "%s%lf", j == 0 ? "" : ",", + gpr_asprintf(&tmp, "%s%d", j == 0 ? "" : ",", grpc_stats_histo_bucket_boundaries[i][j]); gpr_strvec_add(&v, tmp); } diff --git a/src/core/lib/debug/stats.h b/src/core/lib/debug/stats.h index c440ab3b66..9d729c20f4 100644 --- a/src/core/lib/debug/stats.h +++ b/src/core/lib/debug/stats.h @@ -51,7 +51,7 @@ 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, - const double *table, int table_size); + const int *table, int table_size); double grpc_stats_histo_percentile(const grpc_stats_data *data, grpc_stats_histograms histogram, double percentile); diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index 9277ee57b2..47f482bd1b 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -50,146 +50,36 @@ const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = { "tcp_write_size", "tcp_write_iov_size", "tcp_read_size", "tcp_read_offer", "tcp_read_iov_size", "http2_send_message_size", }; -const double grpc_stats_table_0[64] = {0, - 1, - 2, - 3, - 4, - 5.17974600698, - 6.70744217421, - 8.68571170472, - 11.2474451301, - 14.5647272503, - 18.8603969544, - 24.4230164536, - 31.6262554885, - 40.9539926456, - 53.032819969, - 68.6741343683, - 88.9286433193, - 115.156946285, - 149.120933174, - 193.102139541, - 250.055009057, - 323.805358672, - 419.307378404, - 542.976429747, - 703.119998467, - 910.495751121, - 1179.03418281, - 1526.77440013, - 1977.07590065, - 2560.18775048, - 3315.28056941, - 4293.07782286, - 5559.26317765, - 7198.89281155, - 9322.10907382, - 12071.5393129, - 15631.8768886, - 20242.2879738, - 26212.4775761, - 33943.4940145, - 43954.6693961, - 56918.5058232, - 73705.8508152, - 95444.3966128, - 123594.433061, - 160046.942783, - 207250.628202, - 268376.403469, - 347530.401059, - 450029.801797, - 582760.01722, - 754637.218056, - 977207.279236, - 1265421.37565, - 1638640.32942, - 2121935.1758, - 2747771.31348, - 3558189.37227, - 4607629.29828, - 5966587.36485, - 7726351.7696, - 10005134.9318, - 12956014.428, - 16777216.0}; +const int grpc_stats_table_0[64] = { + 0, 1, 2, 3, 4, 6, 8, 11, + 15, 20, 26, 34, 44, 57, 74, 96, + 124, 160, 206, 265, 341, 439, 565, 727, + 935, 1202, 1546, 1988, 2556, 3286, 4225, 5432, + 6983, 8977, 11540, 14834, 19069, 24513, 31510, 40505, + 52067, 66929, 86033, 110590, 142157, 182734, 234893, 301940, + 388125, 498910, 641316, 824370, 1059674, 1362141, 1750943, 2250722, + 2893155, 3718960, 4780478, 6144988, 7898976, 10153611, 13051794, 16777216}; const uint8_t grpc_stats_table_1[87] = { - 0, 1, 3, 3, 4, 6, 6, 7, 9, 9, 10, 12, 12, 13, 15, 15, 16, 18, - 18, 19, 21, 21, 22, 24, 24, 25, 27, 27, 28, 30, 30, 31, 32, 34, 34, 36, - 36, 37, 39, 39, 40, 42, 42, 43, 44, 46, 46, 47, 49, 49, 51, 51, 52, 53, - 55, 55, 56, 58, 58, 59, 61, 61, 63, 63, 64, 65, 67, 67, 68, 70, 70, 71, - 73, 73, 75, 75, 76, 77, 79, 79, 80, 82, 82, 83, 85, 85, 87}; -const double grpc_stats_table_2[64] = {0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12.0020736244, - 13.0954337532, - 14.2883963681, - 15.5900350167, - 17.0102498252, - 18.5598427974, - 20.2505999737, - 22.0953810747, - 24.1082173107, - 26.3044181014, - 28.7006875181, - 31.315251333, - 34.1679956422, - 37.2806181177, - 40.6767930374, - 44.3823513489, - 48.4254771375, - 52.8369219909, - 57.6502388927, - 62.902037423, - 68.6322622068, - 74.8844967285, - 81.7062948236, - 89.1495423679, - 97.2708519163, - 106.131993291, - 115.800363399, - 126.34949884, - 137.859635225, - 150.418317437, - 164.121065485, - 179.072101023, - 195.38514005, - 213.184257818, - 232.604832535, - 253.794575043, - 276.914652285, - 302.140913126, - 329.665225843, - 359.696937452, - 392.464465978, - 428.217037783, - 467.226583154, - 509.78980457, - 556.230433401, - 606.901692163, - 662.1889811, - 722.512809492, - 788.331994007, - 860.147148411, - 938.504491184, - 1024.0}; -const uint8_t grpc_stats_table_3[52] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52}; + 1, 1, 3, 3, 4, 6, 6, 8, 8, 9, 11, 11, 12, 14, 14, 15, 17, 17, + 18, 20, 20, 21, 23, 23, 24, 25, 27, 27, 28, 30, 30, 31, 33, 33, 34, 35, + 37, 37, 39, 39, 40, 41, 43, 43, 44, 46, 46, 47, 48, 50, 50, 51, 53, 53, + 55, 55, 56, 57, 59, 59, 60, 62, 62, 63, 64, 66, 66, 67, 69, 69, 71, 71, + 72, 73, 75, 75, 76, 78, 78, 79, 80, 82, 82, 83, 85, 85, 87}; +const int grpc_stats_table_2[64] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, + 15, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 49, + 54, 59, 64, 70, 76, 83, 90, 98, 106, 115, 125, 136, 147, + 159, 172, 186, 201, 218, 236, 255, 276, 299, 323, 349, 377, 408, + 441, 477, 515, 556, 601, 649, 701, 757, 817, 881, 950, 1024}; +const uint8_t grpc_stats_table_3[104] = { + 2, 2, 2, 6, 6, 6, 6, 9, 9, 9, 11, 11, 13, 13, 15, 15, 17, 17, + 20, 20, 20, 23, 23, 23, 25, 25, 26, 28, 28, 30, 30, 32, 32, 35, 35, 35, + 37, 37, 40, 40, 40, 41, 43, 43, 44, 46, 46, 48, 48, 50, 50, 52, 52, 55, + 55, 55, 57, 57, 58, 59, 61, 61, 63, 63, 65, 65, 67, 67, 69, 69, 71, 71, + 73, 73, 74, 76, 76, 77, 79, 79, 81, 81, 83, 83, 85, 85, 88, 88, 88, 89, + 90, 92, 92, 93, 95, 95, 97, 97, 99, 99, 101, 101, 104, 104}; 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}; -const double *const grpc_stats_histo_bucket_boundaries[6] = { +const int *const grpc_stats_histo_bucket_boundaries[6] = { grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0, grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0}; diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 4d1078dfdb..5350264c03 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -177,7 +177,7 @@ typedef enum { if (_val.uint < 4652218415073722368ull) { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ - grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 49)]); \ + grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 48)]); \ } else { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ @@ -249,7 +249,7 @@ typedef enum { if (_val.uint < 4652218415073722368ull) { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, \ - grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 49)]); \ + grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 48)]); \ } else { \ GRPC_STATS_INC_HISTOGRAM( \ (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, \ @@ -283,12 +283,12 @@ typedef enum { } \ } \ } while (false) -extern const double grpc_stats_table_0[64]; +extern const int grpc_stats_table_0[64]; extern const uint8_t grpc_stats_table_1[87]; -extern const double grpc_stats_table_2[64]; -extern const uint8_t grpc_stats_table_3[52]; +extern const int grpc_stats_table_2[64]; +extern const uint8_t grpc_stats_table_3[104]; extern const int grpc_stats_histo_buckets[6]; extern const int grpc_stats_histo_start[6]; -extern const double *const grpc_stats_histo_bucket_boundaries[6]; +extern const int *const grpc_stats_histo_bucket_boundaries[6]; #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 85489eb7dc..f33f07c4cf 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -109,16 +109,19 @@ def gen_bucket_code(histogram): first_nontrivial = None first_unmapped = None while len(bounds) < histogram.buckets: - mul = math.pow(float(histogram.max) / bounds[-1], - 1.0 / (histogram.buckets - len(bounds))) - nextb = bounds[-1] * mul - if nextb < bounds[-1] + 1: + if len(bounds) == histogram.buckets - 1: + nextb = int(histogram.max) + else: + mul = math.pow(float(histogram.max) / bounds[-1], + 1.0 / (histogram.buckets - len(bounds))) + nextb = int(math.ceil(bounds[-1] * mul)) + if nextb <= bounds[-1] + 1: nextb = bounds[-1] + 1 elif not done_trivial: done_trivial = True first_nontrivial = len(bounds) bounds.append(nextb) - bounds_idx = decl_static_table(bounds, 'double') + bounds_idx = decl_static_table(bounds, 'int') if done_trivial: first_nontrivial_code = dbl2u64(first_nontrivial) code_bounds = [dbl2u64(x) - first_nontrivial_code for x in bounds] @@ -226,7 +229,7 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "extern const int grpc_stats_histo_buckets[%d];" % len(inst_map['Histogram']) print >>H, "extern const int grpc_stats_histo_start[%d];" % len(inst_map['Histogram']) - print >>H, "extern const double *const grpc_stats_histo_bucket_boundaries[%d];" % len(inst_map['Histogram']) + print >>H, "extern const int *const grpc_stats_histo_bucket_boundaries[%d];" % len(inst_map['Histogram']) print >>H print >>H, "#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */" @@ -265,5 +268,5 @@ with open('src/core/lib/debug/stats_data.c', 'w') as C: len(inst_map['Histogram']), ','.join('%s' % x for x in histo_buckets)) print >>C, "const int grpc_stats_histo_start[%d] = {%s};" % ( len(inst_map['Histogram']), ','.join('%s' % x for x in histo_start)) - print >>C, "const double *const grpc_stats_histo_bucket_boundaries[%d] = {%s};" % ( + print >>C, "const int *const grpc_stats_histo_bucket_boundaries[%d] = {%s};" % ( len(inst_map['Histogram']), ','.join('grpc_stats_table_%d' % x for x in histo_bucket_boundaries)) -- cgit v1.2.3 From 97ec5eb61e9c2995387668c094d89389facb0878 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 1 Sep 2017 12:57:36 -0700 Subject: Add stats test --- CMakeLists.txt | 42 +++++++ Makefile | 48 ++++++++ build.yaml | 12 ++ src/core/lib/debug/stats_data.c | 75 ++++++++++++ src/core/lib/debug/stats_data.h | 88 ++------------ test/core/debug/stats_test.cc | 127 +++++++++++++++++++++ tools/codegen/core/gen_stats_data.py | 47 +++++--- tools/run_tests/generated/sources_and_headers.json | 18 +++ tools/run_tests/generated/tests.json | 22 ++++ 9 files changed, 386 insertions(+), 93 deletions(-) create mode 100644 test/core/debug/stats_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index efc33c0a6c..0567255dd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -756,6 +756,7 @@ endif() add_dependencies(buildtests_cxx server_crash_test_client) add_dependencies(buildtests_cxx server_request_call_test) add_dependencies(buildtests_cxx shutdown_test) +add_dependencies(buildtests_cxx stats_test) add_dependencies(buildtests_cxx status_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx streaming_throughput_test) @@ -12688,6 +12689,47 @@ target_link_libraries(shutdown_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(stats_test + test/core/debug/stats_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(stats_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${BENCHMARK_ROOT_DIR}/include + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CARES_BUILD_INCLUDE_DIR} + PRIVATE ${CARES_INCLUDE_DIR} + PRIVATE ${CARES_PLATFORM_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(stats_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc++_test_util + grpc_test_util + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(status_test test/cpp/util/status_test.cc third_party/googletest/googletest/src/gtest-all.cc diff --git a/Makefile b/Makefile index 4fd534df09..309ec18a47 100644 --- a/Makefile +++ b/Makefile @@ -1170,6 +1170,7 @@ server_crash_test: $(BINDIR)/$(CONFIG)/server_crash_test server_crash_test_client: $(BINDIR)/$(CONFIG)/server_crash_test_client server_request_call_test: $(BINDIR)/$(CONFIG)/server_request_call_test shutdown_test: $(BINDIR)/$(CONFIG)/shutdown_test +stats_test: $(BINDIR)/$(CONFIG)/stats_test status_test: $(BINDIR)/$(CONFIG)/status_test streaming_throughput_test: $(BINDIR)/$(CONFIG)/streaming_throughput_test stress_test: $(BINDIR)/$(CONFIG)/stress_test @@ -1600,6 +1601,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/server_crash_test_client \ $(BINDIR)/$(CONFIG)/server_request_call_test \ $(BINDIR)/$(CONFIG)/shutdown_test \ + $(BINDIR)/$(CONFIG)/stats_test \ $(BINDIR)/$(CONFIG)/status_test \ $(BINDIR)/$(CONFIG)/streaming_throughput_test \ $(BINDIR)/$(CONFIG)/stress_test \ @@ -1715,6 +1717,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/server_crash_test_client \ $(BINDIR)/$(CONFIG)/server_request_call_test \ $(BINDIR)/$(CONFIG)/shutdown_test \ + $(BINDIR)/$(CONFIG)/stats_test \ $(BINDIR)/$(CONFIG)/status_test \ $(BINDIR)/$(CONFIG)/streaming_throughput_test \ $(BINDIR)/$(CONFIG)/stress_test \ @@ -2114,6 +2117,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/server_request_call_test || ( echo test server_request_call_test failed ; exit 1 ) $(E) "[RUN] Testing shutdown_test" $(Q) $(BINDIR)/$(CONFIG)/shutdown_test || ( echo test shutdown_test failed ; exit 1 ) + $(E) "[RUN] Testing stats_test" + $(Q) $(BINDIR)/$(CONFIG)/stats_test || ( echo test stats_test failed ; exit 1 ) $(E) "[RUN] Testing status_test" $(Q) $(BINDIR)/$(CONFIG)/status_test || ( echo test status_test failed ; exit 1 ) $(E) "[RUN] Testing streaming_throughput_test" @@ -16631,6 +16636,49 @@ endif endif +STATS_TEST_SRC = \ + test/core/debug/stats_test.cc \ + +STATS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(STATS_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/stats_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/stats_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/stats_test: $(PROTOBUF_DEP) $(STATS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(STATS_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/stats_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/debug/stats_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_stats_test: $(STATS_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(STATS_TEST_OBJS:.o=.dep) +endif +endif + + STATUS_TEST_SRC = \ test/cpp/util/status_test.cc \ diff --git a/build.yaml b/build.yaml index a43ad6ae31..2b69888e06 100644 --- a/build.yaml +++ b/build.yaml @@ -4515,6 +4515,18 @@ targets: - grpc - gpr_test_util - gpr +- name: stats_test + gtest: true + build: test + language: c++ + src: + - test/core/debug/stats_test.cc + deps: + - grpc++_test_util + - grpc_test_util + - grpc + - gpr_test_util + - gpr - name: status_test build: test language: c++ diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index 177234ab5b..0ba10e68e3 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -19,6 +19,8 @@ */ #include "src/core/lib/debug/stats_data.h" +#include "src/core/lib/debug/stats.h" +#include "src/core/lib/iomgr/exec_ctx.h" const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { "client_calls_created", "server_calls_created", "syscall_write", "syscall_read", "syscall_poll", "syscall_wait", @@ -165,7 +167,80 @@ const uint8_t grpc_stats_table_3[52] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52}; +void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, double value) { + union { + double dbl; + uint64_t uint; + } _val; + _val.dbl = value; + if (_val.dbl < 0) _val.dbl = 0; + if (_val.dbl < 5.000000) { + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, + (int)_val.dbl); + } else { + if (_val.uint < 4715268809856909312ull) { + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, + grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 4); + } else { + 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)); + } + } +} +void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, double value) { + union { + double dbl; + uint64_t uint; + } _val; + _val.dbl = value; + if (_val.dbl < 0) _val.dbl = 0; + if (_val.dbl < 12.000000) { + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, (int)_val.dbl); + } else { + if (_val.uint < 4652218415073722368ull) { + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, + grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 49)] + + 11); + } else { + 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)); + } + } +} +void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, double value) { + union { + double dbl; + uint64_t uint; + } _val; + _val.dbl = value; + if (_val.dbl < 0) _val.dbl = 0; + if (_val.dbl < 5.000000) { + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + (int)_val.dbl); + } else { + if (_val.uint < 4715268809856909312ull) { + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 4); + } else { + 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)); + } + } +} const int grpc_stats_histo_buckets[3] = {64, 64, 64}; const int grpc_stats_histo_start[3] = {0, 64, 128}; const double *const grpc_stats_histo_bucket_boundaries[3] = { grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0}; +void (*const grpc_stats_inc_histogram[3])(grpc_exec_ctx *exec_ctx, double x) = { + grpc_stats_inc_tcp_write_size, grpc_stats_inc_tcp_write_iov_size, + grpc_stats_inc_tcp_read_size}; diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 9a4ba68655..4fff769450 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -22,6 +22,7 @@ #define GRPC_CORE_LIB_DEBUG_STATS_DATA_H #include +#include "src/core/lib/iomgr/exec_ctx.h" typedef enum { GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED, @@ -64,84 +65,19 @@ typedef enum { GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_SYSCALL_WAIT) #define GRPC_STATS_INC_HISTOGRAM_SLOW_LOOKUPS(exec_ctx) \ GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_HISTOGRAM_SLOW_LOOKUPS) -#define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \ - do { \ - union { \ - double dbl; \ - uint64_t uint; \ - } _val; \ - _val.dbl = (double)(value); \ - if (_val.dbl < 0) _val.dbl = 0; \ - if (_val.dbl < 5.000000) { \ - GRPC_STATS_INC_HISTOGRAM( \ - (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, (int)_val.dbl); \ - } else { \ - if (_val.uint < 4715268809856909312ull) { \ - GRPC_STATS_INC_HISTOGRAM( \ - (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, \ - grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)]); \ - } else { \ - 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)); \ - } \ - } \ - } while (false) -#define GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, value) \ - do { \ - union { \ - double dbl; \ - uint64_t uint; \ - } _val; \ - _val.dbl = (double)(value); \ - if (_val.dbl < 0) _val.dbl = 0; \ - if (_val.dbl < 12.000000) { \ - GRPC_STATS_INC_HISTOGRAM( \ - (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, (int)_val.dbl); \ - } else { \ - if (_val.uint < 4652218415073722368ull) { \ - GRPC_STATS_INC_HISTOGRAM( \ - (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, \ - grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 49)]); \ - } else { \ - 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)); \ - } \ - } \ - } while (false) -#define GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, value) \ - do { \ - union { \ - double dbl; \ - uint64_t uint; \ - } _val; \ - _val.dbl = (double)(value); \ - if (_val.dbl < 0) _val.dbl = 0; \ - if (_val.dbl < 5.000000) { \ - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, \ - (int)_val.dbl); \ - } else { \ - if (_val.uint < 4715268809856909312ull) { \ - GRPC_STATS_INC_HISTOGRAM( \ - (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, \ - grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)]); \ - } else { \ - 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)); \ - } \ - } \ - } while (false) -extern const double grpc_stats_table_0[64]; -extern const uint8_t grpc_stats_table_1[87]; -extern const double grpc_stats_table_2[64]; -extern const uint8_t grpc_stats_table_3[52]; +#define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \ + grpc_stats_inc_tcp_write_size((exec_ctx), (double)(value)) +void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, double x); +#define GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, value) \ + grpc_stats_inc_tcp_write_iov_size((exec_ctx), (double)(value)) +void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, double x); +#define GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, value) \ + grpc_stats_inc_tcp_read_size((exec_ctx), (double)(value)) +void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, double x); extern const int grpc_stats_histo_buckets[3]; extern const int grpc_stats_histo_start[3]; extern const double *const grpc_stats_histo_bucket_boundaries[3]; +extern void (*const grpc_stats_inc_histogram[3])(grpc_exec_ctx *exec_ctx, + double x); #endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */ diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc new file mode 100644 index 0000000000..65ccc7a5c8 --- /dev/null +++ b/test/core/debug/stats_test.cc @@ -0,0 +1,127 @@ +/* + * + * Copyright 2017 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +extern "C" { +#include "src/core/lib/debug/stats.h" +} + +#include +#include +#include + +namespace grpc { +namespace testing { + +class Snapshot { + public: + Snapshot() { grpc_stats_collect(&begin_); } + + grpc_stats_data delta() { + grpc_stats_data now; + grpc_stats_collect(&now); + grpc_stats_data delta; + grpc_stats_diff(&now, &begin_, &delta); + return delta; + } + + private: + grpc_stats_data begin_; +}; + +TEST(StatsTest, IncCounters) { + for (int i = 0; i < GRPC_STATS_COUNTER_COUNT; i++) { + Snapshot snapshot; + + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_STATS_INC_COUNTER(&exec_ctx, (grpc_stats_counters)i); + grpc_exec_ctx_finish(&exec_ctx); + + EXPECT_EQ(snapshot.delta().counters[i], 1); + } +} + +TEST(StatsTest, IncSpecificCounter) { + Snapshot snapshot; + + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_STATS_INC_SYSCALL_POLL(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); + + EXPECT_EQ(snapshot.delta().counters[GRPC_STATS_COUNTER_SYSCALL_POLL], 1); +} + +static int FindExpectedBucket(int i, int j) { + if (j < 0) { + return 0; + } + if (j >= + grpc_stats_histo_bucket_boundaries[i][grpc_stats_histo_buckets[i] - 1]) { + return grpc_stats_histo_buckets[i] - 1; + } + int r = 0; + while (grpc_stats_histo_bucket_boundaries[i][r + 1] <= j) r++; + return r; +} + +static int FindNonZeroBucket(const grpc_stats_data& data, int i) { + for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) { + if (data.histograms[grpc_stats_histo_start[i] + j] != 0) { + return j; + } + } + return -1; +} + +TEST(StatsTest, IncHistogram) { + for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { + for (int j = -1000; + j < + grpc_stats_histo_bucket_boundaries[i] + [grpc_stats_histo_buckets[i] - 1] + + 1000; + j++) { + gpr_log(GPR_DEBUG, "histo:%d value:%d", i, j); + + Snapshot snapshot; + + int expected_bucket = FindExpectedBucket(i, j); + + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_stats_inc_histogram[i](&exec_ctx, j); + grpc_exec_ctx_finish(&exec_ctx); + + auto delta = snapshot.delta(); + int got_bucket = FindNonZeroBucket(delta, i); + + EXPECT_EQ(expected_bucket, got_bucket); + EXPECT_EQ(delta.histograms[grpc_stats_histo_start[i] + expected_bucket], + 1); + } + } +} + +} // namespace testing +} // namespace grpc + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; +} diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 85489eb7dc..8ae8f6b831 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -125,32 +125,30 @@ def gen_bucket_code(histogram): shift_data = find_ideal_shift(code_bounds[first_nontrivial:], 256 * histogram.buckets) print first_nontrivial, shift_data, bounds if shift_data is not None: print [hex(x >> shift_data[0]) for x in code_bounds[first_nontrivial:]] - code = 'do {\\\n' - code += ' union { double dbl; uint64_t uint; } _val;\\\n' - code += '_val.dbl = (double)(value);\\\n' - code += 'if (_val.dbl < 0) _val.dbl = 0;\\\n' + code = ' union { double dbl; uint64_t uint; } _val;\n' + code += '_val.dbl = value;\n' + code += 'if (_val.dbl < 0) _val.dbl = 0;\n' map_table = gen_map_table(code_bounds[first_nontrivial:], shift_data) if first_nontrivial is None: - code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_val.dbl);\\\n' + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_val.dbl);\n' % histogram.name.upper()) else: - code += 'if (_val.dbl < %f) {\\\n' % first_nontrivial - code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_val.dbl);\\\n' + code += 'if (_val.dbl < %f) {\n' % first_nontrivial + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_val.dbl);\n' % histogram.name.upper()) code += '} else {' first_nontrivial_code = dbl2u64(first_nontrivial) if shift_data is not None: map_table_idx = decl_static_table(map_table, type_for_uint_table(map_table)) - code += 'if (_val.uint < %dull) {\\\n' % ((map_table[-1] << shift_data[0]) + first_nontrivial_code) + code += 'if (_val.uint < %dull) {\n' % ((map_table[-1] << shift_data[0]) + first_nontrivial_code) code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, ' % histogram.name.upper() - code += 'grpc_stats_table_%d[((_val.uint - %dull) >> %d)]);\\\n' % (map_table_idx, first_nontrivial_code, shift_data[0]) - code += '} else {\\\n' + code += 'grpc_stats_table_%d[((_val.uint - %dull) >> %d)] + %d);\n' % (map_table_idx, first_nontrivial_code, shift_data[0], first_nontrivial-1) + code += '} else {\n' code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() - code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, grpc_stats_table_%d, %d));\\\n' % (bounds_idx, len(bounds)) + code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, grpc_stats_table_%d, %d));\n' % (bounds_idx, len(bounds)) if shift_data is not None: code += '}' code += '}' - code += '} while (false)' return (code, bounds_idx) # utility: print a big comment block into a set of files @@ -184,6 +182,7 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "#define GRPC_CORE_LIB_DEBUG_STATS_DATA_H" print >>H print >>H, "#include " + print >>H, "#include \"src/core/lib/iomgr/exec_ctx.h\"" print >>H for typename, instances in sorted(inst_map.items()): @@ -215,11 +214,9 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: "GRPC_STATS_INC_COUNTER((exec_ctx), GRPC_STATS_COUNTER_%s)") % ( ctr.name.upper(), ctr.name.upper()) for histogram in inst_map['Histogram']: - code, bounds_idx = gen_bucket_code(histogram) - histo_bucket_boundaries.append(bounds_idx) - print >>H, ("#define GRPC_STATS_INC_%s(exec_ctx, value) %s") % ( - histogram.name.upper(), - code) + print >>H, "#define GRPC_STATS_INC_%s(exec_ctx, value) grpc_stats_inc_%s((exec_ctx), (double)(value))" % ( + histogram.name.upper(), histogram.name.lower()) + print >>H, "void grpc_stats_inc_%s(grpc_exec_ctx *exec_ctx, double x);" % histogram.name.lower() for i, tbl in enumerate(static_tables): print >>H, "extern const %s grpc_stats_table_%d[%d];" % (tbl[0], i, len(tbl[1])) @@ -227,6 +224,7 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "extern const int grpc_stats_histo_buckets[%d];" % len(inst_map['Histogram']) print >>H, "extern const int grpc_stats_histo_start[%d];" % len(inst_map['Histogram']) print >>H, "extern const double *const grpc_stats_histo_bucket_boundaries[%d];" % len(inst_map['Histogram']) + print >>H, "extern void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, double x);" % len(inst_map['Histogram']) print >>H print >>H, "#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */" @@ -250,6 +248,14 @@ with open('src/core/lib/debug/stats_data.c', 'w') as C: put_banner([C], ["Automatically generated by tools/codegen/core/gen_stats_data.py"]) print >>C, "#include \"src/core/lib/debug/stats_data.h\"" + print >>C, "#include \"src/core/lib/debug/stats.h\"" + print >>C, "#include \"src/core/lib/iomgr/exec_ctx.h\"" + + histo_code = [] + for histogram in inst_map['Histogram']: + code, bounds_idx = gen_bucket_code(histogram) + histo_bucket_boundaries.append(bounds_idx) + histo_code.append(code) for typename, instances in sorted(inst_map.items()): print >>C, "const char *grpc_stats_%s_name[GRPC_STATS_%s_COUNT] = {" % ( @@ -261,9 +267,16 @@ with open('src/core/lib/debug/stats_data.c', 'w') as C: print >>C, "const %s grpc_stats_table_%d[%d] = {%s};" % ( tbl[0], i, len(tbl[1]), ','.join('%s' % x for x in tbl[1])) + for histogram, code in zip(inst_map['Histogram'], histo_code): + print >>C, ("void grpc_stats_inc_%s(grpc_exec_ctx *exec_ctx, double value) {%s}") % ( + histogram.name.lower(), + code) + print >>C, "const int grpc_stats_histo_buckets[%d] = {%s};" % ( len(inst_map['Histogram']), ','.join('%s' % x for x in histo_buckets)) print >>C, "const int grpc_stats_histo_start[%d] = {%s};" % ( len(inst_map['Histogram']), ','.join('%s' % x for x in histo_start)) print >>C, "const double *const grpc_stats_histo_bucket_boundaries[%d] = {%s};" % ( len(inst_map['Histogram']), ','.join('grpc_stats_table_%d' % x for x in histo_bucket_boundaries)) + print >>C, "void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, double x) = {%s};" % ( + len(inst_map['Histogram']), ','.join('grpc_stats_inc_%s' % histogram.name.lower() for histogram in inst_map['Histogram'])) diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 5ce25dc14a..7326f8cf72 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -4013,6 +4013,24 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc++_test_util", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "stats_test", + "src": [ + "test/core/debug/stats_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 4368a5768e..f77b45839e 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3931,6 +3931,28 @@ "windows" ] }, + { + "args": [], + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "stats_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, { "args": [], "ci_platforms": [ -- cgit v1.2.3 From 40bca8468e91e5e8a9df0b84b30458bf79a3acc3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 1 Sep 2017 16:35:08 -0700 Subject: Fix one rounding bug --- src/core/lib/debug/stats_data.c | 18 +++++++++--------- tools/codegen/core/gen_stats_data.py | 8 +++++--- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index 0ba10e68e3..eeb1f9460a 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -94,11 +94,11 @@ const double grpc_stats_table_0[64] = {0, 12956014.428, 16777216.0}; const uint8_t grpc_stats_table_1[87] = { - 0, 1, 3, 3, 4, 6, 6, 7, 9, 9, 10, 12, 12, 13, 15, 15, 16, 18, - 18, 19, 21, 21, 22, 24, 24, 25, 27, 27, 28, 30, 30, 31, 32, 34, 34, 36, - 36, 37, 39, 39, 40, 42, 42, 43, 44, 46, 46, 47, 49, 49, 51, 51, 52, 53, - 55, 55, 56, 58, 58, 59, 61, 61, 63, 63, 64, 65, 67, 67, 68, 70, 70, 71, - 73, 73, 75, 75, 76, 77, 79, 79, 80, 82, 82, 83, 85, 85, 87}; + 0, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, 11, 12, + 12, 13, 14, 14, 15, 16, 16, 17, 18, 18, 19, 20, 20, 21, 22, 23, 23, 24, + 24, 25, 26, 26, 27, 28, 28, 29, 30, 31, 31, 32, 33, 33, 34, 34, 35, 36, + 37, 37, 38, 39, 39, 40, 41, 41, 42, 42, 43, 44, 45, 45, 46, 47, 47, 48, + 49, 49, 50, 50, 51, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58}; const double grpc_stats_table_2[64] = {0, 1, 2, @@ -166,7 +166,7 @@ const double grpc_stats_table_2[64] = {0, const uint8_t grpc_stats_table_3[52] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, - 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52}; + 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51}; void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, double value) { union { double dbl; @@ -178,7 +178,7 @@ void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, double value) { GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, (int)_val.dbl); } else { - if (_val.uint < 4715268809856909312ull) { + 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); @@ -201,7 +201,7 @@ void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, double value) { GRPC_STATS_INC_HISTOGRAM( (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, (int)_val.dbl); } else { - if (_val.uint < 4652218415073722368ull) { + if (_val.uint < 4651655465120301056ull) { GRPC_STATS_INC_HISTOGRAM( (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 49)] + @@ -225,7 +225,7 @@ void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, double value) { GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, (int)_val.dbl); } else { - if (_val.uint < 4715268809856909312ull) { + 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); diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 8ae8f6b831..36f2ec2c3e 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -72,11 +72,13 @@ def find_ideal_shift(mapped_bounds, max_size): def gen_map_table(mapped_bounds, shift_data): tbl = [] cur = 0 + print mapped_bounds mapped_bounds = [x >> shift_data[0] for x in mapped_bounds] + print mapped_bounds for i in range(0, mapped_bounds[shift_data[1]-1]): while i > mapped_bounds[cur]: cur += 1 - tbl.append(mapped_bounds[cur]) + tbl.append(cur) return tbl static_tables = [] @@ -123,8 +125,8 @@ def gen_bucket_code(histogram): first_nontrivial_code = dbl2u64(first_nontrivial) code_bounds = [dbl2u64(x) - first_nontrivial_code for x in bounds] shift_data = find_ideal_shift(code_bounds[first_nontrivial:], 256 * histogram.buckets) - print first_nontrivial, shift_data, bounds - if shift_data is not None: print [hex(x >> shift_data[0]) for x in code_bounds[first_nontrivial:]] + #print first_nontrivial, shift_data, bounds + #if shift_data is not None: print [hex(x >> shift_data[0]) for x in code_bounds[first_nontrivial:]] code = ' union { double dbl; uint64_t uint; } _val;\n' code += '_val.dbl = value;\n' code += 'if (_val.dbl < 0) _val.dbl = 0;\n' -- cgit v1.2.3 From e4605634a70fa67afaa593b1aa0465c5cf19c361 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 1 Sep 2017 16:45:36 -0700 Subject: Cleanup intification --- src/core/lib/debug/stats_data.c | 191 +++++++++++++++++------------------ src/core/lib/debug/stats_data.h | 1 - tools/codegen/core/gen_stats_data.py | 27 +++-- 3 files changed, 105 insertions(+), 114 deletions(-) diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index 8ebfb23283..4829f78579 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -19,6 +19,7 @@ */ #include "src/core/lib/debug/stats_data.h" +#include #include "src/core/lib/debug/stats.h" #include "src/core/lib/iomgr/exec_ctx.h" const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = { @@ -80,154 +81,146 @@ const uint8_t grpc_stats_table_3[104] = { 24, 24, 25, 25, 26, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, 36, 36, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 42, 43, 44, 45, 45, 46, 47, 47, 48, 48, 49, 49, 50, 50, 51, 51}; -void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, double value) { +void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int value) { + value = GPR_CLAMP(value, 0, 16777216); + if (value < 5) { + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, + value); + return; + } union { double dbl; uint64_t uint; } _val; _val.dbl = value; - if (_val.dbl < 0) _val.dbl = 0; - if (_val.dbl < 5.000000) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, - (int)_val.dbl); - } else { - 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); - } else { - 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)); - } + 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); + 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)); } -void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, double value) { +void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, int value) { + value = GPR_CLAMP(value, 0, 1024); + if (value < 12) { + GRPC_STATS_INC_HISTOGRAM((exec_ctx), + GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, value); + return; + } union { double dbl; uint64_t uint; } _val; _val.dbl = value; - if (_val.dbl < 0) _val.dbl = 0; - if (_val.dbl < 12.000000) { + if (_val.uint < 4637300241308057600ull) { GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, (int)_val.dbl); - } else { - 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); - } else { - 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), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, + grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 48)] + 11); + 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)); } -void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, double value) { +void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, int value) { + value = GPR_CLAMP(value, 0, 16777216); + if (value < 5) { + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, + value); + return; + } union { double dbl; uint64_t uint; } _val; _val.dbl = value; - if (_val.dbl < 0) _val.dbl = 0; - if (_val.dbl < 5.000000) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, - (int)_val.dbl); - } else { - 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); - } else { - 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)); - } + 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); + 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)); } -void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx *exec_ctx, double value) { +void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx *exec_ctx, int value) { + value = GPR_CLAMP(value, 0, 16777216); + if (value < 5) { + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, + value); + return; + } union { double dbl; uint64_t uint; } _val; _val.dbl = value; - if (_val.dbl < 0) _val.dbl = 0; - if (_val.dbl < 5.000000) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, - (int)_val.dbl); - } else { - 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); - } else { - 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)); - } + 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); + 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)); } -void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, double value) { +void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, int value) { + value = GPR_CLAMP(value, 0, 1024); + if (value < 12) { + GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, + value); + return; + } union { double dbl; uint64_t uint; } _val; _val.dbl = value; - if (_val.dbl < 0) _val.dbl = 0; - if (_val.dbl < 12.000000) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, - (int)_val.dbl); - } else { - 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); - } else { - 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)); - } + 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); + 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)); } void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, - double value) { + int value) { + value = GPR_CLAMP(value, 0, 16777216); + if (value < 5) { + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, value); + return; + } union { double dbl; uint64_t uint; } _val; _val.dbl = value; - if (_val.dbl < 0) _val.dbl = 0; - if (_val.dbl < 5.000000) { - GRPC_STATS_INC_HISTOGRAM((exec_ctx), - GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, - (int)_val.dbl); - } else { - if (_val.uint < 4682617712558473216ull) { - GRPC_STATS_INC_HISTOGRAM( - (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, - grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 4); - } else { - 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)); - } + if (_val.uint < 4682617712558473216ull) { + GRPC_STATS_INC_HISTOGRAM( + (exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, + grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 4); + 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)); } 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}; const int *const grpc_stats_histo_bucket_boundaries[6] = { grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0, grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_0}; -void (*const grpc_stats_inc_histogram[6])(grpc_exec_ctx *exec_ctx, double x) = { +void (*const grpc_stats_inc_histogram[6])(grpc_exec_ctx *exec_ctx, int x) = { grpc_stats_inc_tcp_write_size, grpc_stats_inc_tcp_write_iov_size, grpc_stats_inc_tcp_read_size, grpc_stats_inc_tcp_read_offer, grpc_stats_inc_tcp_read_iov_size, grpc_stats_inc_http2_send_message_size}; diff --git a/src/core/lib/debug/stats_data.h b/src/core/lib/debug/stats_data.h index 13bf9d0c8e..9b2d43a03c 100644 --- a/src/core/lib/debug/stats_data.h +++ b/src/core/lib/debug/stats_data.h @@ -160,7 +160,6 @@ void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, int x); extern const int grpc_stats_histo_buckets[6]; extern const int grpc_stats_histo_start[6]; extern const int *const grpc_stats_histo_bucket_boundaries[6]; -extern const double *const grpc_stats_histo_bucket_boundaries[6]; extern void (*const grpc_stats_inc_histogram[6])(grpc_exec_ctx *exec_ctx, int x); diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 857c99da8d..a15745cf84 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -130,30 +130,29 @@ def gen_bucket_code(histogram): shift_data = find_ideal_shift(code_bounds[first_nontrivial:], 256 * histogram.buckets) #print first_nontrivial, shift_data, bounds #if shift_data is not None: print [hex(x >> shift_data[0]) for x in code_bounds[first_nontrivial:]] - code = ' union { double dbl; uint64_t uint; } _val;\n' - code += '_val.dbl = value;\n' - code += 'if (_val.dbl < 0) _val.dbl = 0;\n' + code = 'value = GPR_CLAMP(value, 0, %d);\n' % histogram.max map_table = gen_map_table(code_bounds[first_nontrivial:], shift_data) if first_nontrivial is None: - code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_val.dbl);\n' + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, value);\n' % histogram.name.upper()) else: - code += 'if (_val.dbl < %f) {\n' % first_nontrivial - code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, (int)_val.dbl);\n' + code += 'if (value < %d) {\n' % first_nontrivial + code += ('GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, value);\n' % histogram.name.upper()) - code += '} else {' + code += 'return;\n' + code += '}' first_nontrivial_code = dbl2u64(first_nontrivial) if shift_data is not None: map_table_idx = decl_static_table(map_table, type_for_uint_table(map_table)) + code += 'union { double dbl; uint64_t uint; } _val;\n' + code += '_val.dbl = value;\n' code += 'if (_val.uint < %dull) {\n' % ((map_table[-1] << shift_data[0]) + first_nontrivial_code) code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, ' % histogram.name.upper() code += 'grpc_stats_table_%d[((_val.uint - %dull) >> %d)] + %d);\n' % (map_table_idx, first_nontrivial_code, shift_data[0], first_nontrivial-1) - code += '} else {\n' + code += 'return;\n' + code += '}\n' code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, grpc_stats_table_%d, %d));\n' % (bounds_idx, len(bounds)) - if shift_data is not None: - code += '}' - code += '}' return (code, bounds_idx) # utility: print a big comment block into a set of files @@ -229,7 +228,6 @@ with open('src/core/lib/debug/stats_data.h', 'w') as H: print >>H, "extern const int grpc_stats_histo_buckets[%d];" % len(inst_map['Histogram']) print >>H, "extern const int grpc_stats_histo_start[%d];" % len(inst_map['Histogram']) print >>H, "extern const int *const grpc_stats_histo_bucket_boundaries[%d];" % len(inst_map['Histogram']) - print >>H, "extern const double *const grpc_stats_histo_bucket_boundaries[%d];" % len(inst_map['Histogram']) print >>H, "extern void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, int x);" % len(inst_map['Histogram']) print >>H @@ -256,6 +254,7 @@ with open('src/core/lib/debug/stats_data.c', 'w') as C: print >>C, "#include \"src/core/lib/debug/stats_data.h\"" print >>C, "#include \"src/core/lib/debug/stats.h\"" print >>C, "#include \"src/core/lib/iomgr/exec_ctx.h\"" + print >>C, "#include " histo_code = [] for histogram in inst_map['Histogram']: @@ -274,7 +273,7 @@ with open('src/core/lib/debug/stats_data.c', 'w') as C: tbl[0], i, len(tbl[1]), ','.join('%s' % x for x in tbl[1])) for histogram, code in zip(inst_map['Histogram'], histo_code): - print >>C, ("void grpc_stats_inc_%s(grpc_exec_ctx *exec_ctx, double value) {%s}") % ( + print >>C, ("void grpc_stats_inc_%s(grpc_exec_ctx *exec_ctx, int value) {%s}") % ( histogram.name.lower(), code) @@ -284,5 +283,5 @@ with open('src/core/lib/debug/stats_data.c', 'w') as C: len(inst_map['Histogram']), ','.join('%s' % x for x in histo_start)) print >>C, "const int *const grpc_stats_histo_bucket_boundaries[%d] = {%s};" % ( len(inst_map['Histogram']), ','.join('grpc_stats_table_%d' % x for x in histo_bucket_boundaries)) - print >>C, "void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, double x) = {%s};" % ( + print >>C, "void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, int x) = {%s};" % ( len(inst_map['Histogram']), ','.join('grpc_stats_inc_%s' % histogram.name.lower() for histogram in inst_map['Histogram'])) -- cgit v1.2.3 From cd0a91e4e1ff40c66a8dd7b56a861203508112c6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Sat, 2 Sep 2017 17:58:22 -0700 Subject: Fix some rounding bugs --- src/core/lib/debug/stats.c | 23 +++++------ src/core/lib/debug/stats.h | 2 +- src/core/lib/debug/stats_data.c | 76 ++++++++++++++++++++++-------------- tools/codegen/core/gen_stats_data.py | 11 ++++-- 4 files changed, 65 insertions(+), 47 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}; diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index a15745cf84..104ac83f17 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -144,15 +144,18 @@ def gen_bucket_code(histogram): first_nontrivial_code = dbl2u64(first_nontrivial) if shift_data is not None: map_table_idx = decl_static_table(map_table, type_for_uint_table(map_table)) - code += 'union { double dbl; uint64_t uint; } _val;\n' + code += 'union { double dbl; uint64_t uint; } _val, _bkt;\n' code += '_val.dbl = value;\n' code += 'if (_val.uint < %dull) {\n' % ((map_table[-1] << shift_data[0]) + first_nontrivial_code) - code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, ' % histogram.name.upper() - code += 'grpc_stats_table_%d[((_val.uint - %dull) >> %d)] + %d);\n' % (map_table_idx, first_nontrivial_code, shift_data[0], first_nontrivial-1) + code += 'int bucket = ' + code += 'grpc_stats_table_%d[((_val.uint - %dull) >> %d)] + %d;\n' % (map_table_idx, first_nontrivial_code, shift_data[0], first_nontrivial) + code += '_bkt.dbl = grpc_stats_table_%d[bucket];\n' % bounds_idx + code += 'bucket -= (_val.uint < _bkt.uint);\n' + code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, bucket);\n' % histogram.name.upper() code += 'return;\n' code += '}\n' code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() - code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, grpc_stats_table_%d, %d));\n' % (bounds_idx, len(bounds)) + code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), value, grpc_stats_table_%d, %d));\n' % (bounds_idx, len(bounds)) return (code, bounds_idx) # utility: print a big comment block into a set of files -- cgit v1.2.3 From c75f9868c3be5680eb33e1a6f1b8be7b9723a874 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 5 Sep 2017 11:34:57 -0700 Subject: Fix benchmark builds --- CMakeLists.txt | 3 +++ Makefile | 18 +++++++++--------- build.yaml | 3 +++ tools/run_tests/generated/sources_and_headers.json | 3 +++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0deab9907c..34c2a91613 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12156,6 +12156,7 @@ target_link_libraries(qps_openloop_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} qps + grpc++_core_stats grpc++_test_util grpc_test_util grpc++ @@ -12201,6 +12202,7 @@ target_link_libraries(qps_worker ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} qps + grpc++_core_stats grpc++_test_util grpc_test_util grpc++ @@ -12418,6 +12420,7 @@ target_link_libraries(secure_sync_unary_ping_pong_test ${_gRPC_PROTOBUF_LIBRARIES} ${_gRPC_ALLTARGETS_LIBRARIES} qps + grpc++_core_stats grpc++_test_util grpc_test_util grpc++ diff --git a/Makefile b/Makefile index 8639c3194b..842df13db0 100644 --- a/Makefile +++ b/Makefile @@ -16134,16 +16134,16 @@ $(BINDIR)/$(CONFIG)/qps_openloop_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/qps_openloop_test: $(PROTOBUF_DEP) $(QPS_OPENLOOP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(BINDIR)/$(CONFIG)/qps_openloop_test: $(PROTOBUF_DEP) $(QPS_OPENLOOP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(QPS_OPENLOOP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_openloop_test + $(Q) $(LDXX) $(LDFLAGS) $(QPS_OPENLOOP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_openloop_test endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_openloop_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_openloop_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a deps_qps_openloop_test: $(QPS_OPENLOOP_TEST_OBJS:.o=.dep) @@ -16177,16 +16177,16 @@ $(BINDIR)/$(CONFIG)/qps_worker: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/qps_worker: $(PROTOBUF_DEP) $(QPS_WORKER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(BINDIR)/$(CONFIG)/qps_worker: $(PROTOBUF_DEP) $(QPS_WORKER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(QPS_WORKER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_worker + $(Q) $(LDXX) $(LDFLAGS) $(QPS_WORKER_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/qps_worker endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/worker.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/worker.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a deps_qps_worker: $(QPS_WORKER_OBJS:.o=.dep) @@ -16369,16 +16369,16 @@ $(BINDIR)/$(CONFIG)/secure_sync_unary_ping_pong_test: protobuf_dep_error else -$(BINDIR)/$(CONFIG)/secure_sync_unary_ping_pong_test: $(PROTOBUF_DEP) $(SECURE_SYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(BINDIR)/$(CONFIG)/secure_sync_unary_ping_pong_test: $(PROTOBUF_DEP) $(SECURE_SYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(SECURE_SYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/secure_sync_unary_ping_pong_test + $(Q) $(LDXX) $(LDFLAGS) $(SECURE_SYNC_UNARY_PING_PONG_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/secure_sync_unary_ping_pong_test endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/qps/secure_sync_unary_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(OBJDIR)/$(CONFIG)/test/cpp/qps/secure_sync_unary_ping_pong_test.o: $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libgrpc++_core_stats.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a deps_secure_sync_unary_ping_pong_test: $(SECURE_SYNC_UNARY_PING_PONG_TEST_OBJS:.o=.dep) diff --git a/build.yaml b/build.yaml index 4539896e44..f0335ce17b 100644 --- a/build.yaml +++ b/build.yaml @@ -4332,6 +4332,7 @@ targets: - test/cpp/qps/qps_openloop_test.cc deps: - qps + - grpc++_core_stats - grpc++_test_util - grpc_test_util - grpc++ @@ -4354,6 +4355,7 @@ targets: - test/cpp/qps/worker.cc deps: - qps + - grpc++_core_stats - grpc++_test_util - grpc_test_util - grpc++ @@ -4417,6 +4419,7 @@ targets: - test/cpp/qps/secure_sync_unary_ping_pong_test.cc deps: - qps + - grpc++_core_stats - grpc++_test_util - grpc_test_util - grpc++ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 186f383f18..94ece67450 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3726,6 +3726,7 @@ "gpr_test_util", "grpc", "grpc++", + "grpc++_core_stats", "grpc++_test_config", "grpc++_test_util", "grpc_test_util", @@ -3747,6 +3748,7 @@ "gpr_test_util", "grpc", "grpc++", + "grpc++_core_stats", "grpc++_test_config", "grpc++_test_util", "grpc_test_util", @@ -3854,6 +3856,7 @@ "gpr_test_util", "grpc", "grpc++", + "grpc++_core_stats", "grpc++_test_config", "grpc++_test_util", "grpc_test_util", -- cgit v1.2.3 From 83db6312c60859002d4bb2c301f594fc65039ecf Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 5 Sep 2017 12:10:18 -0700 Subject: Optimize test --- test/core/debug/stats_test.cc | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index 65ccc7a5c8..82ed27cb13 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -73,30 +73,29 @@ static int FindExpectedBucket(int i, int j) { grpc_stats_histo_bucket_boundaries[i][grpc_stats_histo_buckets[i] - 1]) { return grpc_stats_histo_buckets[i] - 1; } - int r = 0; - while (grpc_stats_histo_bucket_boundaries[i][r + 1] <= j) r++; - return r; -} - -static int FindNonZeroBucket(const grpc_stats_data& data, int i) { - for (int j = 0; j < grpc_stats_histo_buckets[i]; j++) { - if (data.histograms[grpc_stats_histo_start[i] + j] != 0) { - return j; - } - } - return -1; + return std::upper_bound(grpc_stats_histo_bucket_boundaries[i], + grpc_stats_histo_bucket_boundaries[i] + + grpc_stats_histo_buckets[i], + j) - + grpc_stats_histo_bucket_boundaries[i] - 1; } TEST(StatsTest, IncHistogram) { for (int i = 0; i < GRPC_STATS_HISTOGRAM_COUNT; i++) { + std::vector test_values; for (int j = -1000; j < grpc_stats_histo_bucket_boundaries[i] [grpc_stats_histo_buckets[i] - 1] + 1000; j++) { - gpr_log(GPR_DEBUG, "histo:%d value:%d", i, j); - + test_values.push_back(j); + } + std::random_shuffle(test_values.begin(), test_values.end()); + if (test_values.size() > 10000) { + test_values.resize(10000); + } + for (auto j : test_values) { Snapshot snapshot; int expected_bucket = FindExpectedBucket(i, j); @@ -106,9 +105,7 @@ TEST(StatsTest, IncHistogram) { grpc_exec_ctx_finish(&exec_ctx); auto delta = snapshot.delta(); - int got_bucket = FindNonZeroBucket(delta, i); - EXPECT_EQ(expected_bucket, got_bucket); EXPECT_EQ(delta.histograms[grpc_stats_histo_start[i] + expected_bucket], 1); } -- cgit v1.2.3 From b6ab5f599ec691b33dce1ca6eb3892f7830d61da Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 5 Sep 2017 13:10:00 -0700 Subject: Mac compilation fixes --- src/core/lib/iomgr/tcp_posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/iomgr/tcp_posix.c b/src/core/lib/iomgr/tcp_posix.c index 793147f30a..98a2afd78b 100644 --- a/src/core/lib/iomgr/tcp_posix.c +++ b/src/core/lib/iomgr/tcp_posix.c @@ -250,7 +250,7 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_iov = iov; - msg.msg_iovlen = tcp->incoming_buffer->count; + msg.msg_iovlen = (msg_iovlen_type)tcp->incoming_buffer->count; msg.msg_control = NULL; msg.msg_controllen = 0; msg.msg_flags = 0; -- cgit v1.2.3 From 07530dbbeb25b89b9fbaaea2c9823d5ea157a038 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 5 Sep 2017 14:55:43 -0700 Subject: Fixup bounds --- src/core/lib/debug/stats_data.c | 87 ++++++++++++++++++------------------ tools/codegen/core/gen_stats_data.py | 6 +-- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index 57cbafc817..f889606de8 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -53,34 +53,35 @@ const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = { "tcp_write_size", "tcp_write_iov_size", "tcp_read_size", "tcp_read_offer", "tcp_read_iov_size", "http2_send_message_size", }; -const int grpc_stats_table_0[64] = { - 0, 1, 2, 3, 4, 6, 8, 11, - 15, 20, 26, 34, 44, 57, 74, 96, - 124, 160, 206, 265, 341, 439, 565, 727, - 935, 1202, 1546, 1988, 2556, 3286, 4225, 5432, - 6983, 8977, 11540, 14834, 19069, 24513, 31510, 40505, - 52067, 66929, 86033, 110590, 142157, 182734, 234893, 301940, - 388125, 498910, 641316, 824370, 1059674, 1362141, 1750943, 2250722, - 2893155, 3718960, 4780478, 6144988, 7898976, 10153611, 13051794, 16777216}; +const int grpc_stats_table_0[65] = { + 0, 1, 2, 3, 4, 6, 8, 11, + 15, 20, 26, 34, 44, 57, 73, 94, + 121, 155, 199, 255, 327, 419, 537, 688, + 881, 1128, 1444, 1848, 2365, 3026, 3872, 4954, + 6338, 8108, 10373, 13270, 16976, 21717, 27782, 35541, + 45467, 58165, 74409, 95189, 121772, 155778, 199281, 254933, + 326126, 417200, 533707, 682750, 873414, 1117323, 1429345, 1828502, + 2339127, 2992348, 3827987, 4896985, 6264509, 8013925, 10251880, 13114801, + 16777216}; const uint8_t grpc_stats_table_1[87] = { - 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 10, - 11, 12, 12, 13, 14, 14, 15, 16, 17, 17, 18, 19, 19, 20, 21, 21, 22, 23, - 24, 24, 25, 25, 26, 27, 28, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 35, - 36, 36, 37, 38, 39, 39, 40, 41, 41, 42, 43, 44, 44, 45, 46, 46, 47, 47, - 48, 49, 50, 50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 57, 58}; -const int grpc_stats_table_2[64] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, - 15, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 49, - 54, 59, 64, 70, 76, 83, 90, 98, 106, 115, 125, 136, 147, - 159, 172, 186, 201, 218, 236, 255, 276, 299, 323, 349, 377, 408, - 441, 477, 515, 556, 601, 649, 701, 757, 817, 881, 950, 1024}; -const uint8_t grpc_stats_table_3[104] = { - 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, - 7, 7, 7, 8, 8, 8, 9, 9, 10, 11, 11, 12, 12, 13, 13, 14, 14, 14, - 15, 15, 16, 16, 16, 17, 18, 18, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, - 24, 24, 25, 25, 26, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, - 34, 34, 35, 36, 36, 37, 38, 38, 39, 39, 40, 40, 41, 41, 42, 42, 42, 43, - 44, 45, 45, 46, 47, 47, 48, 48, 49, 49, 50, 50, 51, 51}; + 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, + 11, 12, 13, 13, 14, 15, 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 22, 23, + 24, 25, 25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, + 36, 37, 38, 39, 39, 40, 41, 41, 42, 43, 44, 44, 45, 45, 46, 47, 48, 48, + 49, 50, 51, 51, 52, 53, 53, 54, 55, 56, 56, 57, 58, 58, 59}; +const int grpc_stats_table_2[65] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 14, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39, 43, 47, + 51, 56, 61, 66, 72, 78, 85, 92, 100, 109, 118, 128, 139, + 151, 164, 178, 193, 209, 226, 244, 264, 285, 308, 333, 359, 387, + 418, 451, 486, 524, 565, 609, 656, 707, 762, 821, 884, 952, 1024}; +const uint8_t grpc_stats_table_3[102] = { + 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, + 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 11, 12, 12, 13, 13, 14, 14, + 14, 15, 15, 16, 16, 17, 17, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, + 23, 24, 24, 24, 25, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, + 32, 33, 33, 34, 35, 35, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41, 41, + 42, 42, 43, 44, 44, 45, 46, 46, 47, 48, 48, 49, 49, 50, 50, 51, 51}; void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int value) { value = GPR_CLAMP(value, 0, 16777216); if (value < 5) { @@ -93,7 +94,7 @@ void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int value) { uint64_t uint; } _val, _bkt; _val.dbl = value; - if (_val.uint < 4682617712558473216ull) { + if (_val.uint < 4683743612465315840ull) { int bucket = grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_0[bucket]; @@ -104,11 +105,11 @@ void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_0, 64)); + (exec_ctx), value, grpc_stats_table_0, 65)); } void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, int value) { value = GPR_CLAMP(value, 0, 1024); - if (value < 12) { + if (value < 13) { GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, value); return; @@ -118,9 +119,9 @@ void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, int value) { uint64_t uint; } _val, _bkt; _val.dbl = value; - if (_val.uint < 4637300241308057600ull) { + if (_val.uint < 4637863191261478912ull) { int bucket = - grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 48)] + 12; + grpc_stats_table_3[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _bkt.dbl = grpc_stats_table_2[bucket]; bucket -= (_val.uint < _bkt.uint); GRPC_STATS_INC_HISTOGRAM((exec_ctx), @@ -129,7 +130,7 @@ void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_2, 64)); + (exec_ctx), value, grpc_stats_table_2, 65)); } void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, int value) { value = GPR_CLAMP(value, 0, 16777216); @@ -143,7 +144,7 @@ void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, int value) { uint64_t uint; } _val, _bkt; _val.dbl = value; - if (_val.uint < 4682617712558473216ull) { + if (_val.uint < 4683743612465315840ull) { int bucket = grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_0[bucket]; @@ -154,7 +155,7 @@ void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_0, 64)); + (exec_ctx), value, grpc_stats_table_0, 65)); } void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx *exec_ctx, int value) { value = GPR_CLAMP(value, 0, 16777216); @@ -168,7 +169,7 @@ void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx *exec_ctx, int value) { uint64_t uint; } _val, _bkt; _val.dbl = value; - if (_val.uint < 4682617712558473216ull) { + if (_val.uint < 4683743612465315840ull) { int bucket = grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_0[bucket]; @@ -179,11 +180,11 @@ void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_0, 64)); + (exec_ctx), value, grpc_stats_table_0, 65)); } void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, int value) { value = GPR_CLAMP(value, 0, 1024); - if (value < 12) { + if (value < 13) { GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, value); return; @@ -193,9 +194,9 @@ void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, int value) { uint64_t uint; } _val, _bkt; _val.dbl = value; - if (_val.uint < 4637300241308057600ull) { + if (_val.uint < 4637863191261478912ull) { int bucket = - grpc_stats_table_3[((_val.uint - 4622945017495814144ull) >> 48)] + 12; + grpc_stats_table_3[((_val.uint - 4623507967449235456ull) >> 48)] + 13; _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, @@ -204,7 +205,7 @@ void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_2, 64)); + (exec_ctx), value, grpc_stats_table_2, 65)); } void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, int value) { @@ -219,7 +220,7 @@ void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, uint64_t uint; } _val, _bkt; _val.dbl = value; - if (_val.uint < 4682617712558473216ull) { + if (_val.uint < 4683743612465315840ull) { int bucket = grpc_stats_table_1[((_val.uint - 4617315517961601024ull) >> 50)] + 5; _bkt.dbl = grpc_stats_table_0[bucket]; @@ -231,7 +232,7 @@ void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_0, 64)); + (exec_ctx), value, grpc_stats_table_0, 65)); } 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}; diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 104ac83f17..60cbd6436f 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -110,12 +110,12 @@ def gen_bucket_code(histogram): done_unmapped = False first_nontrivial = None first_unmapped = None - while len(bounds) < histogram.buckets: - if len(bounds) == histogram.buckets - 1: + while len(bounds) < histogram.buckets + 1: + if len(bounds) == histogram.buckets: nextb = int(histogram.max) else: mul = math.pow(float(histogram.max) / bounds[-1], - 1.0 / (histogram.buckets - len(bounds))) + 1.0 / (histogram.buckets + 1 - len(bounds))) nextb = int(math.ceil(bounds[-1] * mul)) if nextb <= bounds[-1] + 1: nextb = bounds[-1] + 1 -- cgit v1.2.3 From 3e3dd080877be8951ce35f98711b3932291d04bb Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 5 Sep 2017 15:08:39 -0700 Subject: Bounds fixes --- src/core/lib/debug/stats_data.c | 12 ++++++------ test/core/debug/stats_test.cc | 2 +- tools/codegen/core/gen_stats_data.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core/lib/debug/stats_data.c b/src/core/lib/debug/stats_data.c index f889606de8..f4ac2ddbd2 100644 --- a/src/core/lib/debug/stats_data.c +++ b/src/core/lib/debug/stats_data.c @@ -105,7 +105,7 @@ void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_0, 65)); + (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); @@ -130,7 +130,7 @@ void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_WRITE_IOV_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_2, 65)); + (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); @@ -155,7 +155,7 @@ void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_0, 65)); + (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); @@ -180,7 +180,7 @@ void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_OFFER, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_0, 65)); + (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); @@ -205,7 +205,7 @@ void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, int value) { } GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_TCP_READ_IOV_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_2, 65)); + (exec_ctx), value, grpc_stats_table_2, 64)); } void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, int value) { @@ -232,7 +232,7 @@ void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_HTTP2_SEND_MESSAGE_SIZE, grpc_stats_histo_find_bucket_slow( - (exec_ctx), value, grpc_stats_table_0, 65)); + (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}; diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index 82ed27cb13..bda580f7ca 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -70,7 +70,7 @@ static int FindExpectedBucket(int i, int j) { return 0; } if (j >= - grpc_stats_histo_bucket_boundaries[i][grpc_stats_histo_buckets[i] - 1]) { + grpc_stats_histo_bucket_boundaries[i][grpc_stats_histo_buckets[i]]) { return grpc_stats_histo_buckets[i] - 1; } return std::upper_bound(grpc_stats_histo_bucket_boundaries[i], diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py index 60cbd6436f..df6cd5a6bd 100755 --- a/tools/codegen/core/gen_stats_data.py +++ b/tools/codegen/core/gen_stats_data.py @@ -155,7 +155,7 @@ def gen_bucket_code(histogram): code += 'return;\n' code += '}\n' code += 'GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_%s, '% histogram.name.upper() - code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), value, grpc_stats_table_%d, %d));\n' % (bounds_idx, len(bounds)) + code += 'grpc_stats_histo_find_bucket_slow((exec_ctx), value, grpc_stats_table_%d, %d));\n' % (bounds_idx, histogram.buckets) return (code, bounds_idx) # utility: print a big comment block into a set of files -- cgit v1.2.3 From f4e5802c2ea37ff20d38ff0565befde19db28f1e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 6 Sep 2017 09:09:27 -0700 Subject: Fix ASAN detected failure --- test/core/iomgr/fd_conservation_posix_test.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/core/iomgr/fd_conservation_posix_test.c b/test/core/iomgr/fd_conservation_posix_test.c index 3c61173ecd..d29b1e8e41 100644 --- a/test/core/iomgr/fd_conservation_posix_test.c +++ b/test/core/iomgr/fd_conservation_posix_test.c @@ -30,9 +30,8 @@ int main(int argc, char **argv) { grpc_endpoint_pair p; grpc_test_init(argc, argv); + grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_iomgr_init(&exec_ctx); - grpc_iomgr_start(&exec_ctx); /* set max # of file descriptors to a low value, and verify we can create and destroy many more than this number @@ -51,7 +50,7 @@ int main(int argc, char **argv) { grpc_resource_quota_unref(resource_quota); - grpc_iomgr_shutdown(&exec_ctx); grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); return 0; } -- cgit v1.2.3 From e1101cf09925d23b491c895e2bcf4bae01857504 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 6 Sep 2017 09:42:20 -0700 Subject: Update Bazel for new systems --- BUILD | 15 +++++++++++++++ src/proto/grpc/core/BUILD | 24 ++++++++++++++++++++++++ src/proto/grpc/testing/BUILD | 3 +++ test/cpp/qps/BUILD | 1 + 4 files changed, 43 insertions(+) create mode 100644 src/proto/grpc/core/BUILD diff --git a/BUILD b/BUILD index 67e727bd52..76dbeb2ca8 100644 --- a/BUILD +++ b/BUILD @@ -1601,4 +1601,19 @@ grpc_cc_library( ], ) +grpc_cc_library( + name = "grpc++_core_stats", + srcs = [ + "src/cpp/util/core_stats.cc", + ], + hdrs = [ + "src/cpp/util/core_stats.h", + ], + language = "c++", + deps = [ + ":grpc++", + "//src/proto/grpc/core:stats_proto", + ], +) + grpc_generate_one_off_targets() diff --git a/src/proto/grpc/core/BUILD b/src/proto/grpc/core/BUILD new file mode 100644 index 0000000000..46de9fae18 --- /dev/null +++ b/src/proto/grpc/core/BUILD @@ -0,0 +1,24 @@ +# Copyright 2017 gRPC authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +licenses(["notice"]) # Apache v2 + +load("//bazel:grpc_build_system.bzl", "grpc_proto_library", "grpc_package") + +grpc_package(name = "core", visibility = "public") + +grpc_proto_library( + name = "stats_proto", + srcs = ["stats.proto"], +) diff --git a/src/proto/grpc/testing/BUILD b/src/proto/grpc/testing/BUILD index 07e08117f0..36d3782262 100644 --- a/src/proto/grpc/testing/BUILD +++ b/src/proto/grpc/testing/BUILD @@ -84,6 +84,9 @@ grpc_proto_library( name = "stats_proto", srcs = ["stats.proto"], has_services = False, + deps = [ + "//src/proto/grpc/core:stats_proto", + ] ) grpc_proto_library( diff --git a/test/cpp/qps/BUILD b/test/cpp/qps/BUILD index 31f210dec0..3352269517 100644 --- a/test/cpp/qps/BUILD +++ b/test/cpp/qps/BUILD @@ -46,6 +46,7 @@ grpc_cc_library( ":usage_timer", "//:grpc", "//:grpc++", + "//:grpc++_core_stats", "//src/proto/grpc/testing:control_proto", "//src/proto/grpc/testing:payloads_proto", "//src/proto/grpc/testing:services_proto", -- cgit v1.2.3 From 6869da4d658bf3e6631a8773e4b8ae315fcfec0e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 6 Sep 2017 09:22:39 -0700 Subject: Annotate benign race --- include/grpc/impl/codegen/port_platform.h | 6 ++++++ test/cpp/microbenchmarks/bm_fullstack_trickle.cc | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index e84a75d295..5bbab70c6a 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -409,4 +409,10 @@ typedef unsigned __int64 uint64_t; #define CENSUSAPI GRPCAPI #endif +#if defined(__has_feature) +#if __has_feature(thread_sanitizer) +#define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread"))) +#endif +#endif + #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */ diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 135b4710ce..37dd08c33d 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -105,7 +105,7 @@ class TrickledCHTTP2 : public EndpointPairFixture { (double)state.iterations()); } - void Log(int64_t iteration) { + void Log(int64_t iteration) GPR_ATTRIBUTE_NO_TSAN { auto now = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), start_); grpc_chttp2_transport* client = reinterpret_cast(client_transport_); -- cgit v1.2.3 From c1453ca8c24ca6e42c6fb350ed3e8b70c010084c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 7 Sep 2017 10:19:43 -0700 Subject: Revert "Annotate benign race" This reverts commit 6869da4d658bf3e6631a8773e4b8ae315fcfec0e. --- include/grpc/impl/codegen/port_platform.h | 6 ------ test/cpp/microbenchmarks/bm_fullstack_trickle.cc | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 5bbab70c6a..e84a75d295 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -409,10 +409,4 @@ typedef unsigned __int64 uint64_t; #define CENSUSAPI GRPCAPI #endif -#if defined(__has_feature) -#if __has_feature(thread_sanitizer) -#define GPR_ATTRIBUTE_NO_TSAN __attribute__((no_sanitize("thread"))) -#endif -#endif - #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */ diff --git a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc index 37dd08c33d..135b4710ce 100644 --- a/test/cpp/microbenchmarks/bm_fullstack_trickle.cc +++ b/test/cpp/microbenchmarks/bm_fullstack_trickle.cc @@ -105,7 +105,7 @@ class TrickledCHTTP2 : public EndpointPairFixture { (double)state.iterations()); } - void Log(int64_t iteration) GPR_ATTRIBUTE_NO_TSAN { + void Log(int64_t iteration) { auto now = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), start_); grpc_chttp2_transport* client = reinterpret_cast(client_transport_); -- cgit v1.2.3 From e5a1b2b087c560b7c8ca3bd21a86875d502b1095 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 7 Sep 2017 12:20:12 -0700 Subject: clang-format --- test/core/debug/stats_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/core/debug/stats_test.cc b/test/core/debug/stats_test.cc index bda580f7ca..c85ab3598a 100644 --- a/test/core/debug/stats_test.cc +++ b/test/core/debug/stats_test.cc @@ -69,8 +69,7 @@ static int FindExpectedBucket(int i, int j) { if (j < 0) { return 0; } - if (j >= - grpc_stats_histo_bucket_boundaries[i][grpc_stats_histo_buckets[i]]) { + if (j >= grpc_stats_histo_bucket_boundaries[i][grpc_stats_histo_buckets[i]]) { return grpc_stats_histo_buckets[i] - 1; } return std::upper_bound(grpc_stats_histo_bucket_boundaries[i], -- cgit v1.2.3