Merge branch 'stats_histo' into pollset_kick_stats

pull/12370/head
Craig Tiller 8 years ago
commit f0ba70a9ea
  1. 45
      CMakeLists.txt
  2. 66
      Makefile
  3. 15
      build.yaml
  4. 29
      src/core/lib/debug/stats.c
  5. 4
      src/core/lib/debug/stats.h
  6. 624
      src/core/lib/debug/stats_data.c
  7. 231
      src/core/lib/debug/stats_data.h
  8. 127
      test/core/debug/stats_test.cc
  9. 85
      tools/codegen/core/gen_stats_data.py
  10. 21
      tools/run_tests/generated/sources_and_headers.json
  11. 22
      tools/run_tests/generated/tests.json

@ -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)
@ -12155,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++
@ -12200,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++
@ -12417,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++
@ -12754,6 +12758,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

@ -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"
@ -16129,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)
@ -16172,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)
@ -16364,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)
@ -16699,6 +16704,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 \

@ -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++
@ -4529,6 +4532,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++

@ -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,
const double *table, int table_size) {
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,
@ -92,7 +89,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 +160,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);
}

@ -50,8 +50,8 @@ 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,
const double *table, int table_size);
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,
double percentile);

@ -19,6 +19,9 @@
*/
#include "src/core/lib/debug/stats_data.h"
#include <grpc/support/useful.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",
@ -57,362 +60,281 @@ const char *grpc_stats_histogram_name[GRPC_STATS_HISTOGRAM_COUNT] = {
"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,
6.03034139457,
7.27300346702,
8.77173877401,
10.5793158863,
12.759377303,
15.3886802239,
18.5597990724,
22.3843849243,
26.9970966002,
32.5603418323,
39.2699954346,
47.3622958068,
57.1221625891,
68.8932283217,
83.0899373109,
100.212137688,
120.862680427,
145.768644968,
175.806938756,
212.035172047,
255.72889502,
308.426508286,
371.98342802,
448.637412817,
541.087352333,
652.588291771,
787.066037897,
949.255381718,
1144.86680448,
1380.78753647,
1665.32404765,
2008.49450799,
2422.38151446,
2921.55750402,
3523.59783062,
4249.69957117,
5125.4278477,
6181.61594298,
7455.45090126,
8991.78283702,
10844.7040506,
13079.4535497,
15774.7140318,
19025.3822027,
22945.9099689,
27674.3341444,
33377.1365516,
40255.1056359,
48550.4059718,
58555.104571,
70621.4541917,
85174.2957114,
102726.016236,
123894.589602,
149425.334448,
180217.155944,
217354.195101,
262144.0};
const int grpc_stats_table_0[64] = {
0, 1, 2, 3, 4, 5, 7, 9, 11, 14,
17, 21, 26, 32, 39, 47, 57, 69, 83, 100,
120, 144, 173, 207, 248, 297, 356, 426, 510, 610,
730, 873, 1044, 1248, 1492, 1784, 2133, 2550, 3048, 3643,
4354, 5204, 6219, 7432, 8882, 10615, 12685, 15159, 18115, 21648,
25870, 30915, 36944, 44148, 52757, 63044, 75337, 90027, 107581, 128558,
153625, 183579, 219373, 262144};
const uint8_t grpc_stats_table_1[124] = {
0, 2, 2, 4, 4, 6, 6, 8, 8, 11, 11, 11, 13, 13,
15, 15, 17, 17, 20, 20, 20, 21, 23, 23, 26, 26, 26, 28,
28, 30, 30, 32, 32, 35, 35, 35, 37, 37, 38, 41, 41, 41,
43, 43, 45, 45, 47, 47, 50, 50, 50, 52, 52, 54, 54, 56,
56, 58, 58, 60, 60, 62, 62, 65, 65, 65, 67, 67, 69, 69,
71, 71, 73, 73, 76, 76, 76, 78, 78, 80, 80, 82, 82, 84,
84, 86, 86, 88, 88, 91, 91, 91, 93, 93, 95, 95, 97, 97,
100, 100, 100, 101, 103, 103, 106, 106, 106, 108, 108, 110, 110, 112,
112, 115, 115, 115, 117, 117, 118, 121, 121, 121, 124, 124};
const double grpc_stats_table_2[128] = {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.0367057593,
30.1117957626,
31.2266911945,
32.382865859,
33.5818481283,
34.8252229627,
36.1146340061,
37.4517857586,
38.8384458298,
40.2764472753,
41.7676910202,
43.3141483714,
44.9178636242,
46.580956764,
48.3056262695,
50.0941520181,
51.9488983005,
53.8723169454,
55.8669505614,
57.9354358972,
60.0805073281,
62.3050004699,
64.6118559278,
67.0041231836,
69.4849646266,
72.0576597342,
74.7256094075,
77.4923404661,
80.3615103113,
83.3369117602,
86.4224780597,
89.6222880862,
92.940571737,
96.3817155226,
99.9502683646,
103.65094761,
107.488645265,
111.468434465,
115.595576179,
119.875526164,
124.313942178,
128.916691457,
133.689858475,
138.639752984,
143.772918355,
149.09614023,
154.616455489,
160.341161557,
166.277826044,
172.434296755,
178.818712061,
185.439511656,
192.305447719,
199.425596476,
206.809370205,
214.466529676,
222.407197051,
230.641869269,
239.181431919,
248.037173633,
257.220801006,
266.744454071,
276.62072235,
286.862661493,
297.48381054,
308.498209814,
319.920419488,
331.765538824,
344.04922614,
356.787719506,
369.997858208,
383.697105013,
397.903569249,
412.636030746,
427.913964659,
443.757567219,
460.187782422,
477.226329722,
494.895732741,
513.219349041,
532.221401003,
551.927007848,
572.36221884,
593.554047722,
615.530508428,
638.320652111,
661.954605552,
686.46361098,
711.880067376,
738.237573297,
765.570971297,
793.91639398,
823.311311768,
853.794582433,
885.406502465,
918.188860339,
952.184991756,
987.439836931,
1024.0};
0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6,
7, 7, 7, 8, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 14,
15, 15, 16, 17, 17, 18, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23,
24, 24, 25, 25, 26, 26, 26, 27, 28, 28, 29, 29, 30, 30, 30, 31, 32, 32,
33, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37, 38, 38, 39, 39, 40, 40, 41,
41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 46, 47, 48, 48, 49, 49, 49,
50, 50, 51, 52, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57};
const int grpc_stats_table_2[128] = {
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, 30,
32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 61,
64, 67, 70, 73, 76, 79, 82, 85, 88, 91, 95, 99, 103, 107, 111,
115, 119, 123, 128, 133, 138, 143, 148, 153, 159, 165, 171, 177, 183, 189,
196, 203, 210, 217, 224, 232, 240, 248, 256, 265, 274, 283, 293, 303, 313,
323, 334, 345, 356, 368, 380, 392, 405, 418, 432, 446, 460, 475, 490, 506,
522, 539, 556, 574, 592, 611, 630, 650, 670, 691, 713, 735, 758, 782, 806,
831, 857, 883, 910, 938, 966, 995, 1024};
const uint8_t grpc_stats_table_3[166] = {
0, 2, 2, 4, 4, 6, 6, 7, 8, 10, 10, 11, 12, 14,
14, 15, 17, 17, 18, 20, 20, 22, 22, 24, 24, 25, 27, 27,
29, 29, 31, 31, 34, 34, 34, 36, 36, 38, 38, 39, 40, 42,
42, 43, 44, 46, 46, 47, 49, 49, 50, 52, 52, 54, 54, 55,
57, 57, 59, 59, 61, 61, 63, 63, 65, 65, 68, 68, 68, 70,
70, 71, 72, 73, 75, 75, 76, 78, 78, 79, 81, 81, 82, 84,
84, 86, 86, 87, 89, 89, 91, 91, 93, 93, 95, 95, 97, 97,
100, 100, 100, 102, 102, 103, 104, 105, 107, 107, 108, 109, 111, 111,
113, 113, 114, 116, 116, 117, 119, 119, 121, 121, 123, 123, 125, 125,
127, 127, 129, 129, 131, 131, 134, 134, 134, 135, 136, 137, 139, 139,
140, 141, 143, 143, 144, 146, 146, 148, 148, 149, 151, 151, 153, 153,
155, 155, 157, 157, 159, 159, 161, 161, 163, 163, 166, 166};
const double grpc_stats_table_4[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};
0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7,
8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 15, 16, 16,
16, 17, 18, 18, 19, 20, 20, 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 27, 28,
28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 34, 35, 36, 37, 38, 38,
39, 40, 41, 41, 42, 43, 43, 44, 45, 45, 46, 46, 47, 48, 48, 49, 49, 50, 50,
51, 51, 52, 52, 53, 53, 54, 54, 55, 56, 57, 58, 59, 60, 60, 61, 62, 63, 63,
64, 65, 65, 66, 67, 67, 68, 69, 69, 70, 70, 71, 72, 72, 73, 73, 74, 74, 75,
75, 76, 77, 78, 79, 80, 80, 81, 82, 83, 84, 85, 85, 86, 87, 88, 88, 89, 90,
90, 91, 92, 92, 93, 93, 94, 95, 95, 96, 96, 97, 97, 98};
const int grpc_stats_table_4[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_5[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_6[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_7[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};
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_6[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_7[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};
void grpc_stats_inc_call_initial_size(grpc_exec_ctx *exec_ctx, int value) {
value = GPR_CLAMP(value, 0, 262144);
if (value < 6) {
GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE,
value);
return;
}
union {
double dbl;
uint64_t uint;
} _val, _bkt;
_val.dbl = value;
if (_val.uint < 4650529565213458432ull) {
int bucket =
grpc_stats_table_1[((_val.uint - 4618441417868443648ull) >> 49)] + 6;
_bkt.dbl = grpc_stats_table_0[bucket];
bucket -= (_val.uint < _bkt.uint);
GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE,
bucket);
return;
}
GRPC_STATS_INC_HISTOGRAM((exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE,
grpc_stats_histo_find_bucket_slow(
(exec_ctx), value, grpc_stats_table_0, 64));
}
void grpc_stats_inc_poll_events_returned(grpc_exec_ctx *exec_ctx, int value) {
value = GPR_CLAMP(value, 0, 1024);
if (value < 29) {
GRPC_STATS_INC_HISTOGRAM((exec_ctx),
GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, value);
return;
}
union {
double dbl;
uint64_t uint;
} _val, _bkt;
_val.dbl = value;
if (_val.uint < 4642648265865560064ull) {
int bucket =
grpc_stats_table_3[((_val.uint - 4628855992006737920ull) >> 47)] + 29;
_bkt.dbl = grpc_stats_table_2[bucket];
bucket -= (_val.uint < _bkt.uint);
GRPC_STATS_INC_HISTOGRAM((exec_ctx),
GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, bucket);
return;
}
GRPC_STATS_INC_HISTOGRAM((exec_ctx),
GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED,
grpc_stats_histo_find_bucket_slow(
(exec_ctx), value, grpc_stats_table_2, 128));
}
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, _bkt;
_val.dbl = value;
if (_val.uint < 4682617712558473216ull) {
int bucket =
grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5;
_bkt.dbl = grpc_stats_table_4[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), value, grpc_stats_table_4, 64));
}
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, _bkt;
_val.dbl = value;
if (_val.uint < 4637300241308057600ull) {
int bucket =
grpc_stats_table_7[((_val.uint - 4622945017495814144ull) >> 48)] + 12;
_bkt.dbl = grpc_stats_table_6[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), value, grpc_stats_table_6, 64));
}
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, _bkt;
_val.dbl = value;
if (_val.uint < 4682617712558473216ull) {
int bucket =
grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5;
_bkt.dbl = grpc_stats_table_4[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), value, grpc_stats_table_4, 64));
}
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, _bkt;
_val.dbl = value;
if (_val.uint < 4682617712558473216ull) {
int bucket =
grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5;
_bkt.dbl = grpc_stats_table_4[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), value, grpc_stats_table_4, 64));
}
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, _bkt;
_val.dbl = value;
if (_val.uint < 4637300241308057600ull) {
int bucket =
grpc_stats_table_7[((_val.uint - 4622945017495814144ull) >> 48)] + 12;
_bkt.dbl = grpc_stats_table_6[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), value, grpc_stats_table_6, 64));
}
void grpc_stats_inc_http2_send_message_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_HTTP2_SEND_MESSAGE_SIZE, value);
return;
}
union {
double dbl;
uint64_t uint;
} _val, _bkt;
_val.dbl = value;
if (_val.uint < 4682617712558473216ull) {
int bucket =
grpc_stats_table_5[((_val.uint - 4617315517961601024ull) >> 50)] + 5;
_bkt.dbl = grpc_stats_table_4[bucket];
bucket -= (_val.uint < _bkt.uint);
GRPC_STATS_INC_HISTOGRAM(
(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), value, grpc_stats_table_4, 64));
}
const int grpc_stats_histo_buckets[8] = {64, 128, 64, 64, 64, 64, 64, 64};
const int grpc_stats_histo_start[8] = {0, 64, 192, 256, 320, 384, 448, 512};
const double *const grpc_stats_histo_bucket_boundaries[8] = {
const int *const grpc_stats_histo_bucket_boundaries[8] = {
grpc_stats_table_0, grpc_stats_table_2, grpc_stats_table_4,
grpc_stats_table_6, grpc_stats_table_4, grpc_stats_table_4,
grpc_stats_table_6, grpc_stats_table_4};
void (*const grpc_stats_inc_histogram[8])(grpc_exec_ctx *exec_ctx, int x) = {
grpc_stats_inc_call_initial_size, grpc_stats_inc_poll_events_returned,
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};

@ -22,6 +22,7 @@
#define GRPC_CORE_LIB_DEBUG_STATS_DATA_H
#include <inttypes.h>
#include "src/core/lib/iomgr/exec_ctx.h"
typedef enum {
GRPC_STATS_COUNTER_CLIENT_CALLS_CREATED,
@ -163,210 +164,34 @@ typedef enum {
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_CALL_INITIAL_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 < 6.000000) { \
GRPC_STATS_INC_HISTOGRAM( \
(exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, (int)_val.dbl); \
} else { \
if (_val.uint < 4688247212092686336ull) { \
GRPC_STATS_INC_HISTOGRAM( \
(exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, \
grpc_stats_table_1[((_val.uint - 4618441417868443648ull) >> 49)]); \
} else { \
GRPC_STATS_INC_HISTOGRAM( \
(exec_ctx), GRPC_STATS_HISTOGRAM_CALL_INITIAL_SIZE, \
grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, \
grpc_stats_table_0, 64)); \
} \
} \
} while (false)
#define GRPC_STATS_INC_POLL_EVENTS_RETURNED(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 < 29.000000) { \
GRPC_STATS_INC_HISTOGRAM((exec_ctx), \
GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, \
(int)_val.dbl); \
} else { \
if (_val.uint < 4652218415073722368ull) { \
GRPC_STATS_INC_HISTOGRAM( \
(exec_ctx), GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, \
grpc_stats_table_3[((_val.uint - 4628855992006737920ull) >> 47)]); \
} else { \
GRPC_STATS_INC_HISTOGRAM( \
(exec_ctx), GRPC_STATS_HISTOGRAM_POLL_EVENTS_RETURNED, \
grpc_stats_histo_find_bucket_slow((exec_ctx), _val.dbl, \
grpc_stats_table_2, 128)); \
} \
} \
} while (false)
#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_5[((_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_4, 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_7[((_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_6, 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_5[((_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_4, 64)); \
} \
} \
} 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_5[((_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_4, 64)); \
} \
} \
} 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_7[((_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_6, 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_5[((_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_4, 64)); \
} \
} \
} while (false)
extern const double grpc_stats_table_0[64];
extern const uint8_t grpc_stats_table_1[124];
extern const double grpc_stats_table_2[128];
extern const uint8_t grpc_stats_table_3[166];
extern const double grpc_stats_table_4[64];
extern const uint8_t grpc_stats_table_5[87];
extern const double grpc_stats_table_6[64];
extern const uint8_t grpc_stats_table_7[52];
#define GRPC_STATS_INC_CALL_INITIAL_SIZE(exec_ctx, value) \
grpc_stats_inc_call_initial_size((exec_ctx), (int)(value))
void grpc_stats_inc_call_initial_size(grpc_exec_ctx *exec_ctx, int x);
#define GRPC_STATS_INC_POLL_EVENTS_RETURNED(exec_ctx, value) \
grpc_stats_inc_poll_events_returned((exec_ctx), (int)(value))
void grpc_stats_inc_poll_events_returned(grpc_exec_ctx *exec_ctx, int x);
#define GRPC_STATS_INC_TCP_WRITE_SIZE(exec_ctx, value) \
grpc_stats_inc_tcp_write_size((exec_ctx), (int)(value))
void grpc_stats_inc_tcp_write_size(grpc_exec_ctx *exec_ctx, int x);
#define GRPC_STATS_INC_TCP_WRITE_IOV_SIZE(exec_ctx, value) \
grpc_stats_inc_tcp_write_iov_size((exec_ctx), (int)(value))
void grpc_stats_inc_tcp_write_iov_size(grpc_exec_ctx *exec_ctx, int x);
#define GRPC_STATS_INC_TCP_READ_SIZE(exec_ctx, value) \
grpc_stats_inc_tcp_read_size((exec_ctx), (int)(value))
void grpc_stats_inc_tcp_read_size(grpc_exec_ctx *exec_ctx, int x);
#define GRPC_STATS_INC_TCP_READ_OFFER(exec_ctx, value) \
grpc_stats_inc_tcp_read_offer((exec_ctx), (int)(value))
void grpc_stats_inc_tcp_read_offer(grpc_exec_ctx *exec_ctx, int x);
#define GRPC_STATS_INC_TCP_READ_IOV_SIZE(exec_ctx, value) \
grpc_stats_inc_tcp_read_iov_size((exec_ctx), (int)(value))
void grpc_stats_inc_tcp_read_iov_size(grpc_exec_ctx *exec_ctx, int x);
#define GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE(exec_ctx, value) \
grpc_stats_inc_http2_send_message_size((exec_ctx), (int)(value))
void grpc_stats_inc_http2_send_message_size(grpc_exec_ctx *exec_ctx, int x);
extern const int grpc_stats_histo_buckets[8];
extern const int grpc_stats_histo_start[8];
extern const double *const grpc_stats_histo_bucket_boundaries[8];
extern const int *const grpc_stats_histo_bucket_boundaries[8];
extern void (*const grpc_stats_inc_histogram[8])(grpc_exec_ctx *exec_ctx,
int x);
#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */

@ -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 <grpc/grpc.h>
#include <grpc/support/log.h>
#include <gtest/gtest.h>
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;
}

@ -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 = []
@ -109,48 +111,51 @@ 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]
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'
#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 = '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 += '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 += '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 += '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))
if shift_data is not None:
code += '}'
code += '}'
code += '} while (false)'
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
@ -184,6 +189,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 <inttypes.h>"
print >>H, "#include \"src/core/lib/iomgr/exec_ctx.h\""
print >>H
for typename, instances in sorted(inst_map.items()):
@ -215,18 +221,17 @@ 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), (int)(value))" % (
histogram.name.upper(), histogram.name.lower())
print >>H, "void grpc_stats_inc_%s(grpc_exec_ctx *exec_ctx, int 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]))
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, "extern void (*const grpc_stats_inc_histogram[%d])(grpc_exec_ctx *exec_ctx, int x);" % len(inst_map['Histogram'])
print >>H
print >>H, "#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */"
@ -250,6 +255,15 @@ 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\""
print >>C, "#include <grpc/support/useful.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 +275,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, int 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};" % (
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, int x) = {%s};" % (
len(inst_map['Histogram']), ','.join('grpc_stats_inc_%s' % histogram.name.lower() for histogram in inst_map['Histogram']))

@ -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",
@ -4016,6 +4019,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",

@ -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": [

Loading…
Cancel
Save