aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/codegen/core/gen_stats_data.py
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-09-01 16:45:36 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-09-01 16:45:36 -0700
commite4605634a70fa67afaa593b1aa0465c5cf19c361 (patch)
tree0676fe30394020af4333fd8a464b93c526896392 /tools/codegen/core/gen_stats_data.py
parent56a84848c7b683e6e7fb3bef8b37364f9984cfdb (diff)
Cleanup intification
Diffstat (limited to 'tools/codegen/core/gen_stats_data.py')
-rwxr-xr-xtools/codegen/core/gen_stats_data.py27
1 files changed, 13 insertions, 14 deletions
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 <grpc/support/useful.h>"
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']))