Add a benchmark of repeatedly adding an fd to a pollset

pull/10507/head
Craig Tiller 8 years ago
parent cd0354b851
commit d6255951dc
  1. 27
      test/cpp/microbenchmarks/bm_pollset.cc

@ -149,6 +149,33 @@ static void BM_PollEmptyPollset(benchmark::State& state) {
}
BENCHMARK(BM_PollEmptyPollset);
static void BM_PollAddFd(benchmark::State& state) {
TrackCounters track_counters;
size_t ps_sz = grpc_pollset_size();
grpc_pollset* ps = static_cast<grpc_pollset*>(gpr_zalloc(ps_sz));
gpr_mu* mu;
grpc_pollset_init(ps, &mu);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_wakeup_fd wakeup_fd;
GPR_ASSERT(GRPC_LOG_IF_ERROR("wakeup_fd_init", grpc_wakeup_fd_init(&wakeup_fd)));
grpc_fd *fd = grpc_fd_create(wakeup_fd.read_fd, "xxx");
while (state.KeepRunning()) {
grpc_pollset_add_fd(&exec_ctx, ps, fd);
grpc_exec_ctx_flush(&exec_ctx);
}
grpc_fd_orphan(&exec_ctx, fd, NULL, NULL, "xxx");
grpc_closure shutdown_ps_closure;
grpc_closure_init(&shutdown_ps_closure, shutdown_ps, ps,
grpc_schedule_on_exec_ctx);
gpr_mu_lock(mu);
grpc_pollset_shutdown(&exec_ctx, ps, &shutdown_ps_closure);
gpr_mu_unlock(mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_free(ps);
track_counters.Finish(state);
}
BENCHMARK(BM_PollAddFd);
class Closure : public grpc_closure {
public:
virtual ~Closure() {}

Loading…
Cancel
Save