aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/channel/channel_stack.h14
-rw-r--r--src/core/debug/trace.c105
-rw-r--r--src/core/debug/trace.h51
-rw-r--r--src/core/iomgr/tcp_posix.c39
-rw-r--r--src/core/security/secure_endpoint.c35
-rw-r--r--src/core/surface/init.c4
-rw-r--r--src/core/surface/surface_trace.h13
7 files changed, 203 insertions, 58 deletions
diff --git a/src/core/channel/channel_stack.h b/src/core/channel/channel_stack.h
index 98d095fccf..1ca95e7f1a 100644
--- a/src/core/channel/channel_stack.h
+++ b/src/core/channel/channel_stack.h
@@ -45,10 +45,9 @@
#include <grpc/grpc.h>
#include <grpc/support/log.h>
+#include "src/core/debug/trace.h"
#include "src/core/transport/transport.h"
-/* #define GRPC_CHANNEL_STACK_TRACE 1 */
-
typedef struct grpc_channel_element grpc_channel_element;
typedef struct grpc_call_element grpc_call_element;
@@ -246,9 +245,7 @@ typedef struct {
/* A call stack tracks a set of related filters for one call, and guarantees
they live within a single malloc() allocation */
-typedef struct {
- size_t count;
-} grpc_call_stack;
+typedef struct { size_t count; } grpc_call_stack;
/* Get a channel element given a channel stack and its index */
grpc_channel_element *grpc_channel_stack_element(grpc_channel_stack *stack,
@@ -301,12 +298,7 @@ void grpc_call_element_recv_metadata(grpc_call_element *cur_elem,
void grpc_call_element_send_cancel(grpc_call_element *cur_elem);
void grpc_call_element_send_finish(grpc_call_element *cur_elem);
-#ifdef GRPC_CHANNEL_STACK_TRACE
-#define GRPC_CALL_LOG_OP(sev, elem, op) grpc_call_log_op(sev, elem, op)
-#else
#define GRPC_CALL_LOG_OP(sev, elem, op) \
- do { \
- } while (0)
-#endif
+ if (grpc_trace_bits & GRPC_TRACE_CHANNEL) grpc_call_log_op(sev, elem, op)
#endif /* __GRPC_INTERNAL_CHANNEL_CHANNEL_STACK_H__ */
diff --git a/src/core/debug/trace.c b/src/core/debug/trace.c
new file mode 100644
index 0000000000..157a4d5f34
--- /dev/null
+++ b/src/core/debug/trace.c
@@ -0,0 +1,105 @@
+/*
+ *
+ * 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/debug/trace.h"
+
+#include <string.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include "src/core/support/env.h"
+
+gpr_uint32 grpc_trace_bits;
+
+static void add(const char *beg, const char *end, char ***ss, size_t *ns) {
+ size_t n = *ns;
+ size_t np = n + 1;
+ char *s = gpr_malloc(end - beg + 1);
+ memcpy(s, beg, end - beg);
+ s[end-beg] = 0;
+ *ss = gpr_realloc(*ss, sizeof(char**) * np);
+ (*ss)[n] = s;
+ *ns = np;
+}
+
+static void split(const char *s, char ***ss, size_t *ns) {
+ const char *c = strchr(s, ',');
+ if (c == NULL) {
+ add(s, s + strlen(s), ss, ns);
+ } else {
+ add(s, c, ss, ns);
+ split(c+1, ss, ns);
+ }
+}
+
+static void parse(const char *s) {
+ char **strings = NULL;
+ size_t nstrings = 0;
+ size_t i;
+ 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, "all")) {
+ grpc_trace_bits = -1;
+ } else {
+ gpr_log(GPR_ERROR, "Unknown trace var: '%s'", s);
+ }
+ }
+
+ for (i = 0; i < nstrings; i++) {
+ gpr_free(strings[i]);
+ }
+ gpr_free(strings);
+}
+
+void grpc_init_trace_bits() {
+ char *e = gpr_getenv("GRPC_TRACE");
+ if (e == NULL) {
+ grpc_trace_bits = 0;
+ } else {
+ parse(e);
+ gpr_free(e);
+ }
+}
+
diff --git a/src/core/debug/trace.h b/src/core/debug/trace.h
new file mode 100644
index 0000000000..337e871aaa
--- /dev/null
+++ b/src/core/debug/trace.h
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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_CORE_DEBUG_TRACE_H
+#define GRPC_CORE_DEBUG_TRACE_H
+
+#include <grpc/support/port_platform.h>
+
+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_bit_value;
+
+extern gpr_uint32 grpc_trace_bits;
+
+void grpc_init_trace_bits();
+
+#endif
+
diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c
index 34eefc126b..eceb0feadb 100644
--- a/src/core/iomgr/tcp_posix.c
+++ b/src/core/iomgr/tcp_posix.c
@@ -45,6 +45,7 @@
#include <unistd.h>
#include "src/core/support/string.h"
+#include "src/core/debug/trace.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/slice.h>
@@ -293,17 +294,17 @@ static void call_read_cb(grpc_tcp *tcp, gpr_slice *slices, size_t nslices,
grpc_endpoint_cb_status status) {
grpc_endpoint_read_cb cb = tcp->read_cb;
-#ifdef GRPC_TRACE_TCP
- size_t i;
- gpr_log(GPR_DEBUG, "read: status=%d", status);
- for (i = 0; i < nslices; i++) {
- char *dump =
- gpr_hexdump((char *)GPR_SLICE_START_PTR(slices[i]),
- GPR_SLICE_LENGTH(slices[i]), GPR_HEXDUMP_PLAINTEXT);
- gpr_log(GPR_DEBUG, "READ: %s", dump);
- gpr_free(dump);
+ if (grpc_trace_bits & GRPC_TRACE_TCP) {
+ size_t i;
+ gpr_log(GPR_DEBUG, "read: status=%d", status);
+ for (i = 0; i < nslices; i++) {
+ char *dump =
+ gpr_hexdump((char *)GPR_SLICE_START_PTR(slices[i]),
+ GPR_SLICE_LENGTH(slices[i]), GPR_HEXDUMP_PLAINTEXT);
+ gpr_log(GPR_DEBUG, "READ: %s", dump);
+ gpr_free(dump);
+ }
}
-#endif
tcp->read_cb = NULL;
cb(tcp->read_user_data, slices, nslices, status);
@@ -494,17 +495,17 @@ static grpc_endpoint_write_status grpc_tcp_write(grpc_endpoint *ep,
grpc_tcp *tcp = (grpc_tcp *)ep;
grpc_endpoint_write_status status;
-#ifdef GRPC_TRACE_TCP
- size_t i;
+ if (grpc_trace_bits & GRPC_TRACE_TCP) {
+ size_t i;
- for (i = 0; i < nslices; i++) {
- char *data =
- gpr_hexdump((char *)GPR_SLICE_START_PTR(slices[i]),
- GPR_SLICE_LENGTH(slices[i]), GPR_HEXDUMP_PLAINTEXT);
- gpr_log(GPR_DEBUG, "WRITE %p: %s", tcp, data);
- gpr_free(data);
+ for (i = 0; i < nslices; i++) {
+ char *data =
+ gpr_hexdump((char *)GPR_SLICE_START_PTR(slices[i]),
+ GPR_SLICE_LENGTH(slices[i]), GPR_HEXDUMP_PLAINTEXT);
+ gpr_log(GPR_DEBUG, "WRITE %p: %s", tcp, data);
+ gpr_free(data);
+ }
}
-#endif
GPR_ASSERT(tcp->write_cb == NULL);
slice_state_init(&tcp->write_state, slices, nslices, nslices);
diff --git a/src/core/security/secure_endpoint.c b/src/core/security/secure_endpoint.c
index 031f23dc79..d6bdf5a709 100644
--- a/src/core/security/secure_endpoint.c
+++ b/src/core/security/secure_endpoint.c
@@ -39,6 +39,7 @@
#include <grpc/support/slice.h>
#include <grpc/support/sync.h>
#include "src/core/tsi/transport_security_interface.h"
+#include "src/core/debug/trace.h"
#define STAGING_BUFFER_SIZE 8192
@@ -95,16 +96,16 @@ static void flush_read_staging_buffer(secure_endpoint *ep, gpr_uint8 **cur,
static void call_read_cb(secure_endpoint *ep, gpr_slice *slices, size_t nslices,
grpc_endpoint_cb_status error) {
-#ifdef GRPC_TRACE_SECURE_TRANSPORT
- size_t i;
- for (i = 0; i < nslices; i++) {
- char *data =
- gpr_hexdump((char *)GPR_SLICE_START_PTR(slices[i]),
- GPR_SLICE_LENGTH(slices[i]), GPR_HEXDUMP_PLAINTEXT);
- gpr_log(GPR_DEBUG, "READ %p: %s", ep, data);
- gpr_free(data);
+ if (grpc_trace_bits & GRPC_TRACE_SECURE_ENDPOINT) {
+ size_t i;
+ for (i = 0; i < nslices; i++) {
+ char *data =
+ gpr_hexdump((char *)GPR_SLICE_START_PTR(slices[i]),
+ GPR_SLICE_LENGTH(slices[i]), GPR_HEXDUMP_PLAINTEXT);
+ gpr_log(GPR_DEBUG, "READ %p: %s", ep, data);
+ gpr_free(data);
+ }
}
-#endif
ep->read_cb(ep->read_user_data, slices, nslices, error);
secure_endpoint_unref(ep);
}
@@ -230,15 +231,15 @@ static grpc_endpoint_write_status endpoint_write(grpc_endpoint *secure_ep,
grpc_endpoint_write_status status;
GPR_ASSERT(ep->output_buffer.count == 0);
-#ifdef GRPC_TRACE_SECURE_TRANSPORT
- for (i = 0; i < nslices; i++) {
- char *data =
- gpr_hexdump((char *)GPR_SLICE_START_PTR(slices[i]),
- GPR_SLICE_LENGTH(slices[i]), GPR_HEXDUMP_PLAINTEXT);
- gpr_log(GPR_DEBUG, "WRITE %p: %s", ep, data);
- gpr_free(data);
+ if (grpc_trace_bits & GRPC_TRACE_SECURE_ENDPOINT) {
+ for (i = 0; i < nslices; i++) {
+ char *data =
+ gpr_hexdump((char *)GPR_SLICE_START_PTR(slices[i]),
+ GPR_SLICE_LENGTH(slices[i]), GPR_HEXDUMP_PLAINTEXT);
+ gpr_log(GPR_DEBUG, "WRITE %p: %s", ep, data);
+ gpr_free(data);
+ }
}
-#endif
for (i = 0; i < nslices; i++) {
gpr_slice plain = slices[i];
diff --git a/src/core/surface/init.c b/src/core/surface/init.c
index 43c9906a8a..fa4614abc8 100644
--- a/src/core/surface/init.c
+++ b/src/core/surface/init.c
@@ -32,8 +32,9 @@
*/
#include <grpc/grpc.h>
-#include "src/core/statistics/census_interface.h"
#include "src/core/iomgr/iomgr.h"
+#include "src/core/debug/trace.h"
+#include "src/core/statistics/census_interface.h"
static gpr_once g_init = GPR_ONCE_INIT;
static gpr_mu g_init_mu;
@@ -49,6 +50,7 @@ void grpc_init(void) {
gpr_mu_lock(&g_init_mu);
if (++g_initializations == 1) {
+ grpc_init_trace_bits();
grpc_iomgr_init();
census_init();
}
diff --git a/src/core/surface/surface_trace.h b/src/core/surface/surface_trace.h
index f998de1ad6..4d478d6470 100644
--- a/src/core/surface/surface_trace.h
+++ b/src/core/surface/surface_trace.h
@@ -34,21 +34,14 @@
#ifndef __GRPC_INTERNAL_SURFACE_SURFACE_TRACE_H__
#define __GRPC_INTERNAL_SURFACE_SURFACE_TRACE_H__
+#include "src/core/debug/trace.h"
#include <grpc/support/log.h>
-/* #define GRPC_ENABLE_SURFACE_TRACE 1 */
-
-#ifdef GRPC_ENABLE_SURFACE_TRACE
#define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \
- do { \
+ if (grpc_trace_bits & GRPC_TRACE_SURFACE) { \
char *_ev = grpc_event_string(event); \
gpr_log(GPR_INFO, "RETURN_EVENT[%p]: %s", cq, _ev); \
gpr_free(_ev); \
- } while (0)
-#else
-#define GRPC_SURFACE_TRACE_RETURNED_EVENT(cq, event) \
- do { \
- } while (0)
-#endif
+ }
#endif /* __GRPC_INTERNAL_SURFACE_SURFACE_TRACE_H__ */