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 --- tools/codegen/core/gen_stats_data.py | 47 +++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'tools/codegen/core') 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'])) -- cgit v1.2.3