Add copyright

pull/18881/head
Na-Na Pang 6 years ago
parent 13d6d7c2ec
commit 8bf138d799
  1. 18
      test/cpp/microbenchmarks/bm_callback_streaming_ping_pong.cc
  2. 27
      test/cpp/microbenchmarks/bm_callback_unary_ping_pong.cc
  3. 27
      test/cpp/microbenchmarks/callback_streaming_ping_pong.h
  4. 47
      test/cpp/microbenchmarks/callback_test_service.cc
  5. 43
      test/cpp/microbenchmarks/callback_test_service.h
  6. 19
      test/cpp/microbenchmarks/callback_unary_ping_pong.h

@ -1,3 +1,21 @@
/*
*
* Copyright 2016 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "test/cpp/microbenchmarks/callback_streaming_ping_pong.h"
#include "test/cpp/util/test_config.h"

@ -1,3 +1,21 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "test/cpp/microbenchmarks/callback_unary_ping_pong.h"
#include "test/cpp/util/test_config.h"
@ -22,11 +40,14 @@ static void SweepSizesArgs(benchmark::internal::Benchmark* b) {
}
}
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator, NoOpMutator)
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcess, NoOpMutator,
NoOpMutator)
->Apply(SweepSizesArgs);
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, MinInProcess, NoOpMutator, NoOpMutator)
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, MinInProcess, NoOpMutator,
NoOpMutator)
->Apply(SweepSizesArgs);
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator, NoOpMutator)
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, InProcessCHTTP2, NoOpMutator,
NoOpMutator)
->Apply(SweepSizesArgs);
BENCHMARK_TEMPLATE(BM_CallbackUnaryPingPong, MinInProcessCHTTP2, NoOpMutator,
NoOpMutator)

@ -1,14 +1,31 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef TEST_CPP_MICROBENCHMARKS_CALLBACK_STREAMING_PING_PONG_H
#define TEST_CPP_MICROBENCHMARKS_CALLBACK_STREAMING_PING_PONG_H
#include <benchmark/benchmark.h>
#include <sstream>
#include "src/core/lib/profiling/timers.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/callback_test_service.h"
#include "test/cpp/microbenchmarks/fullstack_context_mutators.h"
#include "test/cpp/microbenchmarks/fullstack_fixtures.h"
#include "test/cpp/microbenchmarks/callback_test_service.h"
namespace grpc {
namespace testing {
@ -38,14 +55,14 @@ static void BM_CallbackBidiStreaming(benchmark::State& state) {
cli_ctx->AddMetadata(kServerFinishAfterNReads,
grpc::to_string(max_ping_pongs));
cli_ctx->AddMetadata(kServerResponseStreamsToSend,
grpc::to_string(message_size));
grpc::to_string(message_size));
BidiClient test{stub_.get(), request, response, cli_ctx, max_ping_pongs};
test.Await();
}
fixture->Finish(state);
fixture.reset();
state.SetBytesProcessed(2 * state.range(0) * state.iterations()
* state.range(1));
state.SetBytesProcessed(2 * state.range(0) * state.iterations() *
state.range(1));
}
} // namespace testing

@ -1,3 +1,21 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "test/cpp/microbenchmarks/callback_test_service.h"
namespace grpc {
@ -26,7 +44,7 @@ int GetIntValueFromMetadata(
int default_value) {
return GetIntValueFromMetadataHelper(key, metadata, default_value);
}
} // namespace
} // namespace
void CallbackStreamingTestService::Echo(
ServerContext* context, const EchoRequest* request, EchoResponse* response,
@ -36,24 +54,24 @@ void CallbackStreamingTestService::Echo(
experimental::ServerBidiReactor<EchoRequest, EchoResponse>*
CallbackStreamingTestService::BidiStream() {
class Reactor : public experimental::ServerBidiReactor<EchoRequest,
EchoResponse> {
class Reactor
: public experimental::ServerBidiReactor<EchoRequest, EchoResponse> {
public:
Reactor() {}
void OnStarted(ServerContext* context) override {
ctx_ = context;
server_write_last_ = GetIntValueFromMetadata(
kServerFinishAfterNReads, context->client_metadata(), 0);
message_size_ = GetIntValueFromMetadata(
kServerResponseStreamsToSend, context->client_metadata(), 0);
// EchoRequest* request = new EchoRequest;
// if (message_size_ > 0) {
// request->set_message(std::string(message_size_, 'a'));
// } else {
// request->set_message("");
// }
//
// request_ = request;
message_size_ = GetIntValueFromMetadata(kServerResponseStreamsToSend,
context->client_metadata(), 0);
// EchoRequest* request = new EchoRequest;
// if (message_size_ > 0) {
// request->set_message(std::string(message_size_, 'a'));
// } else {
// request->set_message("");
// }
//
// request_ = request;
StartRead(&request_);
on_started_done_ = true;
}
@ -62,7 +80,7 @@ CallbackStreamingTestService::BidiStream() {
void OnReadDone(bool ok) override {
if (ok) {
num_msgs_read_++;
// gpr_log(GPR_INFO, "recv msg %s", request_.message().c_str());
// gpr_log(GPR_INFO, "recv msg %s", request_.message().c_str());
if (message_size_ > 0) {
response_.set_message(std::string(message_size_, 'a'));
} else {
@ -108,4 +126,3 @@ CallbackStreamingTestService::BidiStream() {
}
} // namespace testing
} // namespace grpc

@ -1,12 +1,30 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef TEST_CPP_MICROBENCHMARKS_CALLBACK_TEST_SERVICE_H
#define TEST_CPP_MICROBENCHMARKS_CALLBACK_TEST_SERVICE_H
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/util/string_ref_helper.h"
#include <sstream>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <condition_variable>
#include <sstream>
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/util/string_ref_helper.h"
namespace grpc {
namespace testing {
@ -22,18 +40,20 @@ class CallbackStreamingTestService
EchoResponse* response,
experimental::ServerCallbackRpcController* controller) override;
experimental::ServerBidiReactor<EchoRequest, EchoResponse>* BidiStream() override;
experimental::ServerBidiReactor<EchoRequest, EchoResponse>* BidiStream()
override;
};
class BidiClient
: public grpc::experimental::ClientBidiReactor<EchoRequest, EchoResponse> {
public:
BidiClient(EchoTestService::Stub* stub, EchoRequest* request,
EchoResponse* response, ClientContext* context, int num_msgs_to_send)
EchoResponse* response, ClientContext* context,
int num_msgs_to_send)
: request_{request},
response_{response},
context_{context},
msgs_to_send_{num_msgs_to_send}{
msgs_to_send_{num_msgs_to_send} {
stub->experimental_async()->BidiStream(context_, this);
MaybeWrite();
StartRead(response_);
@ -63,11 +83,11 @@ class BidiClient
}
void Await() {
std::unique_lock<std::mutex> l(mu_);
while (!done_) {
cv_.wait(l);
}
std::unique_lock<std::mutex> l(mu_);
while (!done_) {
cv_.wait(l);
}
}
private:
void MaybeWrite() {
@ -89,7 +109,6 @@ class BidiClient
bool done_ = false;
};
} // namespace testing
} // namespace grpc
#endif // TEST_CPP_MICROBENCHMARKS_CALLBACK_TEST_SERVICE_H

@ -1,6 +1,6 @@
/*
*
* Copyright 2016 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,9 +25,9 @@
#include <sstream>
#include "src/core/lib/profiling/timers.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
#include "test/cpp/microbenchmarks/callback_test_service.h"
#include "test/cpp/microbenchmarks/fullstack_context_mutators.h"
#include "test/cpp/microbenchmarks/fullstack_fixtures.h"
#include "test/cpp/microbenchmarks/callback_test_service.h"
namespace grpc {
namespace testing {
@ -63,12 +63,12 @@ static void BM_CallbackUnaryPingPong(benchmark::State& state) {
std::condition_variable cv;
bool done = false;
stub_->experimental_async()->Echo(&cli_ctx, &request, &response,
[&done, &mu, &cv](Status s) {
GPR_ASSERT(s.ok());
std::lock_guard<std::mutex> l(mu);
done = true;
cv.notify_one();
});
[&done, &mu, &cv](Status s) {
GPR_ASSERT(s.ok());
std::lock_guard<std::mutex> l(mu);
done = true;
cv.notify_one();
});
std::unique_lock<std::mutex> l(mu);
while (!done) {
cv.wait(l);
@ -76,7 +76,8 @@ static void BM_CallbackUnaryPingPong(benchmark::State& state) {
}
fixture->Finish(state);
fixture.reset();
state.SetBytesProcessed(state.range(0) * state.iterations() + state.range(1) * state.iterations());
state.SetBytesProcessed(state.range(0) * state.iterations() +
state.range(1) * state.iterations());
}
} // namespace testing
} // namespace grpc

Loading…
Cancel
Save