diff options
author | 2015-02-20 15:31:21 -0800 | |
---|---|---|
committer | 2015-02-20 15:31:21 -0800 | |
commit | 6e7c62285c235ad0f83be9f87d48a0f33a7d2032 (patch) | |
tree | 9e924a5f45f8467d5f16ebbf51595a7e147a3420 /src/core/iomgr/tcp_posix.c | |
parent | 00bdbe64a0a5410bc03a8935d4edc83469964aee (diff) |
Add a facility to control tracing without recompiling
This will help greatly when it comes to diagnosing customer issues.
Diffstat (limited to 'src/core/iomgr/tcp_posix.c')
-rw-r--r-- | src/core/iomgr/tcp_posix.c | 39 |
1 files changed, 20 insertions, 19 deletions
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); |