Add cq and fd tracer

pull/10833/head
ncteisen 8 years ago
parent 4b584054b9
commit d39010e68a
  1. 16
      src/core/lib/iomgr/error.c
  2. 11
      src/core/lib/iomgr/error.h
  3. 40
      src/core/lib/iomgr/ev_epollsig_linux.c
  4. 39
      src/core/lib/iomgr/ev_poll_posix.c
  5. 4
      src/core/lib/iomgr/ev_posix.h
  6. 10
      src/core/lib/iomgr/tcp_posix.c
  7. 10
      src/core/lib/iomgr/tcp_uv.c
  8. 10
      src/core/lib/iomgr/tcp_windows.c
  9. 13
      src/core/lib/security/transport/secure_endpoint.c
  10. 21
      src/core/lib/surface/completion_queue.c
  11. 6
      src/core/lib/surface/completion_queue.h
  12. 5
      src/core/lib/surface/init.c
  13. 10
      src/core/lib/surface/init_secure.c
  14. 2
      src/core/lib/transport/metadata.c

@ -124,14 +124,12 @@ bool grpc_error_is_special(grpc_error *err) {
} }
#ifndef NDEBUG #ifndef NDEBUG
grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line) {
const char *func) {
if (grpc_error_is_special(err)) return err; if (grpc_error_is_special(err)) return err;
if (GRPC_TRACER_ON(grpc_trace_error_refcount)) { if (GRPC_TRACER_ON(grpc_trace_error_refcount)) {
gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d %s]", err, gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err,
gpr_atm_no_barrier_load(&err->atomics.refs.count), gpr_atm_no_barrier_load(&err->atomics.refs.count),
gpr_atm_no_barrier_load(&err->atomics.refs.count) + 1, file, line, gpr_atm_no_barrier_load(&err->atomics.refs.count) + 1, file, line);
func);
} }
gpr_ref(&err->atomics.refs); gpr_ref(&err->atomics.refs);
return err; return err;
@ -179,14 +177,12 @@ static void error_destroy(grpc_error *err) {
} }
#ifndef NDEBUG #ifndef NDEBUG
void grpc_error_unref(grpc_error *err, const char *file, int line, void grpc_error_unref(grpc_error *err, const char *file, int line) {
const char *func) {
if (grpc_error_is_special(err)) return; if (grpc_error_is_special(err)) return;
if (GRPC_TRACER_ON(grpc_trace_error_refcount)) { if (GRPC_TRACER_ON(grpc_trace_error_refcount)) {
gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d %s]", err, gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d]", err,
gpr_atm_no_barrier_load(&err->atomics.refs.count), gpr_atm_no_barrier_load(&err->atomics.refs.count),
gpr_atm_no_barrier_load(&err->atomics.refs.count) - 1, file, line, gpr_atm_no_barrier_load(&err->atomics.refs.count) - 1, file, line);
func);
} }
if (gpr_unref(&err->atomics.refs)) { if (gpr_unref(&err->atomics.refs)) {
error_destroy(err); error_destroy(err);

@ -156,13 +156,10 @@ grpc_error *grpc_error_create(const char *file, int line, grpc_slice desc,
errs, count) errs, count)
#ifndef NDEBUG #ifndef NDEBUG
grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line);
const char *func); void grpc_error_unref(grpc_error *err, const char *file, int line);
void grpc_error_unref(grpc_error *err, const char *file, int line, #define GRPC_ERROR_REF(err) grpc_error_ref(err, __FILE__, __LINE__)
const char *func); #define GRPC_ERROR_UNREF(err) grpc_error_unref(err, __FILE__, __LINE__)
#define GRPC_ERROR_REF(err) grpc_error_ref(err, __FILE__, __LINE__, __func__)
#define GRPC_ERROR_UNREF(err) \
grpc_error_unref(err, __FILE__, __LINE__, __func__)
#else #else
grpc_error *grpc_error_ref(grpc_error *err); grpc_error *grpc_error_ref(grpc_error *err);
void grpc_error_unref(grpc_error *err); void grpc_error_unref(grpc_error *err);

