diff options
author | Craig Tiller <ctiller@google.com> | 2017-07-20 08:53:29 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2017-07-20 08:53:29 -0700 |
commit | 6f1a054d8f74ab8d03fdf8e913cc56b137061b71 (patch) | |
tree | 1e448493f2e0ae1c8ca2bb38b2b0468f63f665cb /src/core/lib/iomgr | |
parent | 1ab56d8a89fd6495eaa74d2046aeaf7f8f972ac8 (diff) |
Wrap tracers
Diffstat (limited to 'src/core/lib/iomgr')
-rw-r--r-- | src/core/lib/iomgr/ev_poll_posix.c | 14 | ||||
-rw-r--r-- | src/core/lib/iomgr/tcp_posix.c | 73 |
2 files changed, 61 insertions, 26 deletions
diff --git a/src/core/lib/iomgr/ev_poll_posix.c b/src/core/lib/iomgr/ev_poll_posix.c index 54577f733e..593d53e4eb 100644 --- a/src/core/lib/iomgr/ev_poll_posix.c +++ b/src/core/lib/iomgr/ev_poll_posix.c @@ -961,7 +961,9 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, r = grpc_poll_function(pfds, pfd_count, timeout); GRPC_SCHEDULING_END_BLOCKING_REGION; - gpr_log(GPR_DEBUG, "%p poll=%d", pollset, r); + if (GRPC_TRACER_ON(grpc_polling_trace)) { + gpr_log(GPR_DEBUG, "%p poll=%d", pollset, r); + } if (r < 0) { if (errno != EINTR) { @@ -983,7 +985,7 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, } } else { if (pfds[0].revents & POLLIN_CHECK) { - gpr_log(GPR_DEBUG, "%p: got_wakeup", pollset); + if (GRPC_TRACER_ON(grpc_polling_trace)){gpr_log(GPR_DEBUG, "%p: got_wakeup", pollset);} work_combine_error( &error, grpc_wakeup_fd_consume_wakeup(&worker.wakeup_fd->fd)); } @@ -991,9 +993,11 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, if (watchers[i].fd == NULL) { fd_end_poll(exec_ctx, &watchers[i], 0, 0, NULL); } else { - gpr_log(GPR_DEBUG, "%p got_event: %d r:%d w:%d [%d]", pollset, - pfds[i].fd, (pfds[i].revents & POLLIN_CHECK) != 0, - (pfds[i].revents & POLLOUT_CHECK) != 0, pfds[i].revents); + if (GRPC_TRACER_ON(grpc_polling_trace)) { + gpr_log(GPR_DEBUG, "%p got_event: %d r:%d w:%d [%d]", pollset, + pfds[i].fd, (pfds[i].revents & POLLIN_CHECK) != 0, + (pfds[i].revents & POLLOUT_CHECK) != 0, pfds[i].revents); + } fd_end_poll(exec_ctx, &watchers[i], pfds[i].revents & POLLIN_CHECK, pfds[i].revents & POLLOUT_CHECK, pollset); } diff --git a/src/core/lib/iomgr/tcp_posix.c b/src/core/lib/iomgr/tcp_posix.c index e1d8861541..c6ec472392 100644 --- a/src/core/lib/iomgr/tcp_posix.c +++ b/src/core/lib/iomgr/tcp_posix.c @@ -121,7 +121,9 @@ static void tcp_drop_uncovered_then_handle_write(grpc_exec_ctx *exec_ctx, static void done_poller(grpc_exec_ctx *exec_ctx, void *bp, grpc_error *error_ignored) { backup_poller *p = (backup_poller *)bp; - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p destroy", p); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p destroy", p); + } grpc_pollset_destroy(exec_ctx, BACKUP_POLLER_POLLSET(p)); gpr_free(p); } @@ -129,7 +131,9 @@ static void done_poller(grpc_exec_ctx *exec_ctx, void *bp, static void run_poller(grpc_exec_ctx *exec_ctx, void *bp, grpc_error *error_ignored) { backup_poller *p = (backup_poller *)bp; - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p run", p); + } gpr_mu_lock(p->pollset_mu); GRPC_LOG_IF_ERROR("backup_poller:pollset_work", grpc_pollset_work(exec_ctx, BACKUP_POLLER_POLLSET(p), NULL, @@ -137,10 +141,14 @@ static void run_poller(grpc_exec_ctx *exec_ctx, void *bp, gpr_inf_future(GPR_CLOCK_MONOTONIC))); gpr_mu_unlock(p->pollset_mu); if (gpr_atm_no_barrier_load(&g_backup_poller) == (gpr_atm)p) { - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p reschedule", p); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p reschedule", p); + } GRPC_CLOSURE_SCHED(exec_ctx, &p->run_poller, GRPC_ERROR_NONE); } else { - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p shutdown", p); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p shutdown", p); + } grpc_pollset_shutdown(exec_ctx, BACKUP_POLLER_POLLSET(p), GRPC_CLOSURE_INIT(&p->run_poller, done_poller, p, grpc_schedule_on_exec_ctx)); @@ -151,12 +159,16 @@ static void drop_uncovered(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { backup_poller *p = (backup_poller *)gpr_atm_no_barrier_load(&g_backup_poller); gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, -1); - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, (int)old_count, - (int)old_count - 1); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p uncover cnt %d->%d", p, (int)old_count, + (int)old_count - 1); + } if (old_count == 1) { gpr_mu_lock(p->pollset_mu); bool cas_ok = gpr_atm_no_barrier_cas(&g_backup_poller, (gpr_atm)p, 0); - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p done cas_ok=%d", p, cas_ok); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p done cas_ok=%d", p, cas_ok); + } GRPC_LOG_IF_ERROR("backup_poller:pollset_kick", grpc_pollset_kick(BACKUP_POLLER_POLLSET(p), NULL)); gpr_mu_unlock(p->pollset_mu); @@ -167,11 +179,15 @@ static void cover_self(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { backup_poller *p; gpr_atm old_count = gpr_atm_no_barrier_fetch_add(&g_uncovered_notifications_pending, 2); - gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", (int)old_count, - 2 + (int)old_count); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "BACKUP_POLLER: cover cnt %d->%d", (int)old_count, + 2 + (int)old_count); + } if (old_count == 0) { p = (backup_poller *)gpr_malloc(sizeof(*p) + grpc_pollset_size()); - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p create", p); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p create", p); + } grpc_pollset_init(BACKUP_POLLER_POLLSET(p), &p->pollset_mu); gpr_atm_no_barrier_store(&g_backup_poller, (gpr_atm)p); GRPC_CLOSURE_SCHED( @@ -183,20 +199,26 @@ static void cover_self(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { p = (backup_poller *)gpr_atm_no_barrier_load(&g_backup_poller); GPR_ASSERT(p != NULL); } - gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p add %p", p, tcp); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "BACKUP_POLLER:%p add %p", p, tcp); + } grpc_pollset_add_fd(exec_ctx, BACKUP_POLLER_POLLSET(p), tcp->em_fd); drop_uncovered(exec_ctx, tcp); } static void notify_on_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { - gpr_log(GPR_DEBUG, "TCP:%p notify_on_read", tcp); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "TCP:%p notify_on_read", tcp); + } GRPC_CLOSURE_INIT(&tcp->read_done_closure, tcp_handle_read, tcp, grpc_schedule_on_exec_ctx); grpc_fd_notify_on_read(exec_ctx, tcp->em_fd, &tcp->read_done_closure); } static void notify_on_write(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { - gpr_log(GPR_DEBUG, "TCP:%p notify_on_write", tcp); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "TCP:%p notify_on_write", tcp); + } cover_self(exec_ctx, tcp); GRPC_CLOSURE_INIT(&tcp->write_done_closure, tcp_drop_uncovered_then_handle_write, tcp, @@ -206,7 +228,9 @@ static void notify_on_write(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { static void tcp_drop_uncovered_then_handle_write(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - gpr_log(GPR_DEBUG, "TCP:%p got_write: %s", arg, grpc_error_string(error)); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "TCP:%p got_write: %s", arg, grpc_error_string(error)); + } drop_uncovered(exec_ctx, (grpc_tcp *)arg); tcp_handle_write(exec_ctx, arg, error); } @@ -325,9 +349,8 @@ static void call_read_cb(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, grpc_error *error) { grpc_closure *cb = tcp->read_cb; - gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg); - if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg); size_t i; const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "read: error=%s", str); @@ -418,8 +441,10 @@ static void tcp_do_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { static void tcp_read_allocation_done(grpc_exec_ctx *exec_ctx, void *tcpp, grpc_error *error) { grpc_tcp *tcp = (grpc_tcp *)tcpp; - gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp, - grpc_error_string(error)); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp, + grpc_error_string(error)); + } if (error != GRPC_ERROR_NONE) { grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, @@ -435,11 +460,15 @@ static void tcp_continue_read(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp) { size_t target_read_size = get_target_read_size(tcp); if (tcp->incoming_buffer->length < target_read_size && tcp->incoming_buffer->count < MAX_READ_IOVEC) { - gpr_log(GPR_DEBUG, "TCP:%p alloc_slices", tcp); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "TCP:%p alloc_slices", tcp); + } grpc_resource_user_alloc_slices(exec_ctx, &tcp->slice_allocator, target_read_size, 1, tcp->incoming_buffer); } else { - gpr_log(GPR_DEBUG, "TCP:%p do_read", tcp); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "TCP:%p do_read", tcp); + } tcp_do_read(exec_ctx, tcp); } } @@ -448,7 +477,9 @@ static void tcp_handle_read(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */, grpc_error *error) { grpc_tcp *tcp = (grpc_tcp *)arg; GPR_ASSERT(!tcp->finished_edge); - gpr_log(GPR_DEBUG, "TCP:%p got_read: %s", tcp, grpc_error_string(error)); + if (GRPC_TRACER_ON(grpc_tcp_trace)) { + gpr_log(GPR_DEBUG, "TCP:%p got_read: %s", tcp, grpc_error_string(error)); + } if (error != GRPC_ERROR_NONE) { grpc_slice_buffer_reset_and_unref_internal(exec_ctx, tcp->incoming_buffer); |