profile cpp overhead for call create

pull/10622/head
Yuxuan Li 8 years ago
parent d338dd3d39
commit c7609c4f3f
  1. 79
      test/cpp/microbenchmarks/bm_call_create.cc

@ -166,6 +166,83 @@ static void BM_LameChannelCallCreateCpp(benchmark::State &state) {
}
BENCHMARK(BM_LameChannelCallCreateCpp);
static void do_nothing(void *ignored) {}
static void BM_LameChannelCallCreateCore(benchmark::State &state) {
TrackCounters track_counters;
grpc_channel *channel;
grpc_completion_queue *cq;
grpc_metadata_array initial_metadata_recv;
grpc_metadata_array trailing_metadata_recv;
grpc_byte_buffer *response_payload_recv = NULL;
grpc_status_code status;
grpc_slice details;
grpc::testing::EchoRequest send_request;
grpc_slice send_request_slice =
grpc_slice_new(&send_request, sizeof(send_request), do_nothing);
grpc_slice host = grpc_slice_from_static_string("localhost");
channel = grpc_lame_client_channel_create(
"localhost:1234", GRPC_STATUS_UNAUTHENTICATED, "blah");
cq = grpc_completion_queue_create(NULL);
while (state.KeepRunning()) {
GPR_TIMER_SCOPE("BenchmarkCycle", 0);
grpc_call *call = grpc_channel_create_call(
channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq,
grpc_slice_from_static_string("/EchoTestService/AsyncEcho"), &host,
gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
grpc_metadata_array_init(&initial_metadata_recv);
grpc_metadata_array_init(&trailing_metadata_recv);
grpc_byte_buffer *request_payload_send =
grpc_raw_byte_buffer_create(&send_request_slice, 1);
// Fill in call ops
grpc_op ops[6];
memset(ops, 0, sizeof(ops));
grpc_op *op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;
op->data.send_initial_metadata.count = 0;
op++;
op->op = GRPC_OP_SEND_MESSAGE;
op->data.send_message.send_message = request_payload_send;
op++;
op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
op++;
op->op = GRPC_OP_RECV_INITIAL_METADATA;
op->data.recv_initial_metadata.recv_initial_metadata =
&initial_metadata_recv;
op++;
op->op = GRPC_OP_RECV_MESSAGE;
op->data.recv_message.recv_message = &response_payload_recv;
op++;
op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
op->data.recv_status_on_client.status = &status;
op->data.recv_status_on_client.status_details = &details;
op++;
GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops,
(size_t)(op - ops),
(void *)1, NULL));
grpc_event ev = grpc_completion_queue_next(
cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
GPR_ASSERT(ev.type != GRPC_QUEUE_SHUTDOWN);
GPR_ASSERT(ev.success != 0);
grpc_call_destroy(call);
grpc_byte_buffer_destroy(request_payload_send);
grpc_byte_buffer_destroy(response_payload_recv);
grpc_metadata_array_destroy(&initial_metadata_recv);
grpc_metadata_array_destroy(&trailing_metadata_recv);
}
grpc_channel_destroy(channel);
grpc_completion_queue_destroy(cq);
grpc_slice_unref(send_request_slice);
track_counters.Finish(state);
}
BENCHMARK(BM_LameChannelCallCreateCore);
static void FilterDestroy(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) {
gpr_free(arg);
@ -560,7 +637,7 @@ static const grpc_channel_filter isolated_call_filter = {
GetPeer,
GetChannelInfo,
"isolated_call_filter"};
}
} // namespace isolated_call_filter
class IsolatedCallFixture : public TrackCounters {
public:

Loading…
Cancel
Save