@ -49,6 +49,10 @@
#define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1)
#ifndef NDEBUG
grpc_tracer_flag grpc_trace_fd_refcount = GRPC_TRACER_INITIALIZER(false);
#endif
#define GRPC_POLLING_TRACE(...) \ #define GRPC_POLLING_TRACE(...) \
if (GRPC_TRACER_ON(grpc_polling_trace)) { \ if (GRPC_TRACER_ON(grpc_polling_trace)) { \
gpr_log(GPR_INFO, __VA_ARGS__); \ gpr_log(GPR_INFO, __VA_ARGS__); \
@ -141,7 +145,7 @@ struct grpc_fd {
/* Reference counting for fds */ /* Reference counting for fds */
// #define GRPC_FD_REF_COUNT_DEBUG // #define GRPC_FD_REF_COUNT_DEBUG
#ifdef GRPC_FD_REF_COUNT_DEBUG #ifndef NDEBUG
static void fd_ref(grpc_fd *fd, const char *reason, const char *file, int line); static void fd_ref(grpc_fd *fd, const char *reason, const char *file, int line);
static void fd_unref(grpc_fd *fd, const char *reason, const char *file, static void fd_unref(grpc_fd *fd, const char *reason, const char *file,
int line); int line);
@ -167,7 +171,7 @@ static void fd_global_shutdown(void);
#define PI_UNREF(exec_ctx, p, r) \ #define PI_UNREF(exec_ctx, p, r) \
pi_unref_dbg((exec_ctx), (p), (r), __FILE__, __LINE__) pi_unref_dbg((exec_ctx), (p), (r), __FILE__, __LINE__)
#else #else
#define PI_ADD_REF(p, r) pi_add_ref((p)) #define PI_ADD_REF(p, r) pi_add_ref((p))
#define PI_UNREF(exec_ctx, p, r) pi_unref((exec_ctx), (p)) #define PI_UNREF(exec_ctx, p, r) pi_unref((exec_ctx), (p))
@ -286,13 +290,12 @@ static void pi_add_ref(polling_island *pi);
static void pi_unref(grpc_exec_ctx *exec_ctx, polling_island *pi); static void pi_unref(grpc_exec_ctx *exec_ctx, polling_island *pi);
#ifndef NDEBUG #ifndef NDEBUG
grpc_tracer_flag grpc_trace_workqueue_refcount = GRPC_TRACER_INITIALIZER(false);
static void pi_add_ref_dbg(polling_island *pi, const char *reason, static void pi_add_ref_dbg(polling_island *pi, const char *reason,
const char *file, int line) { const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_workqueue_refcount)) { if (GRPC_TRACER_ON(grpc_trace_workqueue_refcount)) {
long old_cnt = gpr_atm_acq_load(&pi->ref_count); long old_cnt = gpr_atm_acq_load(&pi->ref_count);
gpr_log(GPR_DEBUG, "Add ref pi: %p, old: %ld -> new:%ld (%s) - (%s, %d)", gpr_log(GPR_DEBUG, "Add ref pi: %p, old: %ld -> new:%ld (%s) - (%s, %d)",
(void *)pi, old_cnt, old_cnt + 1, reason, file, line); (void *)pi, old_cnt, old_cnt + 1, reason, file, line);
} }
pi_add_ref(pi); pi_add_ref(pi);
} }
@ -302,7 +305,7 @@ static void pi_unref_dbg(grpc_exec_ctx *exec_ctx, polling_island *pi,
if (GRPC_TRACER_ON(grpc_trace_workqueue_refcount)) { if (GRPC_TRACER_ON(grpc_trace_workqueue_refcount)) {
long old_cnt = gpr_atm_acq_load(&pi->ref_count); long old_cnt = gpr_atm_acq_load(&pi->ref_count);
gpr_log(GPR_DEBUG, "Unref pi: %p, old:%ld -> new:%ld (%s) - (%s, %d)", gpr_log(GPR_DEBUG, "Unref pi: %p, old:%ld -> new:%ld (%s) - (%s, %d)",
(void *)pi, old_cnt, (old_cnt - 1), reason, file, line); (void *)pi, old_cnt, (old_cnt - 1), reason, file, line);
} }
pi_unref(exec_ctx, pi); pi_unref(exec_ctx, pi);
} }
@ -723,14 +726,16 @@ static void polling_island_global_shutdown() {
static grpc_fd *fd_freelist = NULL; static grpc_fd *fd_freelist = NULL;
static gpr_mu fd_freelist_mu; static gpr_mu fd_freelist_mu;
#ifdef GRPC_FD_REF_COUNT_DEBUG #ifndef NDEBUG
#define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__) #define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__)
#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) #define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__)
static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file, static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file,
int line) { int line) {
gpr_log(GPR_DEBUG, "FD %d %p ref %d %ld -> %ld [%s; %s:%d]", fd->fd, if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) {
(void *)fd, n, gpr_atm_no_barrier_load(&fd->refst), gpr_log(GPR_DEBUG, "FD %d %p ref %d %ld -> %ld [%s; %s:%d]", fd->fd,
gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line); (void *)fd, n, gpr_atm_no_barrier_load(&fd->refst),
gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line);
}
#else #else
#define REF_BY(fd, n, reason) ref_by(fd, n) #define REF_BY(fd, n, reason) ref_by(fd, n)
#define UNREF_BY(fd, n, reason) unref_by(fd, n) #define UNREF_BY(fd, n, reason) unref_by(fd, n)
@ -739,17 +744,18 @@ static void ref_by(grpc_fd *fd, int n) {
GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0); GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0);
} }
#ifdef GRPC_FD_REF_COUNT_DEBUG #ifndef NDEBUG
static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file, static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file,
int line) { int line) {
gpr_atm old; if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) {
gpr_log(GPR_DEBUG, "FD %d %p unref %d %ld -> %ld [%s; %s:%d]", fd->fd, gpr_log(GPR_DEBUG, "FD %d %p unref %d %ld -> %ld [%s; %s:%d]", fd->fd,
(void *)fd, n, gpr_atm_no_barrier_load(&fd->refst), (void *)fd, n, gpr_atm_no_barrier_load(&fd->refst),
gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line); gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line);
}
#else #else
static void unref_by(grpc_fd *fd, int n) { static void unref_by(grpc_fd *fd, int n) {
gpr_atm old;
#endif #endif
gpr_atm old;
old = gpr_atm_full_fetch_add(&fd->refst, -n); old = gpr_atm_full_fetch_add(&fd->refst, -n);
if (old == n) { if (old == n) {
/* Add the fd to the freelist */ /* Add the fd to the freelist */
@ -768,7 +774,7 @@ static void unref_by(grpc_fd *fd, int n) {
} }
/* Increment refcount by two to avoid changing the orphan bit */ /* Increment refcount by two to avoid changing the orphan bit */
#ifdef GRPC_FD_REF_COUNT_DEBUG #ifndef NDEBUG
static void fd_ref(grpc_fd *fd, const char *reason, const char *file, static void fd_ref(grpc_fd *fd, const char *reason, const char *file,
int line) { int line) {
ref_by(fd, 2, reason, file, line); ref_by(fd, 2, reason, file, line);
@ -836,7 +842,7 @@ static grpc_fd *fd_create(int fd, const char *name) {
char *fd_name; char *fd_name;
gpr_asprintf(&fd_name, "%s fd=%d", name, fd); gpr_asprintf(&fd_name, "%s fd=%d", name, fd);
grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name); grpc_iomgr_register_object(&new_fd->iomgr_object, fd_name);
#ifdef GRPC_FD_REF_COUNT_DEBUG #ifndef NDEBUG
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, (void *)new_fd, fd_name); gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, (void *)new_fd, fd_name);
#endif #endif
gpr_free(fd_name); gpr_free(fd_name);

@ -45,6 +45,10 @@
#define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1) #define GRPC_POLLSET_KICK_BROADCAST ((grpc_pollset_worker *)1)
#ifndef NDEBUG
grpc_tracer_flag grpc_trace_fd_refcount = GRPC_TRACER_INITIALIZER(false);
#endif
/******************************************************************************* /*******************************************************************************
* FD declarations * FD declarations
*/ */
@ -134,9 +138,7 @@ static void fd_end_poll(grpc_exec_ctx *exec_ctx, grpc_fd_watcher *rec,
/* Return 1 if this fd is orphaned, 0 otherwise */ /* Return 1 if this fd is orphaned, 0 otherwise */
static bool fd_is_orphaned(grpc_fd *fd); static bool fd_is_orphaned(grpc_fd *fd);
/* Reference counting for fds */ #ifndef NDEBUG
//#define GRPC_FD_REF_COUNT_DEBUG
#ifdef GRPC_FD_REF_COUNT_DEBUG
static void fd_ref(grpc_fd *fd, const char *reason, const char *file, int line); static void fd_ref(grpc_fd *fd, const char *reason, const char *file, int line);
static void fd_unref(grpc_fd *fd, const char *reason, const char *file, static void fd_unref(grpc_fd *fd, const char *reason, const char *file,
int line); int line);
@ -263,14 +265,16 @@ cv_fd_table g_cvfds;
* fd_posix.c * fd_posix.c
*/ */
#ifdef GRPC_FD_REF_COUNT_DEBUG #ifndef NDEBUG
#define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__) #define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__)
#define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) #define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__)
static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file, static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file,
int line) { int line) {
gpr_log(GPR_DEBUG, "FD %d %p ref %d %d -> %d [%s; %s:%d]", fd->fd, fd, n, if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) {
(int)gpr_atm_no_barrier_load(&fd->refst), gpr_log(GPR_DEBUG, "FD %d %p ref %d %d -> %d [%s; %s:%d]", fd->fd, fd, n,
(int)gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line); (int)gpr_atm_no_barrier_load(&fd->refst),
(int)gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line);
}
#else #else
#define REF_BY(fd, n, reason) ref_by(fd, n) #define REF_BY(fd, n, reason) ref_by(fd, n)
#define UNREF_BY(fd, n, reason) unref_by(fd, n) #define UNREF_BY(fd, n, reason) unref_by(fd, n)
@ -279,17 +283,18 @@ static void ref_by(grpc_fd *fd, int n) {
GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0); GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&fd->refst, n) > 0);
} }
#ifdef GRPC_FD_REF_COUNT_DEBUG #ifndef NDEBUG
static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file, static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file,
int line) { int line) {
gpr_atm old; if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) {
gpr_log(GPR_DEBUG, "FD %d %p unref %d %d -> %d [%s; %s:%d]", fd->fd, fd, n, gpr_log(GPR_DEBUG, "FD %d %p unref %d %d -> %d [%s; %s:%d]", fd->fd, fd, n,
(int)gpr_atm_no_barrier_load(&fd->refst), (int)gpr_atm_no_barrier_load(&fd->refst),
(int)gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line); (int)gpr_atm_no_barrier_load(&fd->refst) - n, reason, file, line);
}
#else #else
static void unref_by(grpc_fd *fd, int n) { static void unref_by(grpc_fd *fd, int n) {
gpr_atm old;
#endif #endif
gpr_atm old;
old = gpr_atm_full_fetch_add(&fd->refst, -n); old = gpr_atm_full_fetch_add(&fd->refst, -n);
if (old == n) { if (old == n) {
gpr_mu_destroy(&fd->mu); gpr_mu_destroy(&fd->mu);
@ -321,8 +326,10 @@ static grpc_fd *fd_create(int fd, const char *name) {
gpr_asprintf(&name2, "%s fd=%d", name, fd); gpr_asprintf(&name2, "%s fd=%d", name, fd);
grpc_iomgr_register_object(&r->iomgr_object, name2); grpc_iomgr_register_object(&r->iomgr_object, name2);
gpr_free(name2); gpr_free(name2);
#ifdef GRPC_FD_REF_COUNT_DEBUG #ifndef NDEBUG
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, r, name); if (GRPC_TRACER_ON(grpc_trace_fd_refcount)) {
gpr_log(GPR_DEBUG, "FD %d %p create %s", fd, r, name);
}
#endif #endif
return r; return r;
} }
@ -417,7 +424,7 @@ static void fd_orphan(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
} }
/* increment refcount by two to avoid changing the orphan bit */ /* increment refcount by two to avoid changing the orphan bit */
#ifdef GRPC_FD_REF_COUNT_DEBUG #ifndef NDEBUG
static void fd_ref(grpc_fd *fd, const char *reason, const char *file, static void fd_ref(grpc_fd *fd, const char *reason, const char *file,
int line) { int line) {
ref_by(fd, 2, reason, file, line); ref_by(fd, 2, reason, file, line);

@ -29,6 +29,10 @@
extern grpc_tracer_flag grpc_polling_trace; /* Disabled by default */ extern grpc_tracer_flag grpc_polling_trace; /* Disabled by default */
#ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_fd_refcount;
#endif
typedef struct grpc_fd grpc_fd; typedef struct grpc_fd grpc_fd;
typedef struct grpc_event_engine_vtable { typedef struct grpc_event_engine_vtable {

@ -171,8 +171,9 @@ static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
const char *reason, const char *file, int line) { const char *reason, const char *file, int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (GRPC_TRACER_ON(grpc_tcp_trace)) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
reason, val, val - 1); "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
val - 1);
} }
if (gpr_unref(&tcp->refcount)) { if (gpr_unref(&tcp->refcount)) {
tcp_free(exec_ctx, tcp); tcp_free(exec_ctx, tcp);
@ -183,8 +184,9 @@ static void tcp_ref(grpc_tcp *tcp, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (GRPC_TRACER_ON(grpc_tcp_trace)) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
reason, val, val + 1); "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
val + 1);
} }
gpr_ref(&tcp->refcount); gpr_ref(&tcp->refcount);
} }

