From 2bfc3bcf8df4896825986fa7eeb316de9237aa54 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 1 Mar 2017 07:54:20 -0800 Subject: [PATCH 1/2] Add fixtures for call creation benchmarks --- test/cpp/microbenchmarks/bm_call_create.cc | 45 +++++++++++++++++----- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 76d50302769..e2e5bbbe00e 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -62,21 +62,48 @@ static struct Init { ~Init() { grpc_shutdown(); } } g_init; -static void BM_InsecureChannelWithDefaults(benchmark::State &state) { - grpc_channel *channel = - grpc_insecure_channel_create("localhost:12345", NULL, NULL); +class BaseChannelFixture { + public: + BaseChannelFixture(grpc_channel *channel) : channel_(channel) {} + ~BaseChannelFixture() { grpc_channel_destroy(channel_); } + + grpc_channel *channel() const { return channel_; } + + private: + grpc_channel *const channel_; +}; + +class InsecureChannel : public BaseChannelFixture { + public: + InsecureChannel() + : BaseChannelFixture( + grpc_insecure_channel_create("localhost:1234", NULL, NULL)) {} +}; + +class LameChannel : public BaseChannelFixture { + public: + LameChannel() + : BaseChannelFixture(grpc_lame_client_channel_create( + "localhost:1234", GRPC_STATUS_UNAUTHENTICATED, "blah")) {} +}; + +template +static void BM_CallCreateDestroy(benchmark::State &state) { + Fixture fixture; grpc_completion_queue *cq = grpc_completion_queue_create(NULL); - grpc_slice method = grpc_slice_from_static_string("/foo/bar"); gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); + void *method_hdl = + grpc_channel_register_call(fixture.channel(), "/foo/bar", NULL, NULL); while (state.KeepRunning()) { - grpc_call_destroy(grpc_channel_create_call(channel, NULL, - GRPC_PROPAGATE_DEFAULTS, cq, - method, NULL, deadline, NULL)); + grpc_call_destroy(grpc_channel_create_registered_call( + fixture.channel(), NULL, GRPC_PROPAGATE_DEFAULTS, cq, method_hdl, + deadline, NULL)); } - grpc_channel_destroy(channel); grpc_completion_queue_destroy(cq); } -BENCHMARK(BM_InsecureChannelWithDefaults); + +BENCHMARK_TEMPLATE(BM_CallCreateDestroy, InsecureChannel); +BENCHMARK_TEMPLATE(BM_CallCreateDestroy, LameChannel); static void FilterDestroy(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { From 8d9d4d00fd1fb312d20953176fc0b2d3f33d1825 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 1 Mar 2017 07:57:20 -0800 Subject: [PATCH 2/2] Add benchmark to conversion script --- tools/profiling/microbenchmarks/bm2bq.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/profiling/microbenchmarks/bm2bq.py b/tools/profiling/microbenchmarks/bm2bq.py index 280f217e690..1ca0964f640 100755 --- a/tools/profiling/microbenchmarks/bm2bq.py +++ b/tools/profiling/microbenchmarks/bm2bq.py @@ -143,6 +143,10 @@ bm_specs = { 'tpl': ['fixture'], 'dyn': [], }, + 'BM_CallCreateDestroy' : { + 'tpl': ['fixture'], + 'dyn': [], + }, } def numericalize(s):