aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-07-18 14:22:19 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-07-18 14:22:19 -0700
commit280866817ffdec59d0446df3c99c2544837da3ad (patch)
tree63fe79f0d1e5827d025217d6d36d94d8113510bf /tools
parent65d447f2c31b08d0503257932768c59b59549ecd (diff)
Add a simple stats framework to gRPC C core
Diffstat (limited to 'tools')
-rwxr-xr-xtools/codegen/core/gen_stats_data.py102
-rw-r--r--tools/doxygen/Doxyfile.core.internal4
-rw-r--r--tools/run_tests/generated/sources_and_headers.json21
3 files changed, 127 insertions, 0 deletions
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, "};"
diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal
index 4ad8a0ddb4..2995145fe1 100644
--- a/tools/doxygen/Doxyfile.core.internal
+++ b/tools/doxygen/Doxyfile.core.internal
@@ -1073,6 +1073,10 @@ src/core/lib/compression/message_compress.c \
src/core/lib/compression/message_compress.h \
src/core/lib/compression/stream_compression.c \
src/core/lib/compression/stream_compression.h \
+src/core/lib/debug/stats.c \
+src/core/lib/debug/stats.h \
+src/core/lib/debug/stats_data.c \
+src/core/lib/debug/stats_data.h \
src/core/lib/debug/trace.c \
src/core/lib/debug/trace.h \
src/core/lib/http/format_request.c \
diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json
index 8993e9340a..bdad9e9d01 100644
--- a/tools/run_tests/generated/sources_and_headers.json
+++ b/tools/run_tests/generated/sources_and_headers.json
@@ -7691,6 +7691,7 @@
"deps": [
"gpr",
"grpc_codegen",
+ "grpc_stats",
"grpc_trace"
],
"headers": [
@@ -8553,6 +8554,26 @@
},
{
"deps": [
+ "gpr"
+ ],
+ "headers": [
+ "src/core/lib/debug/stats.h",
+ "src/core/lib/debug/stats_data.h"
+ ],
+ "is_filegroup": true,
+ "language": "c",
+ "name": "grpc_stats",
+ "src": [
+ "src/core/lib/debug/stats.c",
+ "src/core/lib/debug/stats.h",
+ "src/core/lib/debug/stats_data.c",
+ "src/core/lib/debug/stats_data.h"
+ ],
+ "third_party": false,
+ "type": "filegroup"
+ },
+ {
+ "deps": [
"gpr_test_util",
"grpc"
],