From 6e7c62285c235ad0f83be9f87d48a0f33a7d2032 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 20 Feb 2015 15:31:21 -0800 Subject: [PATCH 1/2] Add a facility to control tracing without recompiling This will help greatly when it comes to diagnosing customer issues. --- Makefile | 5 + build.json | 2 + src/core/channel/channel_stack.h | 14 +-- src/core/debug/trace.c | 105 ++++++++++++++++++ src/core/debug/trace.h | 51 +++++++++ src/core/iomgr/tcp_posix.c | 39 +++---- src/core/security/secure_endpoint.c | 35 +++--- src/core/surface/init.c | 4 +- src/core/surface/surface_trace.h | 13 +-- vsprojects/vs2013/grpc.vcxproj | 3 + vsprojects/vs2013/grpc.vcxproj.filters | 9 ++ vsprojects/vs2013/grpc_shared.vcxproj | 3 + vsprojects/vs2013/grpc_shared.vcxproj.filters | 9 ++ vsprojects/vs2013/grpc_unsecure.vcxproj | 3 + .../vs2013/grpc_unsecure.vcxproj.filters | 9 ++ 15 files changed, 246 insertions(+), 58 deletions(-) create mode 100644 src/core/debug/trace.c create mode 100644 src/core/debug/trace.h diff --git a/Makefile b/Makefile index fe6368d5704..5c618d30224 100644 --- a/Makefile +++ b/Makefile @@ -2262,6 +2262,7 @@ LIBGRPC_SRC = \ src/core/channel/noop_filter.c \ src/core/compression/algorithm.c \ src/core/compression/message_compress.c \ + src/core/debug/trace.c \ src/core/httpcli/format_request.c \ src/core/httpcli/httpcli.c \ src/core/httpcli/httpcli_security_context.c \ @@ -2401,6 +2402,7 @@ src/core/channel/metadata_buffer.c: $(OPENSSL_DEP) src/core/channel/noop_filter.c: $(OPENSSL_DEP) src/core/compression/algorithm.c: $(OPENSSL_DEP) src/core/compression/message_compress.c: $(OPENSSL_DEP) +src/core/debug/trace.c: $(OPENSSL_DEP) src/core/httpcli/format_request.c: $(OPENSSL_DEP) src/core/httpcli/httpcli.c: $(OPENSSL_DEP) src/core/httpcli/httpcli_security_context.c: $(OPENSSL_DEP) @@ -2557,6 +2559,7 @@ $(OBJDIR)/$(CONFIG)/src/core/channel/metadata_buffer.o: $(OBJDIR)/$(CONFIG)/src/core/channel/noop_filter.o: $(OBJDIR)/$(CONFIG)/src/core/compression/algorithm.o: $(OBJDIR)/$(CONFIG)/src/core/compression/message_compress.o: +$(OBJDIR)/$(CONFIG)/src/core/debug/trace.o: $(OBJDIR)/$(CONFIG)/src/core/httpcli/format_request.o: $(OBJDIR)/$(CONFIG)/src/core/httpcli/httpcli.o: $(OBJDIR)/$(CONFIG)/src/core/httpcli/httpcli_security_context.o: @@ -2734,6 +2737,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/channel/noop_filter.c \ src/core/compression/algorithm.c \ src/core/compression/message_compress.c \ + src/core/debug/trace.c \ src/core/httpcli/format_request.c \ src/core/httpcli/httpcli.c \ src/core/httpcli/httpcli_security_context.c \ @@ -2874,6 +2878,7 @@ $(OBJDIR)/$(CONFIG)/src/core/channel/metadata_buffer.o: $(OBJDIR)/$(CONFIG)/src/core/channel/noop_filter.o: $(OBJDIR)/$(CONFIG)/src/core/compression/algorithm.o: $(OBJDIR)/$(CONFIG)/src/core/compression/message_compress.o: +$(OBJDIR)/$(CONFIG)/src/core/debug/trace.o: $(OBJDIR)/$(CONFIG)/src/core/httpcli/format_request.o: $(OBJDIR)/$(CONFIG)/src/core/httpcli/httpcli.o: $(OBJDIR)/$(CONFIG)/src/core/httpcli/httpcli_security_context.o: diff --git a/build.json b/build.json index fca657866a8..172753ba4ac 100644 --- a/build.json +++ b/build.json @@ -32,6 +32,7 @@ "src/core/channel/noop_filter.h", "src/core/compression/algorithm.h", "src/core/compression/message_compress.h", + "src/core/debug/trace.h", "src/core/httpcli/format_request.h", "src/core/httpcli/httpcli.h", "src/core/httpcli/httpcli_security_context.h", @@ -124,6 +125,7 @@ "src/core/channel/noop_filter.c", "src/core/compression/algorithm.c", "src/core/compression/message_compress.c", + "src/core/debug/trace.c", "src/core/httpcli/format_request.c", "src/core/httpcli/httpcli.c", "src/core/httpcli/httpcli_security_context.c", diff --git a/src/core/channel/channel_stack.h b/src/core/channel/channel_stack.h index 98d095fccf1..1ca95e7f1a6 100644 --- a/src/core/channel/channel_stack.h +++ b/src/core/channel/channel_stack.h @@ -45,10 +45,9 @@ #include #include +#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 00000000000..157a4d5f34c --- /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 + +#include +#include +#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 00000000000..337e871aaab --- /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 + +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 34eefc126bf..eceb0feadb1 100644 --- a/src/core/iomgr/tcp_posix.c +++ b/src/core/iomgr/tcp_posix.c @@ -45,6 +45,7 @@ #include #include "src/core/support/string.h" +#include "src/core/debug/trace.h" #include #include #include @@ -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 031f23dc79d..d6bdf5a709f 100644 --- a/src/core/security/secure_endpoint.c +++ b/src/core/security/secure_endpoint.c @@ -39,6 +39,7 @@ #include #include #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 43c9906a8a4..fa4614abc84 100644 --- a/src/core/surface/init.c +++ b/src/core/surface/init.c @@ -32,8 +32,9 @@ */ #include -#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 f998de1ad6a..4d478d6470e 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 -/* #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__ */ diff --git a/vsprojects/vs2013/grpc.vcxproj b/vsprojects/vs2013/grpc.vcxproj index f51122d1b17..a7ecf5e5bfd 100644 --- a/vsprojects/vs2013/grpc.vcxproj +++ b/vsprojects/vs2013/grpc.vcxproj @@ -109,6 +109,7 @@ + @@ -240,6 +241,8 @@ + + diff --git a/vsprojects/vs2013/grpc.vcxproj.filters b/vsprojects/vs2013/grpc.vcxproj.filters index 9aed6670514..8626604551c 100644 --- a/vsprojects/vs2013/grpc.vcxproj.filters +++ b/vsprojects/vs2013/grpc.vcxproj.filters @@ -82,6 +82,9 @@ src\core\compression + + src\core\debug + src\core\httpcli @@ -422,6 +425,9 @@ src\core\compression + + src\core\debug + src\core\httpcli @@ -668,6 +674,9 @@ {263cb913-dfe6-42a4-096b-cac231f76305} + + {1da7ef8a-a06d-5499-b3de-19fee4a4214d} + {a9bc00ad-835f-c625-c6d9-6a1324f98b9f} diff --git a/vsprojects/vs2013/grpc_shared.vcxproj b/vsprojects/vs2013/grpc_shared.vcxproj index 58022a33d5b..d53abeb6d46 100644 --- a/vsprojects/vs2013/grpc_shared.vcxproj +++ b/vsprojects/vs2013/grpc_shared.vcxproj @@ -113,6 +113,7 @@ + @@ -244,6 +245,8 @@ + + diff --git a/vsprojects/vs2013/grpc_shared.vcxproj.filters b/vsprojects/vs2013/grpc_shared.vcxproj.filters index 9aed6670514..8626604551c 100644 --- a/vsprojects/vs2013/grpc_shared.vcxproj.filters +++ b/vsprojects/vs2013/grpc_shared.vcxproj.filters @@ -82,6 +82,9 @@ src\core\compression + + src\core\debug + src\core\httpcli @@ -422,6 +425,9 @@ src\core\compression + + src\core\debug + src\core\httpcli @@ -668,6 +674,9 @@ {263cb913-dfe6-42a4-096b-cac231f76305} + + {1da7ef8a-a06d-5499-b3de-19fee4a4214d} + {a9bc00ad-835f-c625-c6d9-6a1324f98b9f} diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj b/vsprojects/vs2013/grpc_unsecure.vcxproj index 8b3b853cce7..e8d0a799575 100644 --- a/vsprojects/vs2013/grpc_unsecure.vcxproj +++ b/vsprojects/vs2013/grpc_unsecure.vcxproj @@ -98,6 +98,7 @@ + @@ -205,6 +206,8 @@ + + diff --git a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters index 6fac8464227..ef82e34a62a 100644 --- a/vsprojects/vs2013/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vs2013/grpc_unsecure.vcxproj.filters @@ -46,6 +46,9 @@ src\core\compression + + src\core\debug + src\core\httpcli @@ -353,6 +356,9 @@ src\core\compression + + src\core\debug + src\core\httpcli @@ -599,6 +605,9 @@ {2e3aca1d-223d-10a1-b282-7f9fc68ee6f5} + + {6d8d5774-7291-554d-fafa-583463cd3fd9} + {1ba3a245-47e7-89b5-b0c9-aca758bd0277} From 46863cffb631c68cf302c387e4520bbbe263a43c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 20 Feb 2015 15:58:05 -0800 Subject: [PATCH 2/2] Make it possible to compile out tracing --- src/core/debug/trace.c | 5 +++++ src/core/debug/trace.h | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/core/debug/trace.c b/src/core/debug/trace.c index 157a4d5f34c..cdbe168fc85 100644 --- a/src/core/debug/trace.c +++ b/src/core/debug/trace.c @@ -39,6 +39,7 @@ #include #include "src/core/support/env.h" +#if GRPC_ENABLE_TRACING gpr_uint32 grpc_trace_bits; static void add(const char *beg, const char *end, char ***ss, size_t *ns) { @@ -102,4 +103,8 @@ void grpc_init_trace_bits() { 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 337e871aaab..167ef3c6ea6 100644 --- a/src/core/debug/trace.h +++ b/src/core/debug/trace.h @@ -36,6 +36,11 @@ #include +/* 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, @@ -43,7 +48,11 @@ typedef enum { GRPC_TRACE_SECURE_ENDPOINT = 1 << 3 } 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();