diff --git a/src/core/lib/debug/trace_impl.h b/src/core/lib/debug/trace_impl.h index 45d4f8cba40..4d91c374d02 100644 --- a/src/core/lib/debug/trace_impl.h +++ b/src/core/lib/debug/trace_impl.h @@ -81,10 +81,16 @@ class TraceFlag { }; #define GRPC_TRACE_FLAG_ENABLED_OBJ(obj) GPR_UNLIKELY((obj).enabled()) + #define GRPC_TRACE_FLAG_ENABLED(tracer) \ GPR_UNLIKELY((grpc_core::tracer##_trace).enabled()) + #define GRPC_TRACE_LOG(tracer, level) \ LOG_IF(level, GRPC_TRACE_FLAG_ENABLED(tracer)) + +#define GRPC_TRACE_DLOG(tracer, level) \ + DLOG_IF(level, GRPC_TRACE_FLAG_ENABLED(tracer)) + #define GRPC_TRACE_VLOG(tracer, level) \ if (GRPC_TRACE_FLAG_ENABLED(tracer)) VLOG(level) diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index c8983966ada..d23c976ca46 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -42,18 +42,6 @@ #include "src/core/lib/iomgr/internal_errqueue.h" #include "src/core/util/useful.h" -// Traces fd create/close operations - -// Polling API trace only enabled in debug builds -#ifndef NDEBUG -#define GRPC_POLLING_API_TRACE(format, ...) \ - if (GRPC_TRACE_FLAG_ENABLED(polling_api)) { \ - LOG(INFO) << "(polling-api) " << absl::StrFormat(format, __VA_ARGS__); \ - } -#else -#define GRPC_POLLING_API_TRACE(...) -#endif // NDEBUG - /// Default poll() function - a pointer so that it can be overridden by some /// tests #ifndef GPR_AIX @@ -165,7 +153,8 @@ bool grpc_event_engine_run_in_background(void) { } grpc_fd* grpc_fd_create(int fd, const char* name, bool track_err) { - GRPC_POLLING_API_TRACE("fd_create(%d, %s, %d)", fd, name, track_err); + GRPC_TRACE_DLOG(polling_api, INFO) << "(polling-api) fd_create(" << fd << ", " + << name << ", " << track_err << ")"; GRPC_TRACE_LOG(fd_trace, INFO) << "(fd-trace) fd_create(" << fd << ", " << name << ", " << track_err << ")"; return g_event_engine->fd_create( @@ -178,8 +167,9 @@ int grpc_fd_wrapped_fd(grpc_fd* fd) { void grpc_fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, const char* reason) { - GRPC_POLLING_API_TRACE("fd_orphan(%d, %p, %p, %s)", grpc_fd_wrapped_fd(fd), - on_done, release_fd, reason); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) fd_orphan(" << grpc_fd_wrapped_fd(fd) << ", " << on_done + << ", " << release_fd << ", " << reason << ")"; GRPC_TRACE_LOG(fd_trace, INFO) << "(fd-trace) grpc_fd_orphan, fd:" << grpc_fd_wrapped_fd(fd) << " closed"; @@ -188,14 +178,16 @@ void grpc_fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, } void grpc_fd_set_pre_allocated(grpc_fd* fd) { - GRPC_POLLING_API_TRACE("fd_set_pre_allocated(%d)", grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) fd_set_pre_allocated(" << grpc_fd_wrapped_fd(fd) << ")"; GRPC_TRACE_LOG(fd_trace, INFO) << "(fd-trace) fd_set_pre_allocated(" << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->fd_set_pre_allocated(fd); } void grpc_fd_shutdown(grpc_fd* fd, grpc_error_handle why) { - GRPC_POLLING_API_TRACE("fd_shutdown(%d)", grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_LOG(polling_api, INFO) + << "(polling-api) fd_shutdown(" << grpc_fd_wrapped_fd(fd) << ")"; GRPC_TRACE_LOG(fd_trace, INFO) << "(fd-trace) fd_shutdown(" << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->fd_shutdown(fd, why); @@ -226,41 +218,48 @@ void grpc_fd_set_error(grpc_fd* fd) { g_event_engine->fd_set_error(fd); } static size_t pollset_size(void) { return g_event_engine->pollset_size; } static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { - GRPC_POLLING_API_TRACE("pollset_init(%p)", pollset); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_init(" << pollset << ")"; g_event_engine->pollset_init(pollset, mu); } static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { - GRPC_POLLING_API_TRACE("pollset_shutdown(%p)", pollset); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_shutdown(" << pollset << ")"; g_event_engine->pollset_shutdown(pollset, closure); } static void pollset_destroy(grpc_pollset* pollset) { - GRPC_POLLING_API_TRACE("pollset_destroy(%p)", pollset); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_destroy(" << pollset << ")"; g_event_engine->pollset_destroy(pollset); } static grpc_error_handle pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker, grpc_core::Timestamp deadline) { - GRPC_POLLING_API_TRACE("pollset_work(%p, %" PRId64 ") begin", pollset, - deadline.milliseconds_after_process_epoch()); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_work(" << pollset << ", " + << deadline.milliseconds_after_process_epoch() << ") begin"; grpc_error_handle err = g_event_engine->pollset_work(pollset, worker, deadline); - GRPC_POLLING_API_TRACE("pollset_work(%p, %" PRId64 ") end", pollset, - deadline.milliseconds_after_process_epoch()); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_work(" << pollset << ", " + << deadline.milliseconds_after_process_epoch() << ") end"; return err; } static grpc_error_handle pollset_kick(grpc_pollset* pollset, grpc_pollset_worker* specific_worker) { - GRPC_POLLING_API_TRACE("pollset_kick(%p, %p)", pollset, specific_worker); + GRPC_TRACE_DLOG(polling_api, INFO) << "(polling-api) pollset_kick(" << pollset + << ", " << specific_worker << ")"; return g_event_engine->pollset_kick(pollset, specific_worker); } void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd) { - GRPC_POLLING_API_TRACE("pollset_add_fd(%p, %d)", pollset, - grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_add_fd(" << pollset << ", " + << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->pollset_add_fd(pollset, fd); } @@ -275,38 +274,44 @@ grpc_pollset_vtable grpc_posix_pollset_vtable = { static grpc_pollset_set* pollset_set_create(void) { grpc_pollset_set* pss = g_event_engine->pollset_set_create(); - GRPC_POLLING_API_TRACE("pollset_set_create(%p)", pss); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_create(" << pss << ")"; return pss; } static void pollset_set_destroy(grpc_pollset_set* pollset_set) { - GRPC_POLLING_API_TRACE("pollset_set_destroy(%p)", pollset_set); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_destroy(" << pollset_set << ")"; g_event_engine->pollset_set_destroy(pollset_set); } static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) { - GRPC_POLLING_API_TRACE("pollset_set_add_pollset(%p, %p)", pollset_set, - pollset); + GRPC_TRACE_DLOG(polling_api, INFO) << "(polling-api) pollset_set_add_pollset(" + << pollset_set << ", " << pollset << ")"; g_event_engine->pollset_set_add_pollset(pollset_set, pollset); } static void pollset_set_del_pollset(grpc_pollset_set* pollset_set, grpc_pollset* pollset) { - GRPC_POLLING_API_TRACE("pollset_set_del_pollset(%p, %p)", pollset_set, - pollset); + GRPC_TRACE_DLOG(polling_api, INFO) << "(polling-api) pollset_set_del_pollset(" + << pollset_set << ", " << pollset << ")"; g_event_engine->pollset_set_del_pollset(pollset_set, pollset); } static void pollset_set_add_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { - GRPC_POLLING_API_TRACE("pollset_set_add_pollset_set(%p, %p)", bag, item); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_add_pollset_set(" << bag << ", " << item + << ")"; g_event_engine->pollset_set_add_pollset_set(bag, item); } static void pollset_set_del_pollset_set(grpc_pollset_set* bag, grpc_pollset_set* item) { - GRPC_POLLING_API_TRACE("pollset_set_del_pollset_set(%p, %p)", bag, item); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_del_pollset_set(" << bag << ", " << item + << ")"; g_event_engine->pollset_set_del_pollset_set(bag, item); } @@ -316,14 +321,16 @@ grpc_pollset_set_vtable grpc_posix_pollset_set_vtable = { pollset_set_add_pollset_set, pollset_set_del_pollset_set}; void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { - GRPC_POLLING_API_TRACE("pollset_set_add_fd(%p, %d)", pollset_set, - grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_add_fd(" << pollset_set << ", " + << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->pollset_set_add_fd(pollset_set, fd); } void grpc_pollset_set_del_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { - GRPC_POLLING_API_TRACE("pollset_set_del_fd(%p, %d)", pollset_set, - grpc_fd_wrapped_fd(fd)); + GRPC_TRACE_DLOG(polling_api, INFO) + << "(polling-api) pollset_set_del_fd(" << pollset_set << ", " + << grpc_fd_wrapped_fd(fd) << ")"; g_event_engine->pollset_set_del_fd(pollset_set, fd); }