Add channel refcount debugging

pull/1888/head
Craig Tiller 10 years ago
parent 16a3e1394f
commit 9ec2a520ee
  1. 4
      src/core/surface/call.c
  2. 26
      src/core/surface/channel.c
  3. 15
      src/core/surface/channel.h
  4. 6
      src/core/surface/server.c

@ -280,7 +280,7 @@ grpc_call *grpc_call_create(grpc_channel *channel, grpc_completion_queue *cq,
}
call->send_initial_metadata_count = add_initial_metadata_count;
call->send_deadline = send_deadline;
grpc_channel_internal_ref(channel);
GRPC_CHANNEL_INTERNAL_REF(channel, "call");
call->metadata_context = grpc_channel_get_metadata_context(channel);
grpc_sopb_init(&call->send_ops);
grpc_sopb_init(&call->recv_ops);
@ -333,7 +333,7 @@ static void destroy_call(void *call, int ignored_success) {
size_t i;
grpc_call *c = call;
grpc_call_stack_destroy(CALL_STACK_FROM_CALL(c));
grpc_channel_internal_unref(c->channel);
GRPC_CHANNEL_INTERNAL_UNREF(c->channel, "call");
gpr_mu_destroy(&c->mu);
for (i = 0; i < STATUS_SOURCE_COUNT; i++) {
if (c->status[i].details) {

@ -168,8 +168,14 @@ grpc_call *grpc_channel_create_registered_call(
grpc_mdelem_ref(rc->authority), deadline);
}
void grpc_channel_internal_ref(grpc_channel *channel) {
gpr_ref(&channel->refs);
#ifdef GRPC_CHANNEL_REF_COUNT_DEBUG
void grpc_channel_internal_ref(grpc_channel *c, const char *reason) {
gpr_log(GPR_DEBUG, "CHANNEL: ref %p %d -> %d [%s]", c, c->refs.count,
c->refs.count + 1, reason);
#else
void grpc_channel_internal_ref(grpc_channel *c) {
#endif
gpr_ref(&c->refs);
}
static void destroy_channel(void *p, int ok) {
@ -191,9 +197,15 @@ static void destroy_channel(void *p, int ok) {
gpr_free(channel);
}
void grpc_channel_internal_unref(grpc_channel *channel) {
if (gpr_unref(&channel->refs)) {
grpc_iomgr_add_callback(destroy_channel, channel);
#ifdef GRPC_CHANNEL_REF_COUNT_DEBUG
void grpc_channel_internal_unref(grpc_channel *c, const char *reason) {
gpr_log(GPR_DEBUG, "CHANNEL: unref %p %d -> %d [%s]", c, c->refs.count,
c->refs.count - 1, reason);
#else
void grpc_channel_internal_unref(grpc_channel *c) {
#endif
if (gpr_unref(&c->refs)) {
grpc_iomgr_add_callback(destroy_channel, c);
}
}
@ -213,11 +225,11 @@ void grpc_channel_destroy(grpc_channel *channel) {
op.dir = GRPC_CALL_DOWN;
elem->filter->channel_op(elem, NULL, &op);
grpc_channel_internal_unref(channel);
GRPC_CHANNEL_INTERNAL_UNREF(channel, "channel");
}
void grpc_client_channel_closed(grpc_channel_element *elem) {
grpc_channel_internal_unref(CHANNEL_FROM_TOP_ELEM(elem));
GRPC_CHANNEL_INTERNAL_UNREF(CHANNEL_FROM_TOP_ELEM(elem), "closed");
}
grpc_channel_stack *grpc_channel_get_channel_stack(grpc_channel *channel) {

@ -48,7 +48,22 @@ gpr_uint32 grpc_channel_get_max_message_length(grpc_channel *channel);
void grpc_client_channel_closed(grpc_channel_element *elem);
#define GRPC_CHANNEL_REF_COUNT_DEBUG
#ifdef GRPC_CHANNEL_REF_COUNT_DEBUG
void grpc_channel_internal_ref(grpc_channel *channel, const char *reason);
void grpc_channel_internal_unref(grpc_channel *channel, const char *reason);
#define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \
grpc_channel_internal_ref(channel, reason)
#define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \
grpc_channel_internal_unref(channel, reason)
#else
void grpc_channel_internal_ref(grpc_channel *channel);
void grpc_channel_internal_unref(grpc_channel *channel);
#define GRPC_CHANNEL_INTERNAL_REF(channel, reason) \
grpc_channel_internal_ref(channel)
#define GRPC_CHANNEL_INTERNAL_UNREF(channel, reason) \
grpc_channel_internal_unref(channel)
#endif
#endif /* GRPC_INTERNAL_CORE_SURFACE_CHANNEL_H */

@ -306,7 +306,7 @@ static void orphan_channel(channel_data *chand) {
static void finish_destroy_channel(void *cd, int success) {
channel_data *chand = cd;
grpc_server *server = chand->server;
grpc_channel_internal_unref(chand->channel);
GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "server");
server_unref(server);
}
@ -573,14 +573,14 @@ static void finish_shutdown_channel(void *p, int success) {
grpc_channel_get_channel_stack(sca->chand->channel), 0),
NULL, &op);
}
grpc_channel_internal_unref(sca->chand->channel);
GRPC_CHANNEL_INTERNAL_UNREF(sca->chand->channel, "shutdown");
}
static void shutdown_channel(channel_data *chand, int send_goaway,
int send_disconnect) {
shutdown_channel_args *sca;
gpr_log(GPR_DEBUG, "shutdown_channel: %p %d %d", chand, send_goaway, send_disconnect);
grpc_channel_internal_ref(chand->channel);
GRPC_CHANNEL_INTERNAL_REF(chand->channel, "shutdown");
sca = gpr_malloc(sizeof(shutdown_channel_args));
sca->chand = chand;
sca->send_goaway = send_goaway;

Loading…
Cancel
Save