Restrict histograms to integral boundaries

pull/12371/head
Craig Tiller 8 years ago
parent 357f3f6162
commit da5cd59ed3
  1. 6
      src/core/lib/debug/stats.c
  2. 2
      src/core/lib/debug/stats.h
  3. 166
      src/core/lib/debug/stats_data.c
  4. 12
      src/core/lib/debug/stats_data.h
  5. 17
      tools/codegen/core/gen_stats_data.py

@ -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);
}

@ -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);

@ -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};

@ -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 */

@ -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))

Loading…
Cancel
Save