@ -77,8 +77,9 @@ static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
const char *reason, const char *file, int line) { const char *reason, const char *file, int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (GRPC_TRACER_ON(grpc_tcp_trace)) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
reason, val, val - 1); "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
val - 1);
} }
if (gpr_unref(&tcp->refcount)) { if (gpr_unref(&tcp->refcount)) {
tcp_free(exec_ctx, tcp); tcp_free(exec_ctx, tcp);
@ -89,8 +90,9 @@ static void tcp_ref(grpc_tcp *tcp, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (GRPC_TRACER_ON(grpc_tcp_trace)) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
reason, val, val + 1); "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
val + 1);
} }
gpr_ref(&tcp->refcount); gpr_ref(&tcp->refcount);
} }

@ -125,8 +125,9 @@ static void tcp_unref(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp,
const char *reason, const char *file, int line) { const char *reason, const char *file, int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (GRPC_TRACER_ON(grpc_tcp_trace)) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
reason, val, val - 1); "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
val - 1);
} }
if (gpr_unref(&tcp->refcount)) { if (gpr_unref(&tcp->refcount)) {
tcp_free(exec_ctx, tcp); tcp_free(exec_ctx, tcp);
@ -137,8 +138,9 @@ static void tcp_ref(grpc_tcp *tcp, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_tcp_trace)) { if (GRPC_TRACER_ON(grpc_tcp_trace)) {
gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
reason, val, val + 1); "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val,
val + 1);
} }
gpr_ref(&tcp->refcount); gpr_ref(&tcp->refcount);
} }

