aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/codegen/core
diff options
context:
space:
mode:
Diffstat (limited to 'tools/codegen/core')
-rw-r--r--tools/codegen/core/gen_hpack_tables.c5
-rwxr-xr-xtools/codegen/core/gen_static_metadata.py64
-rwxr-xr-xtools/codegen/core/gen_stats_data.py102
3 files changed, 144 insertions, 27 deletions
diff --git a/tools/codegen/core/gen_hpack_tables.c b/tools/codegen/core/gen_hpack_tables.c
index 858ae20c2d..73dfa9fbd6 100644
--- a/tools/codegen/core/gen_hpack_tables.c
+++ b/tools/codegen/core/gen_hpack_tables.c
@@ -189,7 +189,10 @@ static unsigned state_index(unsigned bitofs, symset syms, unsigned *isnew) {
return i;
}
GPR_ASSERT(nhuffstates != MAXHUFFSTATES);
- i = nhuffstates++;
+
+ i = nhuffstates;
+ nhuffstates++;
+
huffstates[i].bitofs = bitofs;
huffstates[i].syms = syms;
huffstates[i].next = nibblelut_empty();
diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py
index e56c627721..6ee8a7cace 100755
--- a/tools/codegen/core/gen_static_metadata.py
+++ b/tools/codegen/core/gen_static_metadata.py
@@ -132,29 +132,33 @@ CONFIG = [
('www-authenticate', ''),
]
+# Entries marked with is_default=True are ignored when counting
+# non-default initial metadata that prevents the chttp2 server from
+# sending a Trailers-Only response.
METADATA_BATCH_CALLOUTS = [
- ':path',
- ':method',
- ':status',
- ':authority',
- ':scheme',
- 'te',
- 'grpc-message',
- 'grpc-status',
- 'grpc-payload-bin',
- 'grpc-encoding',
- 'grpc-accept-encoding',
- 'grpc-server-stats-bin',
- 'grpc-tags-bin',
- 'grpc-trace-bin',
- 'content-type',
- 'content-encoding',
- 'accept-encoding',
- 'grpc-internal-encoding-request',
- 'grpc-internal-stream-encoding-request',
- 'user-agent',
- 'host',
- 'lb-token',
+ # (name, is_default)
+ (':path', True),
+ (':method', True),
+ (':status', True),
+ (':authority', True),
+ (':scheme', True),
+ ('te', True),
+ ('grpc-message', True),
+ ('grpc-status', True),
+ ('grpc-payload-bin', True),
+ ('grpc-encoding', True),
+ ('grpc-accept-encoding', True),
+ ('grpc-server-stats-bin', True),
+ ('grpc-tags-bin', True),
+ ('grpc-trace-bin', True),
+ ('content-type', True),
+ ('content-encoding', True),
+ ('accept-encoding', True),
+ ('grpc-internal-encoding-request', True),
+ ('grpc-internal-stream-encoding-request', True),
+ ('user-agent', True),
+ ('host', True),
+ ('lb-token', True),
]
COMPRESSION_ALGORITHMS = [
@@ -235,7 +239,7 @@ all_elems = list()
static_userdata = {}
# put metadata batch callouts first, to make the check of if a static metadata
# string is a callout trivial
-for elem in METADATA_BATCH_CALLOUTS:
+for elem, _ in METADATA_BATCH_CALLOUTS:
if elem not in all_strs:
all_strs.append(elem)
for elem in CONFIG:
@@ -372,7 +376,7 @@ def slice_def(i):
# validate configuration
-for elem in METADATA_BATCH_CALLOUTS:
+for elem, _ in METADATA_BATCH_CALLOUTS:
assert elem in all_strs
print >> H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs)
@@ -540,7 +544,7 @@ for a, b in all_elems:
print >> C, '};'
print >> H, 'typedef enum {'
-for elem in METADATA_BATCH_CALLOUTS:
+for elem, _ in METADATA_BATCH_CALLOUTS:
print >> H, ' %s,' % mangle(elem, 'batch').upper()
print >> H, ' GRPC_BATCH_CALLOUTS_COUNT'
print >> H, '} grpc_metadata_batch_callouts_index;'
@@ -548,7 +552,7 @@ print >> H
print >> H, 'typedef union {'
print >> H, ' struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT];'
print >> H, ' struct {'
-for elem in METADATA_BATCH_CALLOUTS:
+for elem, _ in METADATA_BATCH_CALLOUTS:
print >> H, ' struct grpc_linked_mdelem *%s;' % mangle(elem, '').lower()
print >> H, ' } named;'
print >> H, '} grpc_metadata_batch_callouts;'
@@ -556,6 +560,14 @@ print >> H
print >> H, '#define GRPC_BATCH_INDEX_OF(slice) \\'
print >> H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? (grpc_metadata_batch_callouts_index)GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)'
print >> H
+print >> H, ('extern bool grpc_static_callout_is_default['
+ 'GRPC_BATCH_CALLOUTS_COUNT];')
+print >> H
+print >> C, 'bool grpc_static_callout_is_default[GRPC_BATCH_CALLOUTS_COUNT] = {'
+for elem, is_default in METADATA_BATCH_CALLOUTS:
+ print >> C, ' %s, // %s' % (str(is_default).lower(), elem)
+print >> C, '};'
+print >> C
print >> H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (
1 << len(COMPRESSION_ALGORITHMS))
diff --git a/tools/codegen/core/gen_stats_data.py b/tools/codegen/core/gen_stats_data.py
new file mode 100755
index 0000000000..bc601a89a7
--- /dev/null
+++ b/tools/codegen/core/gen_stats_data.py
@@ -0,0 +1,102 @@
+#!/usr/bin/env python2.7
+
+# 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.
+
+import collections
+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')
+
+counters = []
+
+for attr in attrs:
+ if 'counter' in attr:
+ counters.append(Counter(name=attr['counter']))
+ else:
+ print 'Error: bad attr %r' % attr
+
+# utility: print a big comment block into a set of files
+def put_banner(files, banner):
+ for f in files:
+ print >>f, '/*'
+ for line in banner:
+ print >>f, ' * %s' % line
+ print >>f, ' */'
+ print >>f
+
+with open('src/core/lib/debug/stats_data.h', 'w') as H:
+ # copy-paste copyright notice from this file
+ with open(sys.argv[0]) as my_source:
+ copyright = []
+ for line in my_source:
+ if line[0] != '#': break
+ for line in my_source:
+ if line[0] == '#':
+ copyright.append(line)
+ break
+ for line in my_source:
+ if line[0] != '#':
+ break
+ copyright.append(line)
+ put_banner([H], [line[2:].rstrip() for line in copyright])
+
+ put_banner([H], ["Automatically generated by tools/codegen/core/gen_stats_data.py"])
+
+ print >>H, "#ifndef GRPC_CORE_LIB_DEBUG_STATS_DATA_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())
+
+ print >>H, "extern const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT];"
+
+ print >>H
+ print >>H, "#endif /* GRPC_CORE_LIB_DEBUG_STATS_DATA_H */"
+
+with open('src/core/lib/debug/stats_data.c', 'w') as C:
+ # copy-paste copyright notice from this file
+ with open(sys.argv[0]) as my_source:
+ copyright = []
+ for line in my_source:
+ if line[0] != '#': break
+ for line in my_source:
+ if line[0] == '#':
+ copyright.append(line)
+ break
+ for line in my_source:
+ if line[0] != '#':
+ break
+ copyright.append(line)
+ put_banner([C], [line[2:].rstrip() for line in copyright])
+
+ 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, "const char *grpc_stats_counter_name[GRPC_STATS_COUNTER_COUNT] = {";
+ for ctr in counters:
+ print >>C, " \"%s\"," % ctr.name
+ print >>C, "};"