Tracer registration.
First: ugh.
Second: allow tracer global variables to be registered and then parsed out of a configuration environment variable.
Expose TSI trace config variable directly to ease this a little.
diff --git a/Makefile b/Makefile
index e390a3e..6487134 100644
--- a/Makefile
+++ b/Makefile
@@ -2328,6 +2328,7 @@
src/core/security/secure_transport_setup.c \
src/core/security/security_context.c \
src/core/security/server_secure_chttp2.c \
+ src/core/surface/init_secure.c \
src/core/surface/secure_channel_create.c \
src/core/surface/secure_server_create.c \
src/core/tsi/fake_transport_security.c \
@@ -2407,6 +2408,7 @@
src/core/surface/server.c \
src/core/surface/server_chttp2.c \
src/core/surface/server_create.c \
+ src/core/surface/surface_trace.c \
src/core/transport/chttp2/alpn.c \
src/core/transport/chttp2/bin_encoder.c \
src/core/transport/chttp2/frame_data.c \
@@ -2472,6 +2474,7 @@
src/core/security/secure_transport_setup.c: $(OPENSSL_DEP)
src/core/security/security_context.c: $(OPENSSL_DEP)
src/core/security/server_secure_chttp2.c: $(OPENSSL_DEP)
+src/core/surface/init_secure.c: $(OPENSSL_DEP)
src/core/surface/secure_channel_create.c: $(OPENSSL_DEP)
src/core/surface/secure_server_create.c: $(OPENSSL_DEP)
src/core/tsi/fake_transport_security.c: $(OPENSSL_DEP)
@@ -2551,6 +2554,7 @@
src/core/surface/server.c: $(OPENSSL_DEP)
src/core/surface/server_chttp2.c: $(OPENSSL_DEP)
src/core/surface/server_create.c: $(OPENSSL_DEP)
+src/core/surface/surface_trace.c: $(OPENSSL_DEP)
src/core/transport/chttp2/alpn.c: $(OPENSSL_DEP)
src/core/transport/chttp2/bin_encoder.c: $(OPENSSL_DEP)
src/core/transport/chttp2/frame_data.c: $(OPENSSL_DEP)
@@ -2633,6 +2637,7 @@
$(OBJDIR)/$(CONFIG)/src/core/security/secure_transport_setup.o:
$(OBJDIR)/$(CONFIG)/src/core/security/security_context.o:
$(OBJDIR)/$(CONFIG)/src/core/security/server_secure_chttp2.o:
+$(OBJDIR)/$(CONFIG)/src/core/surface/init_secure.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/secure_channel_create.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/secure_server_create.o:
$(OBJDIR)/$(CONFIG)/src/core/tsi/fake_transport_security.o:
@@ -2712,6 +2717,7 @@
$(OBJDIR)/$(CONFIG)/src/core/surface/server.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/server_chttp2.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/server_create.o:
+$(OBJDIR)/$(CONFIG)/src/core/surface/surface_trace.o:
$(OBJDIR)/$(CONFIG)/src/core/transport/chttp2/alpn.o:
$(OBJDIR)/$(CONFIG)/src/core/transport/chttp2/bin_encoder.o:
$(OBJDIR)/$(CONFIG)/src/core/transport/chttp2/frame_data.o:
@@ -2811,6 +2817,7 @@
LIBGRPC_UNSECURE_SRC = \
+ src/core/surface/init_unsecure.c \
src/core/channel/call_op_string.c \
src/core/channel/census_filter.c \
src/core/channel/channel_args.c \
@@ -2885,6 +2892,7 @@
src/core/surface/server.c \
src/core/surface/server_chttp2.c \
src/core/surface/server_create.c \
+ src/core/surface/surface_trace.c \
src/core/transport/chttp2/alpn.c \
src/core/transport/chttp2/bin_encoder.c \
src/core/transport/chttp2/frame_data.c \
@@ -2947,6 +2955,7 @@
-include $(LIBGRPC_UNSECURE_OBJS:.o=.dep)
endif
+$(OBJDIR)/$(CONFIG)/src/core/surface/init_unsecure.o:
$(OBJDIR)/$(CONFIG)/src/core/channel/call_op_string.o:
$(OBJDIR)/$(CONFIG)/src/core/channel/census_filter.o:
$(OBJDIR)/$(CONFIG)/src/core/channel/channel_args.o:
@@ -3021,6 +3030,7 @@
$(OBJDIR)/$(CONFIG)/src/core/surface/server.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/server_chttp2.o:
$(OBJDIR)/$(CONFIG)/src/core/surface/server_create.o:
+$(OBJDIR)/$(CONFIG)/src/core/surface/surface_trace.o:
$(OBJDIR)/$(CONFIG)/src/core/transport/chttp2/alpn.o:
$(OBJDIR)/$(CONFIG)/src/core/transport/chttp2/bin_encoder.o:
$(OBJDIR)/$(CONFIG)/src/core/transport/chttp2/frame_data.o:
@@ -8076,13 +8086,24 @@
else
-$(BINDIR)/$(CONFIG)/qps_client_async: $(QPS_CLIENT_ASYNC_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
+
+ifeq ($(NO_PROTOBUF),true)
+
+# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
+
+$(BINDIR)/$(CONFIG)/qps_client_async: protobuf_dep_error
+
+else
+
+$(BINDIR)/$(CONFIG)/qps_client_async: $(PROTOBUF_DEP) $(QPS_CLIENT_ASYNC_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(QPS_CLIENT_ASYNC_OBJS) $(GTEST_LIB) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/qps_client_async
endif
+endif
+
$(OBJDIR)/$(CONFIG)/test/cpp/qps/qpstest.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/test/cpp/qps/client_async.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
@@ -8153,13 +8174,24 @@
else
-$(BINDIR)/$(CONFIG)/qps_server_async: $(QPS_SERVER_ASYNC_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
+
+ifeq ($(NO_PROTOBUF),true)
+
+# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+.
+
+$(BINDIR)/$(CONFIG)/qps_server_async: protobuf_dep_error
+
+else
+
+$(BINDIR)/$(CONFIG)/qps_server_async: $(PROTOBUF_DEP) $(QPS_SERVER_ASYNC_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(QPS_SERVER_ASYNC_OBJS) $(GTEST_LIB) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/qps_server_async
endif
+endif
+
$(OBJDIR)/$(CONFIG)/test/cpp/qps/qpstest.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/test/cpp/qps/server_async.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
diff --git a/build.json b/build.json
index 6be1d53..e8ecd8e 100644
--- a/build.json
+++ b/build.json
@@ -79,6 +79,7 @@
"src/core/surface/client.h",
"src/core/surface/completion_queue.h",
"src/core/surface/event_string.h",
+ "src/core/surface/init.h",
"src/core/surface/lame_client.h",
"src/core/surface/server.h",
"src/core/surface/surface_trace.h",
@@ -180,6 +181,7 @@
"src/core/surface/server.c",
"src/core/surface/server_chttp2.c",
"src/core/surface/server_create.c",
+ "src/core/surface/surface_trace.c",
"src/core/transport/chttp2/alpn.c",
"src/core/transport/chttp2/bin_encoder.c",
"src/core/transport/chttp2/frame_data.c",
@@ -329,6 +331,7 @@
"src/core/security/secure_transport_setup.c",
"src/core/security/security_context.c",
"src/core/security/server_secure_chttp2.c",
+ "src/core/surface/init_secure.c",
"src/core/surface/secure_channel_create.c",
"src/core/surface/secure_server_create.c",
"src/core/tsi/fake_transport_security.c",
@@ -372,6 +375,9 @@
"name": "grpc_unsecure",
"build": "all",
"language": "c",
+ "src": [
+ "src/core/surface/init_unsecure.c"
+ ],
"deps": [
"gpr"
],
diff --git a/src/core/channel/channel_stack.c b/src/core/channel/channel_stack.c
index 0382a7a..21df977 100644
--- a/src/core/channel/channel_stack.c
+++ b/src/core/channel/channel_stack.c
@@ -36,6 +36,8 @@
#include <stdlib.h>
+int grpc_trace_channel = 0;
+
/* Memory layouts.
Channel stack is laid out as: {
diff --git a/src/core/channel/channel_stack.h b/src/core/channel/channel_stack.h
index c136f5c..ef1da7b 100644
--- a/src/core/channel/channel_stack.h
+++ b/src/core/channel/channel_stack.h
@@ -298,7 +298,9 @@
void grpc_call_element_send_cancel(grpc_call_element *cur_elem);
void grpc_call_element_send_finish(grpc_call_element *cur_elem);
+extern int grpc_trace_channel;
+
#define GRPC_CALL_LOG_OP(sev, elem, op) \
- if (grpc_trace_bits & GRPC_TRACE_CHANNEL) grpc_call_log_op(sev, elem, op)
+ if (grpc_trace_channel) grpc_call_log_op(sev, elem, op)
#endif /* GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_STACK_H */
diff --git a/src/core/debug/trace.c b/src/core/debug/trace.c
index 6f84ee2..9389631 100644
--- a/src/core/debug/trace.c
+++ b/src/core/debug/trace.c
@@ -39,8 +39,21 @@
#include <grpc/support/log.h>
#include "src/core/support/env.h"
-#if GRPC_ENABLE_TRACING
-gpr_uint32 grpc_trace_bits = 0;
+typedef struct tracer {
+ const char *name;
+ int *flag;
+ struct tracer *next;
+} tracer;
+static tracer *tracers;
+
+void grpc_register_tracer(const char *name, int *flag) {
+ tracer *t = gpr_malloc(sizeof(*t));
+ t->name = name;
+ t->flag = flag;
+ t->next = tracers;
+ *flag = 0;
+ tracers = t;
+}
static void add(const char *beg, const char *end, char ***ss, size_t *ns) {
size_t n = *ns;
@@ -67,28 +80,26 @@
char **strings = NULL;
size_t nstrings = 0;
size_t i;
+ tracer *t;
split(s, &strings, &nstrings);
- grpc_trace_bits = 0;
-
for (i = 0; i < nstrings; i++) {
const char *s = strings[i];
- if (0 == strcmp(s, "surface")) {
- grpc_trace_bits |= GRPC_TRACE_SURFACE;
- } else if (0 == strcmp(s, "channel")) {
- grpc_trace_bits |= GRPC_TRACE_CHANNEL;
- } else if (0 == strcmp(s, "tcp")) {
- grpc_trace_bits |= GRPC_TRACE_TCP;
- } else if (0 == strcmp(s, "secure_endpoint")) {
- grpc_trace_bits |= GRPC_TRACE_SECURE_ENDPOINT;
- } else if (0 == strcmp(s, "http")) {
- grpc_trace_bits |= GRPC_TRACE_HTTP;
- } else if (0 == strcmp(s, "ssl")) {
- grpc_trace_bits |= GRPC_TRACE_SSL;
- } else if (0 == strcmp(s, "all")) {
- grpc_trace_bits = -1;
+ if (0 == strcmp(s, "all")) {
+ for (t = tracers; t; t = t->next) {
+ *t->flag = 1;
+ }
} else {
- gpr_log(GPR_ERROR, "Unknown trace var: '%s'", s);
+ int found = 0;
+ for (t = tracers; t; t = t->next) {
+ if (0 == strcmp(s, t->name)) {
+ *t->flag = 1;
+ found = 1;
+ }
+ }
+ if (!found) {
+ gpr_log(GPR_ERROR, "Unknown trace var: '%s'", s);
+ }
}
}
@@ -98,17 +109,10 @@
gpr_free(strings);
}
-void grpc_init_trace_bits() {
- char *e = gpr_getenv("GRPC_TRACE");
- if (e == NULL) {
- grpc_trace_bits = 0;
- } else {
+void grpc_tracer_init(const char *env_var) {
+ char *e = gpr_getenv(env_var);
+ if (e != NULL) {
parse(e);
gpr_free(e);
}
}
-#else
-void grpc_init_trace_bits() {
-}
-#endif
-
diff --git a/src/core/debug/trace.h b/src/core/debug/trace.h
index e11630f..c02f14b 100644
--- a/src/core/debug/trace.h
+++ b/src/core/debug/trace.h
@@ -36,26 +36,7 @@
#include <grpc/support/port_platform.h>
-/* set to zero to remove all debug trace code */
-#ifndef GRPC_ENABLE_TRACING
-# define GRPC_ENABLE_TRACING 1
-#endif
-
-typedef enum {
- GRPC_TRACE_SURFACE = 1 << 0,
- GRPC_TRACE_CHANNEL = 1 << 1,
- GRPC_TRACE_TCP = 1 << 2,
- GRPC_TRACE_SECURE_ENDPOINT = 1 << 3,
- GRPC_TRACE_HTTP = 1 << 4,
- GRPC_TRACE_SSL = 1 << 5
-} grpc_trace_bit_value;
-
-#if GRPC_ENABLE_TRACING
-extern gpr_uint32 grpc_trace_bits;
-#else
-# define grpc_trace_bits 0
-#endif
-
-void grpc_init_trace_bits();
+void grpc_register_tracer(const char *name, int *flag);
+void grpc_tracer_init(const char *env_var_name);
#endif /* GRPC_INTERNAL_CORE_DEBUG_TRACE_H */
diff --git a/src/core/iomgr/iomgr_posix.c b/src/core/iomgr/iomgr_posix.c
index 14e3d18..758ae77 100644
--- a/src/core/iomgr/iomgr_posix.c
+++ b/src/core/iomgr/iomgr_posix.c
@@ -36,11 +36,14 @@
#ifdef GPR_POSIX_SOCKET
#include "src/core/iomgr/iomgr_posix.h"
+#include "src/core/debug/trace.h"
#include "src/core/iomgr/fd_posix.h"
+#include "src/core/iomgr/tcp_posix.h"
void grpc_iomgr_platform_init(void) {
grpc_fd_global_init();
grpc_pollset_global_init();
+ grpc_register_tracer("tcp", &grpc_tcp_trace);
}
void grpc_iomgr_platform_shutdown(void) {
diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c
index eceb0fe..597a2a6 100644
--- a/src/core/iomgr/tcp_posix.c
+++ b/src/core/iomgr/tcp_posix.c
@@ -63,6 +63,8 @@
int memory_owned; /* True if slices array is owned */
} grpc_tcp_slice_state;
+int grpc_tcp_trace = 0;
+
static void slice_state_init(grpc_tcp_slice_state *state, gpr_slice *slices,
size_t nslices, size_t valid_slices) {
state->slices = slices;
@@ -294,7 +296,7 @@
grpc_endpoint_cb_status status) {
grpc_endpoint_read_cb cb = tcp->read_cb;
- if (grpc_trace_bits & GRPC_TRACE_TCP) {
+ if (grpc_tcp_trace) {
size_t i;
gpr_log(GPR_DEBUG, "read: status=%d", status);
for (i = 0; i < nslices; i++) {
@@ -495,7 +497,7 @@
grpc_tcp *tcp = (grpc_tcp *)ep;
grpc_endpoint_write_status status;
- if (grpc_trace_bits & GRPC_TRACE_TCP) {
+ if (grpc_tcp_trace) {
size_t i;
for (i = 0; i < nslices; i++) {
diff --git a/src/core/iomgr/tcp_posix.h b/src/core/iomgr/tcp_posix.h
index 7e8064b..44279d5 100644
--- a/src/core/iomgr/tcp_posix.h
+++ b/src/core/iomgr/tcp_posix.h
@@ -49,6 +49,8 @@
#define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192
+extern int grpc_tcp_trace;
+
/* Create a tcp endpoint given a file desciptor and a read slice size.
Takes ownership of fd. */
grpc_endpoint *grpc_tcp_create(grpc_fd *fd, size_t read_slice_size);
diff --git a/src/core/security/secure_endpoint.c b/src/core/security/secure_endpoint.c
index d6bdf5a..7bb1de4 100644
--- a/src/core/security/secure_endpoint.c
+++ b/src/core/security/secure_endpoint.c
@@ -65,6 +65,8 @@
gpr_refcount ref;
} secure_endpoint;
+int grpc_trace_secure_endpoint = 0;
+
static void secure_endpoint_ref(secure_endpoint *ep) { gpr_ref(&ep->ref); }
static void destroy(secure_endpoint *secure_ep) {
@@ -96,7 +98,7 @@
static void call_read_cb(secure_endpoint *ep, gpr_slice *slices, size_t nslices,
grpc_endpoint_cb_status error) {
- if (grpc_trace_bits & GRPC_TRACE_SECURE_ENDPOINT) {
+ if (grpc_trace_secure_endpoint) {
size_t i;
for (i = 0; i < nslices; i++) {
char *data =
@@ -231,7 +233,7 @@
grpc_endpoint_write_status status;
GPR_ASSERT(ep->output_buffer.count == 0);
- if (grpc_trace_bits & GRPC_TRACE_SECURE_ENDPOINT) {
+ if (grpc_trace_secure_endpoint) {
for (i = 0; i < nslices; i++) {
char *data =
gpr_hexdump((char *)GPR_SLICE_START_PTR(slices[i]),
diff --git a/src/core/security/secure_endpoint.h b/src/core/security/secure_endpoint.h
index 808889b..93c29b5 100644
--- a/src/core/security/secure_endpoint.h
+++ b/src/core/security/secure_endpoint.h
@@ -39,6 +39,8 @@
struct tsi_frame_protector;
+extern int grpc_trace_secure_endpoint;
+
/* Takes ownership of protector and to_wrap, and refs leftover_slices. */
grpc_endpoint *grpc_secure_endpoint_create(
struct tsi_frame_protector *protector, grpc_endpoint *to_wrap,
diff --git a/src/core/surface/init.c b/src/core/surface/init.c
index 2d8f36e..4db66fb 100644
--- a/src/core/surface/init.c
+++ b/src/core/surface/init.c
@@ -35,6 +35,10 @@
#include "src/core/iomgr/iomgr.h"
#include "src/core/debug/trace.h"
#include "src/core/statistics/census_interface.h"
+#include "src/core/channel/channel_stack.h"
+#include "src/core/surface/init.h"
+#include "src/core/surface/surface_trace.h"
+#include "src/core/transport/chttp2_transport.h"
static gpr_once g_init = GPR_ONCE_INIT;
static gpr_mu g_init_mu;
@@ -50,7 +54,11 @@
gpr_mu_lock(&g_init_mu);
if (++g_initializations == 1) {
- grpc_init_trace_bits();
+ grpc_register_tracer("channel", &grpc_trace_channel);
+ grpc_register_tracer("surface", &grpc_surface_trace);
+ grpc_register_tracer("http", &grpc_http_trace);
+ grpc_security_pre_init();
+ grpc_tracer_init("GRPC_TRACE");
grpc_iomgr_init();
census_init();
}
diff --git a/src/core/surface/init.h b/src/core/surface/init.h
new file mode 100644
index 0000000..ab40bed
--- /dev/null
+++ b/src/core/surface/init.h
@@ -0,0 +1,39 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef GRPC_INTERNAL_CORE_SURFACE_INIT_H
+#define GRPC_INTERNAL_CORE_SURFACE_INIT_H
+
+void grpc_security_pre_init(void);
+
+#endif /* GRPC_INTERNAL_CORE_SURFACE_INIT_H */
diff --git a/src/core/surface/init_secure.c b/src/core/surface/init_secure.c
new file mode 100644
index 0000000..5d7e5c4
--- /dev/null
+++ b/src/core/surface/init_secure.c
@@ -0,0 +1,42 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "src/core/surface/init.h"
+#include "src/core/debug/trace.h"
+#include "src/core/security/secure_endpoint.h"
+#include "src/core/tsi/transport_security_interface.h"
+
+void grpc_security_pre_init(void) {
+ grpc_register_tracer("secure_endpoint", &grpc_trace_secure_endpoint);
+ grpc_register_tracer("ssl", &tsi_tracing_enabled);
+}
diff --git a/src/core/surface/init_unsecure.c b/src/core/surface/init_unsecure.c
new file mode 100644
index 0000000..ddb70ce
--- /dev/null
+++ b/src/core/surface/init_unsecure.c
@@ -0,0 +1,37 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "src/core/surface/init.h"
+
+void grpc_security_pre_init(void) {
+}
diff --git a/src/core/surface/surface_trace.c b/src/core/surface/surface_trace.c
new file mode 100644
index 0000000..57a0053
--- /dev/null
+++ b/src/core/surface/surface_trace.c
@@ -0,0 +1,36 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "src/core/surface/surface_trace.h"
+
+int grpc_surface_trace = 0;
diff --git a/src/core/surface/surface_trace.h b/src/core/surface/surface_trace.h
index 50071ee..01302bb 100644
--- a/src/core/surface/surface_trace.h
+++ b/src/core/surface/surface_trace.h
@@ -37,8 +37,10 @@
#include "src/core/debug/trace.h"
#include <grpc/support/log.h>
+extern int grpc_surface_trace;
+
#define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \
- if (grpc_trace_bits & GRPC_TRACE_SURFACE) { \
+ if (grpc_surface_trace) { \
char *_ev = grpc_event_string(event); \
gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \
gpr_free(_ev); \
diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c
index e6c4b7e..8d3250c 100644
--- a/src/core/transport/chttp2/frame_settings.c
+++ b/src/core/transport/chttp2/frame_settings.c
@@ -37,6 +37,7 @@
#include "src/core/debug/trace.h"
#include "src/core/transport/chttp2/frame.h"
+#include "src/core/transport/chttp2_transport.h"
#include <grpc/support/log.h>
#include <grpc/support/useful.h>
@@ -218,7 +219,7 @@
}
}
parser->incoming_settings[parser->id] = parser->value;
- if (grpc_trace_bits & GRPC_TRACE_HTTP) {
+ if (grpc_http_trace) {
gpr_log(GPR_DEBUG, "CHTTP2: got setting %d = %d", parser->id,
parser->value);
}
diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c
index 476cc4b..1c5efca 100644
--- a/src/core/transport/chttp2_transport.c
+++ b/src/core/transport/chttp2_transport.c
@@ -37,7 +37,6 @@
#include <stdio.h>
#include <string.h>
-#include "src/core/debug/trace.h"
#include "src/core/support/string.h"
#include "src/core/transport/chttp2/frame_data.h"
#include "src/core/transport/chttp2/frame_goaway.h"
@@ -64,11 +63,13 @@
#define CLIENT_CONNECT_STRING "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
#define CLIENT_CONNECT_STRLEN 24
+int grpc_http_trace = 0;
+
typedef struct transport transport;
typedef struct stream stream;
#define IF_TRACING(stmt) \
- if (!(grpc_trace_bits & GRPC_TRACE_HTTP)) \
+ if (!(grpc_http_trace)) \
; \
else \
stmt
diff --git a/src/core/transport/chttp2_transport.h b/src/core/transport/chttp2_transport.h
index c5b65bd..a7f1b9a 100644
--- a/src/core/transport/chttp2_transport.h
+++ b/src/core/transport/chttp2_transport.h
@@ -37,6 +37,8 @@
#include "src/core/iomgr/endpoint.h"
#include "src/core/transport/transport.h"
+extern int grpc_http_trace;
+
void grpc_create_chttp2_transport(grpc_transport_setup_callback setup,
void *arg,
const grpc_channel_args *channel_args,
diff --git a/src/core/tsi/transport_security.c b/src/core/tsi/transport_security.c
index 04b3000..c8c74c5 100644
--- a/src/core/tsi/transport_security.c
+++ b/src/core/tsi/transport_security.c
@@ -40,10 +40,6 @@
int tsi_tracing_enabled = 0;
-void tsi_enable_tracing() {
- tsi_tracing_enabled = 1;
-}
-
/* --- Utils. --- */
char* tsi_strdup(const char* src) {
diff --git a/src/core/tsi/transport_security_interface.h b/src/core/tsi/transport_security_interface.h
index 33a19be..4e7ad00 100644
--- a/src/core/tsi/transport_security_interface.h
+++ b/src/core/tsi/transport_security_interface.h
@@ -63,8 +63,8 @@
/* --- tsi tracing --- */
-/* Call this function before any other tsi function to avoid races. */
-void tsi_enable_tracing(void);
+/* set this early to avoid races */
+extern int tsi_tracing_enabled;
/* --- tsi_frame_protector object ---
diff --git a/vsprojects/vs2013/grpc.vcxproj b/vsprojects/vs2013/grpc.vcxproj
index 48f975f..60dc980 100644
--- a/vsprojects/vs2013/grpc.vcxproj
+++ b/vsprojects/vs2013/grpc.vcxproj
@@ -160,6 +160,7 @@
<ClInclude Include="..\..\src\core\surface\client.h" />
<ClInclude Include="..\..\src\core\surface\completion_queue.h" />
<ClInclude Include="..\..\src\core\surface\event_string.h" />
+ <ClInclude Include="..\..\src\core\surface\init.h" />
<ClInclude Include="..\..\src\core\surface\lame_client.h" />
<ClInclude Include="..\..\src\core\surface\server.h" />
<ClInclude Include="..\..\src\core\surface\surface_trace.h" />
@@ -219,6 +220,8 @@
</ClCompile>
<ClCompile Include="..\..\src\core\security\server_secure_chttp2.c">
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\init_secure.c">
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\secure_channel_create.c">
</ClCompile>
<ClCompile Include="..\..\src\core\surface\secure_server_create.c">
@@ -377,6 +380,8 @@
</ClCompile>
<ClCompile Include="..\..\src\core\surface\server_create.c">
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\surface_trace.c">
+ </ClCompile>
<ClCompile Include="..\..\src\core\transport\chttp2\alpn.c">
</ClCompile>
<ClCompile Include="..\..\src\core\transport\chttp2\bin_encoder.c">
diff --git a/vsprojects/vs2013/grpc.vcxproj.filters b/vsprojects/vs2013/grpc.vcxproj.filters
index 867e545..9fc70e7 100644
--- a/vsprojects/vs2013/grpc.vcxproj.filters
+++ b/vsprojects/vs2013/grpc.vcxproj.filters
@@ -49,6 +49,9 @@
<ClCompile Include="..\..\src\core\security\server_secure_chttp2.c">
<Filter>src\core\security</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\init_secure.c">
+ <Filter>src\core\surface</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\secure_channel_create.c">
<Filter>src\core\surface</Filter>
</ClCompile>
@@ -286,6 +289,9 @@
<ClCompile Include="..\..\src\core\surface\server_create.c">
<Filter>src\core\surface</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\surface_trace.c">
+ <Filter>src\core\surface</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\core\transport\chttp2\alpn.c">
<Filter>src\core\transport\chttp2</Filter>
</ClCompile>
@@ -590,6 +596,9 @@
<ClInclude Include="..\..\src\core\surface\event_string.h">
<Filter>src\core\surface</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\core\surface\init.h">
+ <Filter>src\core\surface</Filter>
+ </ClInclude>
<ClInclude Include="..\..\src\core\surface\lame_client.h">
<Filter>src\core\surface</Filter>
</ClInclude>
diff --git a/vsprojects/vs2013/grpc_shared.vcxproj b/vsprojects/vs2013/grpc_shared.vcxproj
index 4b2f1e7..5c2e23b 100644
--- a/vsprojects/vs2013/grpc_shared.vcxproj
+++ b/vsprojects/vs2013/grpc_shared.vcxproj
@@ -164,6 +164,7 @@
<ClInclude Include="..\..\src\core\surface\client.h" />
<ClInclude Include="..\..\src\core\surface\completion_queue.h" />
<ClInclude Include="..\..\src\core\surface\event_string.h" />
+ <ClInclude Include="..\..\src\core\surface\init.h" />
<ClInclude Include="..\..\src\core\surface\lame_client.h" />
<ClInclude Include="..\..\src\core\surface\server.h" />
<ClInclude Include="..\..\src\core\surface\surface_trace.h" />
@@ -223,6 +224,8 @@
</ClCompile>
<ClCompile Include="..\..\src\core\security\server_secure_chttp2.c">
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\init_secure.c">
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\secure_channel_create.c">
</ClCompile>
<ClCompile Include="..\..\src\core\surface\secure_server_create.c">
@@ -381,6 +384,8 @@
</ClCompile>
<ClCompile Include="..\..\src\core\surface\server_create.c">
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\surface_trace.c">
+ </ClCompile>
<ClCompile Include="..\..\src\core\transport\chttp2\alpn.c">
</ClCompile>
<ClCompile Include="..\..\src\core\transport\chttp2\bin_encoder.c">
diff --git a/vsprojects/vs2013/grpc_shared.vcxproj.filters b/vsprojects/vs2013/grpc_shared.vcxproj.filters
index 867e545..9fc70e7 100644
--- a/vsprojects/vs2013/grpc_shared.vcxproj.filters
+++ b/vsprojects/vs2013/grpc_shared.vcxproj.filters
@@ -49,6 +49,9 @@
<ClCompile Include="..\..\src\core\security\server_secure_chttp2.c">
<Filter>src\core\security</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\init_secure.c">
+ <Filter>src\core\surface</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\core\surface\secure_channel_create.c">
<Filter>src\core\surface</Filter>
</ClCompile>
@@ -286,6 +289,9 @@
<ClCompile Include="..\..\src\core\surface\server_create.c">
<Filter>src\core\surface</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\surface_trace.c">
+ <Filter>src\core\surface</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\core\transport\chttp2\alpn.c">
<Filter>src\core\transport\chttp2</Filter>
</ClCompile>
@@ -590,6 +596,9 @@
<ClInclude Include="..\..\src\core\surface\event_string.h">
<Filter>src\core\surface</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\core\surface\init.h">
+ <Filter>src\core\surface</Filter>
+ </ClInclude>
<ClInclude Include="..\..\src\core\surface\lame_client.h">
<Filter>src\core\surface</Filter>
</ClInclude>
diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj b/vsprojects/vs2013/grpc_unsecure.vcxproj
index 0c81ec4..9181db0 100644
--- a/vsprojects/vs2013/grpc_unsecure.vcxproj
+++ b/vsprojects/vs2013/grpc_unsecure.vcxproj
@@ -145,6 +145,7 @@
<ClInclude Include="..\..\src\core\surface\client.h" />
<ClInclude Include="..\..\src\core\surface\completion_queue.h" />
<ClInclude Include="..\..\src\core\surface\event_string.h" />
+ <ClInclude Include="..\..\src\core\surface\init.h" />
<ClInclude Include="..\..\src\core\surface\lame_client.h" />
<ClInclude Include="..\..\src\core\surface\server.h" />
<ClInclude Include="..\..\src\core\surface\surface_trace.h" />
@@ -172,6 +173,8 @@
<ClInclude Include="..\..\src\core\transport\transport_impl.h" />
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="..\..\src\core\surface\init_unsecure.c">
+ </ClCompile>
<ClCompile Include="..\..\src\core\channel\call_op_string.c">
</ClCompile>
<ClCompile Include="..\..\src\core\channel\census_filter.c">
@@ -320,6 +323,8 @@
</ClCompile>
<ClCompile Include="..\..\src\core\surface\server_create.c">
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\surface_trace.c">
+ </ClCompile>
<ClCompile Include="..\..\src\core\transport\chttp2\alpn.c">
</ClCompile>
<ClCompile Include="..\..\src\core\transport\chttp2\bin_encoder.c">
diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters
index 4b5370a..4583fa4 100644
--- a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters
+++ b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
+ <ClCompile Include="..\..\src\core\surface\init_unsecure.c">
+ <Filter>src\core\surface</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\core\channel\call_op_string.c">
<Filter>src\core\channel</Filter>
</ClCompile>
@@ -223,6 +226,9 @@
<ClCompile Include="..\..\src\core\surface\server_create.c">
<Filter>src\core\surface</Filter>
</ClCompile>
+ <ClCompile Include="..\..\src\core\surface\surface_trace.c">
+ <Filter>src\core\surface</Filter>
+ </ClCompile>
<ClCompile Include="..\..\src\core\transport\chttp2\alpn.c">
<Filter>src\core\transport\chttp2</Filter>
</ClCompile>
@@ -482,6 +488,9 @@
<ClInclude Include="..\..\src\core\surface\event_string.h">
<Filter>src\core\surface</Filter>
</ClInclude>
+ <ClInclude Include="..\..\src\core\surface\init.h">
+ <Filter>src\core\surface</Filter>
+ </ClInclude>
<ClInclude Include="..\..\src\core\surface\lame_client.h">
<Filter>src\core\surface</Filter>
</ClInclude>