@ -80,14 +80,14 @@ static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) {
secure_endpoint_unref((exec_ctx), (ep), (reason), __FILE__, __LINE__) secure_endpoint_unref((exec_ctx), (ep), (reason), __FILE__, __LINE__)
#define SECURE_ENDPOINT_REF(ep, reason) \ #define SECURE_ENDPOINT_REF(ep, reason) \
secure_endpoint_ref((ep), (reason), __FILE__, __LINE__) secure_endpoint_ref((ep), (reason), __FILE__, __LINE__)
static void secure_endpoint_unref(grpc_exec_ctx *exec_ctx, static void secure_endpoint_unref(grpc_exec_ctx *exec_ctx, secure_endpoint *ep,
secure_endpoint *ep,
const char *reason, const char *file, const char *reason, const char *file,
int line) { int line) {
if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) { if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) {
gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count); gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "SECENDP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
ep, reason, val, val - 1); "SECENDP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val,
val - 1);
} }
if (gpr_unref(&ep->ref)) { if (gpr_unref(&ep->ref)) {
destroy(exec_ctx, ep); destroy(exec_ctx, ep);
@ -98,8 +98,9 @@ static void secure_endpoint_ref(secure_endpoint *ep, const char *reason,
const char *file, int line) { const char *file, int line) {
if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) { if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) {
gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count); gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "SECENDP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
ep, reason, val, val + 1); "SECENDP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val,
val + 1);
} }
gpr_ref(&ep->ref); gpr_ref(&ep->ref);
} }

