diff options
author | Craig Tiller <ctiller@google.com> | 2017-10-12 09:33:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-12 09:33:27 -0700 |
commit | 313db433f263061db7083d058ef3e3cef03dc3dd (patch) | |
tree | 85d4fa5f5939f2b76fb1e831b628ac1d9eeced05 /src/core/lib/surface | |
parent | c39b6cf1aac2873536a6d2b7ebd7d147f60de077 (diff) | |
parent | 8454252631e48369901da74b62233b020abd661a (diff) |
Merge pull request #12808 from sreecha/cq_stats
Counter for number of trylocks (successes/failures) and transient pop-failures in cq
Diffstat (limited to 'src/core/lib/surface')
-rw-r--r-- | src/core/lib/surface/completion_queue.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index 36b4b835f8..21664f03c8 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -362,11 +362,24 @@ static bool cq_event_queue_push(grpc_cq_event_queue *q, grpc_cq_completion *c) { static grpc_cq_completion *cq_event_queue_pop(grpc_cq_event_queue *q) { grpc_cq_completion *c = NULL; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + if (gpr_spinlock_trylock(&q->queue_lock)) { - c = (grpc_cq_completion *)gpr_mpscq_pop(&q->queue); + GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_SUCCESSES(&exec_ctx); + + bool is_empty = false; + c = (grpc_cq_completion *)gpr_mpscq_pop_and_check_end(&q->queue, &is_empty); gpr_spinlock_unlock(&q->queue_lock); + + if (c == NULL && !is_empty) { + GRPC_STATS_INC_CQ_EV_QUEUE_TRANSIENT_POP_FAILURES(&exec_ctx); + } + } else { + GRPC_STATS_INC_CQ_EV_QUEUE_TRYLOCK_FAILURES(&exec_ctx); } + grpc_exec_ctx_finish(&exec_ctx); + if (c) { gpr_atm_no_barrier_fetch_add(&q->num_queue_items, -1); } |