aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-04-10 16:19:18 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-04-10 16:19:18 -0700
commitcd0354b851390a4db72a02f389d8dfcd7cc7e3fd (patch)
tree4d1e00cf37dd5e2d4aff4fe562acc83bdbbea296 /src
parent1814374c6958ca4a0a97f7a85e9cdcb7d5d30e82 (diff)
Add tracer
Diffstat (limited to 'src')
-rw-r--r--src/core/lib/iomgr/ev_epoll_linux.c1
-rw-r--r--src/core/lib/iomgr/ev_epollex_linux.c39
-rw-r--r--src/core/lib/iomgr/ev_posix.c5
-rw-r--r--src/core/lib/iomgr/ev_posix.h2
4 files changed, 37 insertions, 10 deletions
diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c
index d41c164d71..613b435693 100644
--- a/src/core/lib/iomgr/ev_epoll_linux.c
+++ b/src/core/lib/iomgr/ev_epoll_linux.c
@@ -66,7 +66,6 @@
#define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1)
/* TODO: sreek - Move this to init.c and initialize this like other tracers. */
-static int grpc_polling_trace = 0; /* Disabled by default */
#define GRPC_POLLING_TRACE(fmt, ...) \
if (grpc_polling_trace) { \
gpr_log(GPR_INFO, (fmt), __VA_ARGS__); \
diff --git a/src/core/lib/iomgr/ev_epollex_linux.c b/src/core/lib/iomgr/ev_epollex_linux.c
index 468acd60c7..4c35dab0c3 100644
--- a/src/core/lib/iomgr/ev_epollex_linux.c
+++ b/src/core/lib/iomgr/ev_epollex_linux.c
@@ -519,7 +519,14 @@ static void pollset_global_shutdown(void) {
/* p->po.mu must be held before calling this function */
static grpc_error *pollset_kick(grpc_pollset *p,
grpc_pollset_worker *specific_worker) {
- gpr_log(GPR_DEBUG, "PS:%p kick %p tls_pollset=%p tls_worker=%p num_pollers=%d root_worker=%p", p, specific_worker, (void*)gpr_tls_get(&g_current_thread_pollset), (void*)gpr_tls_get(&g_current_thread_worker), p->num_pollers, p->root_worker);
+ if (grpc_polling_trace) {
+ gpr_log(GPR_DEBUG,
+ "PS:%p kick %p tls_pollset=%p tls_worker=%p num_pollers=%d "
+ "root_worker=%p",
+ p, specific_worker, (void *)gpr_tls_get(&g_current_thread_pollset),
+ (void *)gpr_tls_get(&g_current_thread_worker), p->num_pollers,
+ p->root_worker);
+ }
if (specific_worker == NULL) {
if (gpr_tls_get(&g_current_thread_pollset) != (intptr_t)p) {
if (p->num_pollers == 0) {
@@ -676,19 +683,25 @@ static grpc_error *pollset_poll(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
GRPC_SCHEDULING_END_BLOCKING_REGION;
if (r < 0) return GRPC_OS_ERROR(errno, "epoll_wait");
- gpr_log(GPR_DEBUG, "PS:%p poll got %d events", pollset, r);
+ if (grpc_polling_trace) {
+ gpr_log(GPR_DEBUG, "PS:%p poll got %d events", pollset, r);
+ }
grpc_error *error = GRPC_ERROR_NONE;
for (int i = 0; i < r; i++) {
void *data_ptr = events[i].data.ptr;
if (data_ptr == &global_wakeup_fd) {
- gpr_log(GPR_DEBUG, "PS:%p poll got global_wakeup_fd", pollset);
+ if (grpc_polling_trace) {
+ gpr_log(GPR_DEBUG, "PS:%p poll got global_wakeup_fd", pollset);
+ }
grpc_timer_consume_kick();
append_error(&error, grpc_wakeup_fd_consume_wakeup(&global_wakeup_fd),
err_desc);
} else if (data_ptr == &pollset->pollset_wakeup) {
- gpr_log(GPR_DEBUG, "PS:%p poll got pollset_wakeup", pollset);
+ if (grpc_polling_trace) {
+ gpr_log(GPR_DEBUG, "PS:%p poll got pollset_wakeup", pollset);
+ }
/* once we start shutting down we stop consuming the wakeup:
the fd is level triggered and non-exclusive, which should result in all
pollers waking */
@@ -702,9 +715,11 @@ static grpc_error *pollset_poll(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
bool cancel = (events[i].events & (EPOLLERR | EPOLLHUP)) != 0;
bool read_ev = (events[i].events & (EPOLLIN | EPOLLPRI)) != 0;
bool write_ev = (events[i].events & EPOLLOUT) != 0;
- gpr_log(GPR_DEBUG,
- "PS:%p poll got fd: is_wq=%d cancel=%d read=%d write=%d", pollset,
- is_workqueue, cancel, read_ev, write_ev);
+ if (grpc_polling_trace) {
+ gpr_log(GPR_DEBUG,
+ "PS:%p poll got fd: is_wq=%d cancel=%d read=%d write=%d",
+ pollset, is_workqueue, cancel, read_ev, write_ev);
+ }
if (is_workqueue) {
append_error(&error,
grpc_wakeup_fd_consume_wakeup(&fd->workqueue_wakeup_fd),
@@ -780,7 +795,13 @@ static grpc_error *pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
grpc_pollset_worker **worker_hdl,
gpr_timespec now, gpr_timespec deadline) {
grpc_pollset_worker worker;
- gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%"PRId64".%09d deadline=%"PRId64".%09d kwp=%d root_worker=%p", pollset, worker_hdl, &worker, now.tv_sec, now.tv_nsec, deadline.tv_sec, deadline.tv_nsec, pollset->kicked_without_poller, pollset->root_worker);
+ if (grpc_polling_trace) {
+ gpr_log(GPR_DEBUG, "PS:%p work hdl=%p worker=%p now=%" PRId64
+ ".%09d deadline=%" PRId64 ".%09d kwp=%d root_worker=%p",
+ pollset, worker_hdl, &worker, now.tv_sec, now.tv_nsec,
+ deadline.tv_sec, deadline.tv_nsec, pollset->kicked_without_poller,
+ pollset->root_worker);
+ }
grpc_error *error = GRPC_ERROR_NONE;
if (pollset->kicked_without_poller) {
pollset->kicked_without_poller = false;
@@ -820,7 +841,7 @@ static void pollset_add_fd(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset,
}
}
struct epoll_event ev_wq = {.events = EPOLLET | EPOLLIN | EPOLLEXCLUSIVE,
- .data.ptr = (void*)(1+(intptr_t)fd)};
+ .data.ptr = (void *)(1 + (intptr_t)fd)};
if (epoll_ctl(pollset->epfd, EPOLL_CTL_ADD, fd->workqueue_wakeup_fd.read_fd,
&ev_wq) != 0) {
switch (errno) {
diff --git a/src/core/lib/iomgr/ev_posix.c b/src/core/lib/iomgr/ev_posix.c
index 2663152aec..a8252b0162 100644
--- a/src/core/lib/iomgr/ev_posix.c
+++ b/src/core/lib/iomgr/ev_posix.c
@@ -44,11 +44,14 @@
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
+#include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/ev_epoll_linux.h"
#include "src/core/lib/iomgr/ev_epollex_linux.h"
#include "src/core/lib/iomgr/ev_poll_posix.h"
#include "src/core/lib/support/env.h"
+int grpc_polling_trace = 0; /* Disabled by default */
+
/** Default poll() function - a pointer so that it can be overridden by some
* tests */
grpc_poll_function_type grpc_poll_function = poll;
@@ -117,6 +120,8 @@ static void try_engine(const char *engine) {
const char *grpc_get_poll_strategy_name() { return g_poll_strategy_name; }
void grpc_event_engine_init(void) {
+ grpc_register_tracer("polling", &grpc_polling_trace);
+
char *s = gpr_getenv("GRPC_POLL_STRATEGY");
if (s == NULL) {
s = gpr_strdup("all");
diff --git a/src/core/lib/iomgr/ev_posix.h b/src/core/lib/iomgr/ev_posix.h
index 1a9e5c115a..7ce1e06f20 100644
--- a/src/core/lib/iomgr/ev_posix.h
+++ b/src/core/lib/iomgr/ev_posix.h
@@ -42,6 +42,8 @@
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
#include "src/core/lib/iomgr/workqueue.h"
+extern int grpc_polling_trace; /* Disabled by default */
+
typedef struct grpc_fd grpc_fd;
typedef struct grpc_event_engine_vtable {