diff options
Diffstat (limited to 'test/cpp/microbenchmarks/bm_chttp2_transport.cc')
-rw-r--r-- | test/cpp/microbenchmarks/bm_chttp2_transport.cc | 186 |
1 files changed, 93 insertions, 93 deletions
diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc index e9f537faa4..154cc91778 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc @@ -35,7 +35,7 @@ #include "test/cpp/microbenchmarks/helpers.h" #include "third_party/benchmark/include/benchmark/benchmark.h" -auto &force_library_initialization = Library::get(); +auto& force_library_initialization = Library::get(); //////////////////////////////////////////////////////////////////////////////// // Helper classes @@ -58,7 +58,7 @@ class DummyEndpoint : public grpc_endpoint { ru_ = grpc_resource_user_create(Library::get().rq(), "dummy_endpoint"); } - void PushInput(grpc_exec_ctx *exec_ctx, grpc_slice slice) { + void PushInput(grpc_exec_ctx* exec_ctx, grpc_slice slice) { if (read_cb_ == nullptr) { GPR_ASSERT(!have_slice_); buffered_slice_ = slice; @@ -71,14 +71,14 @@ class DummyEndpoint : public grpc_endpoint { } private: - grpc_resource_user *ru_; - grpc_closure *read_cb_ = nullptr; - grpc_slice_buffer *slices_ = nullptr; + grpc_resource_user* ru_; + grpc_closure* read_cb_ = nullptr; + grpc_slice_buffer* slices_ = nullptr; bool have_slice_ = false; grpc_slice buffered_slice_; - void QueueRead(grpc_exec_ctx *exec_ctx, grpc_slice_buffer *slices, - grpc_closure *cb) { + void QueueRead(grpc_exec_ctx* exec_ctx, grpc_slice_buffer* slices, + grpc_closure* cb) { GPR_ASSERT(read_cb_ == nullptr); if (have_slice_) { have_slice_ = false; @@ -90,51 +90,50 @@ class DummyEndpoint : public grpc_endpoint { slices_ = slices; } - static void read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, - grpc_slice_buffer *slices, grpc_closure *cb) { - static_cast<DummyEndpoint *>(ep)->QueueRead(exec_ctx, slices, cb); + static void read(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { + static_cast<DummyEndpoint*>(ep)->QueueRead(exec_ctx, slices, cb); } - static void write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, - grpc_slice_buffer *slices, grpc_closure *cb) { + static void write(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_slice_buffer* slices, grpc_closure* cb) { GRPC_CLOSURE_SCHED(exec_ctx, cb, GRPC_ERROR_NONE); } - static grpc_workqueue *get_workqueue(grpc_endpoint *ep) { return NULL; } + static grpc_workqueue* get_workqueue(grpc_endpoint* ep) { return NULL; } - static void add_to_pollset(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, - grpc_pollset *pollset) {} + static void add_to_pollset(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset* pollset) {} - static void add_to_pollset_set(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, - grpc_pollset_set *pollset) {} + static void add_to_pollset_set(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_pollset_set* pollset) {} - static void delete_from_pollset_set(grpc_exec_ctx *exec_ctx, - grpc_endpoint *ep, - grpc_pollset_set *pollset) {} + static void delete_from_pollset_set(grpc_exec_ctx* exec_ctx, + grpc_endpoint* ep, + grpc_pollset_set* pollset) {} - static void shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, - grpc_error *why) { - grpc_resource_user_shutdown(exec_ctx, - static_cast<DummyEndpoint *>(ep)->ru_); - GRPC_CLOSURE_SCHED(exec_ctx, static_cast<DummyEndpoint *>(ep)->read_cb_, + static void shutdown(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep, + grpc_error* why) { + grpc_resource_user_shutdown(exec_ctx, static_cast<DummyEndpoint*>(ep)->ru_); + GRPC_CLOSURE_SCHED(exec_ctx, static_cast<DummyEndpoint*>(ep)->read_cb_, why); } - static void destroy(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep) { - grpc_resource_user_unref(exec_ctx, static_cast<DummyEndpoint *>(ep)->ru_); - delete static_cast<DummyEndpoint *>(ep); + static void destroy(grpc_exec_ctx* exec_ctx, grpc_endpoint* ep) { + grpc_resource_user_unref(exec_ctx, static_cast<DummyEndpoint*>(ep)->ru_); + delete static_cast<DummyEndpoint*>(ep); } - static grpc_resource_user *get_resource_user(grpc_endpoint *ep) { - return static_cast<DummyEndpoint *>(ep)->ru_; + static grpc_resource_user* get_resource_user(grpc_endpoint* ep) { + return static_cast<DummyEndpoint*>(ep)->ru_; } - static char *get_peer(grpc_endpoint *ep) { return gpr_strdup("test"); } - static int get_fd(grpc_endpoint *ep) { return 0; } + static char* get_peer(grpc_endpoint* ep) { return gpr_strdup("test"); } + static int get_fd(grpc_endpoint* ep) { return 0; } }; class Fixture { public: - Fixture(const grpc::ChannelArguments &args, bool client) { + Fixture(const grpc::ChannelArguments& args, bool client) { grpc_channel_args c_args = args.c_channel_args(); ep_ = new DummyEndpoint; t_ = grpc_create_chttp2_transport(exec_ctx(), &c_args, ep_, client); @@ -149,18 +148,18 @@ class Fixture { grpc_exec_ctx_finish(&exec_ctx_); } - grpc_chttp2_transport *chttp2_transport() { - return reinterpret_cast<grpc_chttp2_transport *>(t_); + grpc_chttp2_transport* chttp2_transport() { + return reinterpret_cast<grpc_chttp2_transport*>(t_); } - grpc_transport *transport() { return t_; } - grpc_exec_ctx *exec_ctx() { return &exec_ctx_; } + grpc_transport* transport() { return t_; } + grpc_exec_ctx* exec_ctx() { return &exec_ctx_; } void PushInput(grpc_slice slice) { ep_->PushInput(exec_ctx(), slice); } private: - DummyEndpoint *ep_; + DummyEndpoint* ep_; grpc_exec_ctx exec_ctx_ = GRPC_EXEC_CTX_INIT; - grpc_transport *t_; + grpc_transport* t_; }; class Closure : public grpc_closure { @@ -170,37 +169,37 @@ class Closure : public grpc_closure { template <class F> std::unique_ptr<Closure> MakeClosure( - F f, grpc_closure_scheduler *sched = grpc_schedule_on_exec_ctx) { + F f, grpc_closure_scheduler* sched = grpc_schedule_on_exec_ctx) { struct C : public Closure { - C(const F &f, grpc_closure_scheduler *sched) : f_(f) { + C(const F& f, grpc_closure_scheduler* sched) : f_(f) { GRPC_CLOSURE_INIT(this, Execute, this, sched); } F f_; - static void Execute(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - static_cast<C *>(arg)->f_(exec_ctx, error); + static void Execute(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + static_cast<C*>(arg)->f_(exec_ctx, error); } }; return std::unique_ptr<Closure>(new C(f, sched)); } template <class F> -grpc_closure *MakeOnceClosure( - F f, grpc_closure_scheduler *sched = grpc_schedule_on_exec_ctx) { +grpc_closure* MakeOnceClosure( + F f, grpc_closure_scheduler* sched = grpc_schedule_on_exec_ctx) { struct C : public grpc_closure { - C(const F &f) : f_(f) {} + C(const F& f) : f_(f) {} F f_; - static void Execute(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - static_cast<C *>(arg)->f_(exec_ctx, error); - delete static_cast<C *>(arg); + static void Execute(grpc_exec_ctx* exec_ctx, void* arg, grpc_error* error) { + static_cast<C*>(arg)->f_(exec_ctx, error); + delete static_cast<C*>(arg); } }; - auto *c = new C{f}; + auto* c = new C{f}; return GRPC_CLOSURE_INIT(c, C::Execute, c, sched); } class Stream { public: - Stream(Fixture *f) : f_(f) { + Stream(Fixture* f) : f_(f) { stream_size_ = grpc_transport_stream_size(f->transport()); stream_ = gpr_malloc(stream_size_); arena_ = gpr_arena_create(4096); @@ -212,7 +211,7 @@ class Stream { gpr_arena_destroy(arena_); } - void Init(benchmark::State &state) { + void Init(benchmark::State& state) { GRPC_STREAM_REF_INIT(&refcount_, 1, &Stream::FinishDestroy, this, "test_stream"); gpr_event_init(&done_); @@ -222,11 +221,11 @@ class Stream { arena_ = gpr_arena_create(4096); } grpc_transport_init_stream(f_->exec_ctx(), f_->transport(), - static_cast<grpc_stream *>(stream_), &refcount_, + static_cast<grpc_stream*>(stream_), &refcount_, NULL, arena_); } - void DestroyThen(grpc_exec_ctx *exec_ctx, grpc_closure *closure) { + void DestroyThen(grpc_exec_ctx* exec_ctx, grpc_closure* closure) { destroy_closure_ = closure; #ifndef NDEBUG grpc_stream_unref(exec_ctx, &refcount_, "DestroyThen"); @@ -235,31 +234,31 @@ class Stream { #endif } - void Op(grpc_exec_ctx *exec_ctx, grpc_transport_stream_op_batch *op) { + void Op(grpc_exec_ctx* exec_ctx, grpc_transport_stream_op_batch* op) { grpc_transport_perform_stream_op(exec_ctx, f_->transport(), - static_cast<grpc_stream *>(stream_), op); + static_cast<grpc_stream*>(stream_), op); } - grpc_chttp2_stream *chttp2_stream() { - return static_cast<grpc_chttp2_stream *>(stream_); + grpc_chttp2_stream* chttp2_stream() { + return static_cast<grpc_chttp2_stream*>(stream_); } private: - static void FinishDestroy(grpc_exec_ctx *exec_ctx, void *arg, - grpc_error *error) { - auto stream = static_cast<Stream *>(arg); + static void FinishDestroy(grpc_exec_ctx* exec_ctx, void* arg, + grpc_error* error) { + auto stream = static_cast<Stream*>(arg); grpc_transport_destroy_stream(exec_ctx, stream->f_->transport(), - static_cast<grpc_stream *>(stream->stream_), + static_cast<grpc_stream*>(stream->stream_), stream->destroy_closure_); - gpr_event_set(&stream->done_, (void *)1); + gpr_event_set(&stream->done_, (void*)1); } - Fixture *f_; + Fixture* f_; grpc_stream_refcount refcount_; - gpr_arena *arena_; + gpr_arena* arena_; size_t stream_size_; - void *stream_; - grpc_closure *destroy_closure_ = nullptr; + void* stream_; + grpc_closure* destroy_closure_ = nullptr; gpr_event done_; }; @@ -267,7 +266,7 @@ class Stream { // Benchmarks // -static void BM_StreamCreateDestroy(benchmark::State &state) { +static void BM_StreamCreateDestroy(benchmark::State& state) { TrackCounters track_counters; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); @@ -278,7 +277,7 @@ static void BM_StreamCreateDestroy(benchmark::State &state) { op.payload = &op_payload; op_payload.cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; std::unique_ptr<Closure> next = - MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { + MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { if (!state.KeepRunning()) return; s.Init(state); s.Op(exec_ctx, &op); @@ -292,9 +291,10 @@ BENCHMARK(BM_StreamCreateDestroy); class RepresentativeClientInitialMetadata { public: - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { + static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx* exec_ctx) { return { - GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_METHOD_POST, + GRPC_MDELEM_SCHEME_HTTP, + GRPC_MDELEM_METHOD_POST, grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string("/foo/bar"))), @@ -312,7 +312,7 @@ class RepresentativeClientInitialMetadata { }; template <class Metadata> -static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State &state) { +static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State& state) { TrackCounters track_counters; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); @@ -339,7 +339,7 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State &state) { } f.FlushExecCtx(); - start = MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { + start = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { if (!state.KeepRunning()) return; s.Init(state); reset_op(); @@ -348,7 +348,7 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State &state) { op.payload->send_initial_metadata.send_initial_metadata = &b; s.Op(exec_ctx, &op); }); - done = MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { + done = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; @@ -363,7 +363,7 @@ static void BM_StreamCreateSendInitialMetadataDestroy(benchmark::State &state) { BENCHMARK_TEMPLATE(BM_StreamCreateSendInitialMetadataDestroy, RepresentativeClientInitialMetadata); -static void BM_TransportEmptyOp(benchmark::State &state) { +static void BM_TransportEmptyOp(benchmark::State& state) { TrackCounters track_counters; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); @@ -376,7 +376,7 @@ static void BM_TransportEmptyOp(benchmark::State &state) { op.payload = &op_payload; }; std::unique_ptr<Closure> c = - MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { + MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { if (!state.KeepRunning()) return; reset_op(); op.on_complete = c.get(); @@ -388,8 +388,8 @@ static void BM_TransportEmptyOp(benchmark::State &state) { op.cancel_stream = true; op_payload.cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; s.Op(f.exec_ctx(), &op); - s.DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx *exec_ctx, - grpc_error *error) {})); + s.DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx* exec_ctx, + grpc_error* error) {})); f.FlushExecCtx(); track_counters.Finish(state); } @@ -397,7 +397,7 @@ BENCHMARK(BM_TransportEmptyOp); std::vector<std::unique_ptr<gpr_event>> done_events; -static void BM_TransportStreamSend(benchmark::State &state) { +static void BM_TransportStreamSend(benchmark::State& state) { TrackCounters track_counters; Fixture f(grpc::ChannelArguments(), true); auto s = std::unique_ptr<Stream>(new Stream(&f)); @@ -428,13 +428,13 @@ static void BM_TransportStreamSend(benchmark::State &state) { grpc_metadata_batch_add_tail(f.exec_ctx(), &b, &storage[i], elems[i]))); } - gpr_event *bm_done = new gpr_event; + gpr_event* bm_done = new gpr_event; gpr_event_init(bm_done); std::unique_ptr<Closure> c = - MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { + MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { if (!state.KeepRunning()) { - gpr_event_set(bm_done, (void *)1); + gpr_event_set(bm_done, (void*)1); return; } // force outgoing window to be yuge @@ -462,8 +462,8 @@ static void BM_TransportStreamSend(benchmark::State &state) { op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; s->Op(f.exec_ctx(), &op); - s->DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx *exec_ctx, - grpc_error *error) {})); + s->DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx* exec_ctx, + grpc_error* error) {})); f.FlushExecCtx(); s.reset(); track_counters.Finish(state); @@ -529,7 +529,7 @@ static grpc_slice CreateIncomingDataSlice(size_t length, size_t frame_size) { return grpc_slice_from_copied_buffer(framed.data(), framed.size()); } -static void BM_TransportStreamRecv(benchmark::State &state) { +static void BM_TransportStreamRecv(benchmark::State& state) { TrackCounters track_counters; Fixture f(grpc::ChannelArguments(), true); Stream s(&f); @@ -537,7 +537,7 @@ static void BM_TransportStreamRecv(benchmark::State &state) { grpc_transport_stream_op_batch_payload op_payload; memset(&op_payload, 0, sizeof(op_payload)); grpc_transport_stream_op_batch op; - grpc_byte_stream *recv_stream; + grpc_byte_stream* recv_stream; grpc_slice incoming_data = CreateIncomingDataSlice(state.range(0), 16384); auto reset_op = [&]() { @@ -560,7 +560,7 @@ static void BM_TransportStreamRecv(benchmark::State &state) { } std::unique_ptr<Closure> do_nothing = - MakeClosure([](grpc_exec_ctx *exec_ctx, grpc_error *error) {}); + MakeClosure([](grpc_exec_ctx* exec_ctx, grpc_error* error) {}); uint32_t received; @@ -570,7 +570,7 @@ static void BM_TransportStreamRecv(benchmark::State &state) { grpc_slice recv_slice; std::unique_ptr<Closure> c = - MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { + MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { if (!state.KeepRunning()) return; // force outgoing window to be yuge s.chttp2_stream()->flow_control->TestOnlyForceHugeWindow(); @@ -585,7 +585,7 @@ static void BM_TransportStreamRecv(benchmark::State &state) { f.PushInput(grpc_slice_ref(incoming_data)); }); - drain_start = MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { + drain_start = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { if (recv_stream == NULL) { GPR_ASSERT(!state.KeepRunning()); return; @@ -593,7 +593,7 @@ static void BM_TransportStreamRecv(benchmark::State &state) { GRPC_CLOSURE_RUN(exec_ctx, drain.get(), GRPC_ERROR_NONE); }); - drain = MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { + drain = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { do { if (received == recv_stream->length) { grpc_byte_stream_destroy(exec_ctx, recv_stream); @@ -609,7 +609,7 @@ static void BM_TransportStreamRecv(benchmark::State &state) { grpc_slice_unref_internal(exec_ctx, recv_slice), true)); }); - drain_continue = MakeClosure([&](grpc_exec_ctx *exec_ctx, grpc_error *error) { + drain_continue = MakeClosure([&](grpc_exec_ctx* exec_ctx, grpc_error* error) { grpc_byte_stream_pull(exec_ctx, recv_stream, &recv_slice); received += GRPC_SLICE_LENGTH(recv_slice); grpc_slice_unref_internal(exec_ctx, recv_slice); @@ -643,8 +643,8 @@ static void BM_TransportStreamRecv(benchmark::State &state) { op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; s.Op(f.exec_ctx(), &op); - s.DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx *exec_ctx, - grpc_error *error) {})); + s.DestroyThen(f.exec_ctx(), MakeOnceClosure([](grpc_exec_ctx* exec_ctx, + grpc_error* error) {})); f.FlushExecCtx(); track_counters.Finish(state); grpc_metadata_batch_destroy(f.exec_ctx(), &b); |