diff options
Diffstat (limited to 'test/cpp/microbenchmarks/bm_chttp2_hpack.cc')
-rw-r--r-- | test/cpp/microbenchmarks/bm_chttp2_hpack.cc | 99 |
1 files changed, 47 insertions, 52 deletions
diff --git a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc index adbfa4d796..13b0e0dd7f 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_hpack.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_hpack.cc @@ -40,14 +40,14 @@ auto &force_library_initialization = Library::get(); static void BM_HpackEncoderInitDestroy(benchmark::State &state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + ExecCtx _local_exec_ctx; grpc_chttp2_hpack_compressor c; while (state.KeepRunning()) { grpc_chttp2_hpack_compressor_init(&c); - grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &c); - grpc_exec_ctx_flush(&exec_ctx); + grpc_chttp2_hpack_compressor_destroy(&c); + grpc_exec_ctx_flush(); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_exec_ctx_finish(); track_counters.Finish(state); } BENCHMARK(BM_HpackEncoderInitDestroy); @@ -55,17 +55,16 @@ BENCHMARK(BM_HpackEncoderInitDestroy); template <class Fixture> static void BM_HpackEncoderEncodeHeader(benchmark::State &state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + ExecCtx _local_exec_ctx; static bool logged_representative_output = false; grpc_metadata_batch b; grpc_metadata_batch_init(&b); - std::vector<grpc_mdelem> elems = Fixture::GetElems(&exec_ctx); + std::vector<grpc_mdelem> elems = Fixture::GetElems(); std::vector<grpc_linked_mdelem> storage(elems.size()); for (size_t i = 0; i < elems.size(); i++) { GPR_ASSERT(GRPC_LOG_IF_ERROR( - "addmd", - grpc_metadata_batch_add_tail(&exec_ctx, &b, &storage[i], elems[i]))); + "addmd", grpc_metadata_batch_add_tail(&b, &storage[i], elems[i]))); } grpc_chttp2_hpack_compressor c; @@ -82,7 +81,7 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State &state) { (size_t)state.range(1), &stats, }; - grpc_chttp2_encode_header(&exec_ctx, &c, NULL, 0, &b, &hopt, &outbuf); + grpc_chttp2_encode_header(&c, NULL, 0, &b, &hopt, &outbuf); if (!logged_representative_output && state.iterations() > 3) { logged_representative_output = true; for (size_t i = 0; i < outbuf.count; i++) { @@ -91,13 +90,13 @@ static void BM_HpackEncoderEncodeHeader(benchmark::State &state) { gpr_free(s); } } - grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &outbuf); - grpc_exec_ctx_flush(&exec_ctx); + grpc_slice_buffer_reset_and_unref_internal(&outbuf); + grpc_exec_ctx_flush(); } - grpc_metadata_batch_destroy(&exec_ctx, &b); - grpc_chttp2_hpack_compressor_destroy(&exec_ctx, &c); - grpc_slice_buffer_destroy_internal(&exec_ctx, &outbuf); - grpc_exec_ctx_finish(&exec_ctx); + grpc_metadata_batch_destroy(&b); + grpc_chttp2_hpack_compressor_destroy(&c); + grpc_slice_buffer_destroy_internal(&outbuf); + grpc_exec_ctx_finish(); std::ostringstream label; label << "framing_bytes/iter:" << (static_cast<double>(stats.framing_bytes) / @@ -113,15 +112,13 @@ namespace hpack_encoder_fixtures { class EmptyBatch { public: static constexpr bool kEnableTrueBinary = false; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { - return {}; - } + static std::vector<grpc_mdelem> GetElems() { return {}; } }; class SingleStaticElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { + static std::vector<grpc_mdelem> GetElems() { return {GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE}; } }; @@ -129,9 +126,9 @@ class SingleStaticElem { class SingleInternedElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { + static std::vector<grpc_mdelem> GetElems() { return {grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), + grpc_slice_intern(grpc_slice_from_static_string("abc")), grpc_slice_intern(grpc_slice_from_static_string("def")))}; } }; @@ -140,10 +137,10 @@ template <int kLength, bool kTrueBinary> class SingleInternedBinaryElem { public: static constexpr bool kEnableTrueBinary = kTrueBinary; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { + static std::vector<grpc_mdelem> GetElems() { grpc_slice bytes = MakeBytes(); std::vector<grpc_mdelem> out = {grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc-bin")), + grpc_slice_intern(grpc_slice_from_static_string("abc-bin")), grpc_slice_intern(bytes))}; grpc_slice_unref(bytes); return out; @@ -162,9 +159,9 @@ class SingleInternedBinaryElem { class SingleInternedKeyElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { + static std::vector<grpc_mdelem> GetElems() { return {grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), + grpc_slice_intern(grpc_slice_from_static_string("abc")), grpc_slice_from_static_string("def"))}; } }; @@ -172,9 +169,8 @@ class SingleInternedKeyElem { class SingleNonInternedElem { public: static constexpr bool kEnableTrueBinary = false; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { - return {grpc_mdelem_from_slices(exec_ctx, - grpc_slice_from_static_string("abc"), + static std::vector<grpc_mdelem> GetElems() { + return {grpc_mdelem_from_slices(grpc_slice_from_static_string("abc"), grpc_slice_from_static_string("def"))}; } }; @@ -183,9 +179,9 @@ template <int kLength, bool kTrueBinary> class SingleNonInternedBinaryElem { public: static constexpr bool kEnableTrueBinary = kTrueBinary; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { - return {grpc_mdelem_from_slices( - exec_ctx, grpc_slice_from_static_string("abc-bin"), MakeBytes())}; + static std::vector<grpc_mdelem> GetElems() { + return {grpc_mdelem_from_slices(grpc_slice_from_static_string("abc-bin"), + MakeBytes())}; } private: @@ -201,20 +197,20 @@ class SingleNonInternedBinaryElem { class RepresentativeClientInitialMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { + static std::vector<grpc_mdelem> GetElems() { return { GRPC_MDELEM_SCHEME_HTTP, GRPC_MDELEM_METHOD_POST, grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_PATH, + GRPC_MDSTR_PATH, grpc_slice_intern(grpc_slice_from_static_string("/foo/bar"))), - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_mdelem_from_slices(GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_static_string( "foo.test.google.fr:1234"))), GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP, GRPC_MDELEM_TE_TRAILERS, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_USER_AGENT, + GRPC_MDSTR_USER_AGENT, grpc_slice_intern(grpc_slice_from_static_string( "grpc-c/3.0.0-dev (linux; chttp2; green)")))}; } @@ -223,7 +219,7 @@ class RepresentativeClientInitialMetadata { class RepresentativeServerInitialMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { + static std::vector<grpc_mdelem> GetElems() { return {GRPC_MDELEM_STATUS_200, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC, GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP}; @@ -233,7 +229,7 @@ class RepresentativeServerInitialMetadata { class RepresentativeServerTrailingMetadata { public: static constexpr bool kEnableTrueBinary = true; - static std::vector<grpc_mdelem> GetElems(grpc_exec_ctx *exec_ctx) { + static std::vector<grpc_mdelem> GetElems() { return {GRPC_MDELEM_GRPC_STATUS_0}; } }; @@ -331,46 +327,45 @@ BENCHMARK_TEMPLATE(BM_HpackEncoderEncodeHeader, static void BM_HpackParserInitDestroy(benchmark::State &state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + ExecCtx _local_exec_ctx; grpc_chttp2_hpack_parser p; while (state.KeepRunning()) { - grpc_chttp2_hpack_parser_init(&exec_ctx, &p); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &p); - grpc_exec_ctx_flush(&exec_ctx); + grpc_chttp2_hpack_parser_init(&p); + grpc_chttp2_hpack_parser_destroy(&p); + grpc_exec_ctx_flush(); } - grpc_exec_ctx_finish(&exec_ctx); + grpc_exec_ctx_finish(); track_counters.Finish(state); } BENCHMARK(BM_HpackParserInitDestroy); -static void UnrefHeader(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem md) { - GRPC_MDELEM_UNREF(exec_ctx, md); +static void UnrefHeader(void *user_data, grpc_mdelem md) { + GRPC_MDELEM_UNREF(md); } template <class Fixture> static void BM_HpackParserParseHeader(benchmark::State &state) { TrackCounters track_counters; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + ExecCtx _local_exec_ctx; std::vector<grpc_slice> init_slices = Fixture::GetInitSlices(); std::vector<grpc_slice> benchmark_slices = Fixture::GetBenchmarkSlices(); grpc_chttp2_hpack_parser p; - grpc_chttp2_hpack_parser_init(&exec_ctx, &p); + grpc_chttp2_hpack_parser_init(&p); p.on_header = UnrefHeader; p.on_header_user_data = nullptr; for (auto slice : init_slices) { - grpc_chttp2_hpack_parser_parse(&exec_ctx, &p, slice); + grpc_chttp2_hpack_parser_parse(&p, slice); } while (state.KeepRunning()) { for (auto slice : benchmark_slices) { - grpc_chttp2_hpack_parser_parse(&exec_ctx, &p, slice); + grpc_chttp2_hpack_parser_parse(&p, slice); } - grpc_exec_ctx_flush(&exec_ctx); + grpc_exec_ctx_flush(); } for (auto slice : init_slices) grpc_slice_unref(slice); for (auto slice : benchmark_slices) grpc_slice_unref(slice); - grpc_chttp2_hpack_parser_destroy(&exec_ctx, &p); - grpc_exec_ctx_finish(&exec_ctx); + grpc_chttp2_hpack_parser_destroy(&p); + grpc_exec_ctx_finish(); track_counters.Finish(state); } |