address the reference arguments

pull/18881/head
Na-Na Pang 6 years ago
parent 714e13b426
commit 32e10e618a
  1. 8
      test/cpp/microbenchmarks/callback_streaming_ping_pong.h
  2. 33
      test/cpp/microbenchmarks/callback_test_service.h
  3. 22
      test/cpp/microbenchmarks/callback_unary_ping_pong.h

@ -55,9 +55,13 @@ static void BM_CallbackBidiStreaming(benchmark::State& state) {
std::condition_variable cv;
bool done = false;
BidiClient* test =
new BidiClient(state, stub_.get(), &request, &response, mu, cv, done);
new BidiClient(&state, stub_.get(), &request, &response,
&mu, &cv, &done);
test->StartNewRpc();
test->Await();
std::unique_lock<std::mutex> l(mu);
while (!done) {
cv.wait(l);
}
}
fixture->Finish(state);
fixture.reset();

@ -48,9 +48,9 @@ class CallbackStreamingTestService
class BidiClient
: public grpc::experimental::ClientBidiReactor<EchoRequest, EchoResponse> {
public:
BidiClient(benchmark::State& state, EchoTestService::Stub* stub,
EchoRequest* request, EchoResponse* response, std::mutex& mu,
std::condition_variable& cv, bool& done)
BidiClient(benchmark::State* state, EchoTestService::Stub* stub,
EchoRequest* request, EchoResponse* response, std::mutex* mu,
std::condition_variable* cv, bool* done)
: state_{state},
stub_{stub},
request_{request},
@ -58,8 +58,8 @@ class BidiClient
mu_{mu},
cv_{cv},
done_(done) {
msgs_size_ = state.range(0);
msgs_to_send_ = state.range(1);
msgs_size_ = state->range(0);
msgs_to_send_ = state->range(1);
cli_ctx_ = new ClientContext();
cli_ctx_->AddMetadata(kServerFinishAfterNReads,
grpc::to_string(msgs_to_send_));
@ -85,25 +85,18 @@ class BidiClient
void OnDone(const Status& s) override {
GPR_ASSERT(s.ok());
if (state_.KeepRunning()) {
if (state_->KeepRunning()) {
BidiClient* test =
new BidiClient(state_, stub_, request_, response_, mu_, cv_, done_);
test->StartNewRpc();
} else {
std::unique_lock<std::mutex> l(mu_);
done_ = true;
cv_.notify_one();
std::unique_lock<std::mutex> l(*mu_);
*done_ = true;
cv_->notify_one();
}
delete cli_ctx_;
}
void Await() {
std::unique_lock<std::mutex> l(mu_);
while (!done_) {
cv_.wait(l);
}
}
void StartNewRpc() {
stub_->experimental_async()->BidiStream(cli_ctx_, this);
MaybeWrite();
@ -120,16 +113,16 @@ class BidiClient
}
ClientContext* cli_ctx_;
benchmark::State& state_;
benchmark::State* state_;
EchoTestService::Stub* stub_;
EchoRequest* request_;
EchoResponse* response_;
int writes_complete_{0};
int msgs_to_send_;
int msgs_size_;
std::mutex& mu_;
std::condition_variable& cv_;
bool& done_;
std::mutex* mu_;
std::condition_variable* cv_;
bool* done_;
};
} // namespace testing

@ -37,24 +37,24 @@ namespace testing {
*/
// Send next rpc when callback function is evoked.
void SendCallbackUnaryPingPong(benchmark::State& state, EchoRequest* request,
void SendCallbackUnaryPingPong(benchmark::State* state, EchoRequest* request,
EchoResponse* response,
EchoTestService::Stub* stub_, bool& done,
std::mutex& mu, std::condition_variable& cv) {
int response_msgs_size = state.range(1);
EchoTestService::Stub* stub_, bool* done,
std::mutex* mu, std::condition_variable* cv) {
int response_msgs_size = state->range(1);
ClientContext* cli_ctx = new ClientContext();
cli_ctx->AddMetadata(kServerMessageSize, grpc::to_string(response_msgs_size));
stub_->experimental_async()->Echo(
cli_ctx, request, response,
[&state, cli_ctx, request, response, stub_, &done, &mu, &cv](Status s) {
[state, cli_ctx, request, response, stub_, done, mu, cv](Status s) {
GPR_ASSERT(s.ok());
if (state.KeepRunning()) {
if (state->KeepRunning()) {
SendCallbackUnaryPingPong(state, request, response, stub_, done, mu,
cv);
} else {
std::lock_guard<std::mutex> l(mu);
done = true;
cv.notify_one();
std::lock_guard<std::mutex> l(*mu);
*done = true;
cv->notify_one();
}
delete cli_ctx;
});
@ -82,8 +82,8 @@ static void BM_CallbackUnaryPingPong(benchmark::State& state) {
bool done = false;
if (state.KeepRunning()) {
GPR_TIMER_SCOPE("BenchmarkCycle", 0);
SendCallbackUnaryPingPong(state, &request, &response, stub_.get(), done, mu,
cv);
SendCallbackUnaryPingPong(&state, &request, &response, stub_.get(), &done,
&mu, &cv);
}
std::unique_lock<std::mutex> l(mu);
while (!done) {

Loading…
Cancel
Save