@ -38,6 +38,7 @@
grpc_tracer_flag grpc_trace_operation_failures = GRPC_TRACER_INITIALIZER(false); grpc_tracer_flag grpc_trace_operation_failures = GRPC_TRACER_INITIALIZER(false);
#ifndef NDEBUG #ifndef NDEBUG
grpc_tracer_flag grpc_trace_pending_tags = GRPC_TRACER_INITIALIZER(false); grpc_tracer_flag grpc_trace_pending_tags = GRPC_TRACER_INITIALIZER(false);
grpc_tracer_flag grpc_trace_cq_refcount = GRPC_TRACER_INITIALIZER(false);
#endif #endif
typedef struct { typedef struct {
@ -437,12 +438,15 @@ int grpc_get_cq_poll_num(grpc_completion_queue *cc) {
return cur_num_polls; return cur_num_polls;
} }
#ifdef GRPC_CQ_REF_COUNT_DEBUG #ifndef NDEBUG
void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason, void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason,
const char *file, int line) { const char *file, int line) {
cq_data *cqd = &cc->data; cq_data *cqd = &cc->data;
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "CQ:%p ref %d -> %d %s", cc, if (GRPC_TRACER_ON(grpc_trace_cq_refcount)) {
(int)cqd->owning_refs.count, (int)cqd->owning_refs.count + 1, reason); gpr_atm val = gpr_atm_no_barrier_load(&cqd->owning_refs.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "CQ:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", cc,
val, val + 1, reason);
}
#else #else
void grpc_cq_internal_ref(grpc_completion_queue *cc) { void grpc_cq_internal_ref(grpc_completion_queue *cc) {
cq_data *cqd = &cc->data; cq_data *cqd = &cc->data;
@ -456,12 +460,15 @@ static void on_pollset_shutdown_done(grpc_exec_ctx *exec_ctx, void *arg,
GRPC_CQ_INTERNAL_UNREF(exec_ctx, cc, "pollset_destroy"); GRPC_CQ_INTERNAL_UNREF(exec_ctx, cc, "pollset_destroy");
} }
#ifdef GRPC_CQ_REF_COUNT_DEBUG #ifndef NDEBUG
void grpc_cq_internal_unref(grpc_completion_queue *cc, const char *reason, void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, const char *reason,
const char *file, int line) { const char *file, int line) {
cq_data *cqd = &cc->data; cq_data *cqd = &cc->data;
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "CQ:%p unref %d -> %d %s", cc, if (GRPC_TRACER_ON(grpc_trace_cq_refcount)) {
(int)cqd->owning_refs.count, (int)cqd->owning_refs.count - 1, reason); gpr_atm val = gpr_atm_no_barrier_load(&cqd->owning_refs.count);
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "CQ:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", cc,
val, val - 1, reason);
}
#else #else
void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx,
grpc_completion_queue *cc) { grpc_completion_queue *cc) {

@ -30,8 +30,10 @@
extern grpc_tracer_flag grpc_cq_pluck_trace; extern grpc_tracer_flag grpc_cq_pluck_trace;
extern grpc_tracer_flag grpc_cq_event_timeout_trace; extern grpc_tracer_flag grpc_cq_event_timeout_trace;
extern grpc_tracer_flag grpc_trace_operation_failures; extern grpc_tracer_flag grpc_trace_operation_failures;
#ifndef NDEBUG #ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_pending_tags; extern grpc_tracer_flag grpc_trace_pending_tags;
extern grpc_tracer_flag grpc_trace_cq_refcount;
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
@ -52,9 +54,7 @@ typedef struct grpc_cq_completion {
uintptr_t next; uintptr_t next;
} grpc_cq_completion; } grpc_cq_completion;
//#define GRPC_CQ_REF_COUNT_DEBUG #ifndef NDEBUG
#ifdef GRPC_CQ_REF_COUNT_DEBUG
void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason, void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason,
const char *file, int line); const char *file, int line);
void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, void grpc_cq_internal_unref(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc,

@ -48,6 +48,7 @@
#include "src/core/lib/transport/transport_impl.h" #include "src/core/lib/transport/transport_impl.h"
#ifndef NDEBUG #ifndef NDEBUG
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/security/context/security_context.h" #include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/transport/security_connector.h" #include "src/core/lib/security/transport/security_connector.h"
#endif #endif
@ -141,12 +142,14 @@ void grpc_init(void) {
grpc_register_tracer("call_error", &grpc_call_error_trace); grpc_register_tracer("call_error", &grpc_call_error_trace);
#ifndef NDEBUG #ifndef NDEBUG
grpc_register_tracer("pending_tags", &grpc_trace_pending_tags); grpc_register_tracer("pending_tags", &grpc_trace_pending_tags);
grpc_register_tracer("queue_refcount", &grpc_trace_cq_refcount);
grpc_register_tracer("closure", &grpc_trace_closure); grpc_register_tracer("closure", &grpc_trace_closure);
grpc_register_tracer("error_refcount", &grpc_trace_error_refcount); grpc_register_tracer("error_refcount", &grpc_trace_error_refcount);
grpc_register_tracer("stream_refcount", &grpc_trace_stream_refcount); grpc_register_tracer("stream_refcount", &grpc_trace_stream_refcount);
// TODO(ncteisen): re-enable after rebasing // TODO(ncteisen): fix this after rebase
// grpc_register_tracer("auth_context_refcount", &grpc_trace_auth_context_refcount); // grpc_register_tracer("auth_context_refcount", &grpc_trace_auth_context_refcount);
// grpc_register_tracer("security_connector_refcount", &grpc_trace_security_connector_refcount); // grpc_register_tracer("security_connector_refcount", &grpc_trace_security_connector_refcount);
grpc_register_tracer("fd_refcount", &grpc_trace_fd_refcount);
grpc_register_tracer("metadata", &grpc_trace_metadata); grpc_register_tracer("metadata", &grpc_trace_metadata);
#endif #endif
grpc_security_pre_init(); grpc_security_pre_init();

@ -32,9 +32,19 @@
#include "src/core/lib/surface/channel_init.h" #include "src/core/lib/surface/channel_init.h"
#include "src/core/tsi/transport_security_interface.h" #include "src/core/tsi/transport_security_interface.h"
#ifndef NDEBUG
#include "src/core/lib/security/context/security_context.h"
#endif
void grpc_security_pre_init(void) { void grpc_security_pre_init(void) {
grpc_register_tracer("secure_endpoint", &grpc_trace_secure_endpoint); grpc_register_tracer("secure_endpoint", &grpc_trace_secure_endpoint);
grpc_register_tracer("transport_security", &tsi_tracing_enabled); grpc_register_tracer("transport_security", &tsi_tracing_enabled);
#ifndef NDEBUG
grpc_register_tracer("auth_context_refcount",
&grpc_trace_auth_context_refcount);
grpc_register_tracer("security_connector_refcount",
&grpc_trace_security_connector_refcount);
#endif
} }
static bool maybe_prepend_client_auth_filter( static bool maybe_prepend_client_auth_filter(

@ -395,7 +395,7 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) {
gpr_atm_no_barrier_load(&md->refcnt) + 1, key_str, value_str); gpr_atm_no_barrier_load(&md->refcnt) + 1, key_str, value_str);
gpr_free(key_str); gpr_free(key_str);
gpr_free(value_str); gpr_free(value_str);
} }
#endif #endif
/* we can assume the ref count is >= 1 as the application is calling /* we can assume the ref count is >= 1 as the application is calling
this function - meaning that no adjustment to mdtab_free is necessary, this function - meaning that no adjustment to mdtab_free is necessary,

Loading…
Cancel
Save