clang-format plus helpful comments

pull/2771/head
Vijay Pai 9 years ago
parent eed63fa267
commit 90e7369484
  1. 11
      test/cpp/qps/client.h
  2. 3
      test/cpp/qps/client_async.cc
  3. 7
      test/cpp/qps/client_sync.cc
  4. 13
      test/cpp/qps/driver.cc

@ -69,7 +69,9 @@ typedef std::chrono::time_point<grpc_time_source> grpc_time;
class Client { class Client {
public: public:
explicit Client(const ClientConfig& config) explicit Client(const ClientConfig& config)
: channels_(config.client_channels()), timer_(new Timer), interarrival_timer_() { : channels_(config.client_channels()),
timer_(new Timer),
interarrival_timer_() {
for (int i = 0; i < config.client_channels(); i++) { for (int i = 0; i < config.client_channels(); i++) {
channels_[i].init(config.server_targets(i % config.server_targets_size()), channels_[i].init(config.server_targets(i % config.server_targets_size()),
config); config);
@ -110,14 +112,21 @@ class Client {
public: public:
ClientChannelInfo() {} ClientChannelInfo() {}
ClientChannelInfo(const ClientChannelInfo& i) : channel_(), stub_() { ClientChannelInfo(const ClientChannelInfo& i) : channel_(), stub_() {
// The copy constructor is to satisfy old compilers
// that need it for using std::vector . It is only ever
// used for empty entries
GPR_ASSERT(!i.channel_ && !i.stub_); GPR_ASSERT(!i.channel_ && !i.stub_);
} }
void init(const grpc::string& target, const ClientConfig& config) { void init(const grpc::string& target, const ClientConfig& config) {
// We have to use a 2-phase init like this with a default
// constructor followed by an initializer function to make
// old compilers happy with using this in std::vector
channel_ = CreateTestChannel(target, config.enable_ssl()); channel_ = CreateTestChannel(target, config.enable_ssl());
stub_ = TestService::NewStub(channel_); stub_ = TestService::NewStub(channel_);
} }
ChannelInterface* get_channel() { return channel_.get(); } ChannelInterface* get_channel() { return channel_.get(); }
TestService::Stub* get_stub() { return stub_.get(); } TestService::Stub* get_stub() { return stub_.get(); }
private: private:
std::shared_ptr<ChannelInterface> channel_; std::shared_ptr<ChannelInterface> channel_;
std::unique_ptr<TestService::Stub> stub_; std::unique_ptr<TestService::Stub> stub_;

@ -337,7 +337,8 @@ class AsyncClient : public Client {
std::vector<boolean> issue_allowed_; // may this thread attempt to issue std::vector<boolean> issue_allowed_; // may this thread attempt to issue
std::vector<grpc_time> next_issue_; // when should it issue? std::vector<grpc_time> next_issue_; // when should it issue?
std::mutex *channel_lock_; // a vector, but avoid std::vector for old compilers std::mutex*
channel_lock_; // a vector, but avoid std::vector for old compilers
std::vector<context_list> contexts_; // per-channel list of idle contexts std::vector<context_list> contexts_; // per-channel list of idle contexts
int max_outstanding_per_channel_; int max_outstanding_per_channel_;
int channel_count_; int channel_count_;

@ -125,7 +125,8 @@ class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient {
} }
~SynchronousStreamingClient() { ~SynchronousStreamingClient() {
EndThreads(); EndThreads();
for (auto stream = &stream_[0]; stream != &stream_[num_threads_]; stream++) { for (auto stream = &stream_[0]; stream != &stream_[num_threads_];
stream++) {
if (*stream) { if (*stream) {
(*stream)->WritesDone(); (*stream)->WritesDone();
EXPECT_TRUE((*stream)->Finish().ok()); EXPECT_TRUE((*stream)->Finish().ok());
@ -150,8 +151,8 @@ class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient {
// These are both conceptually std::vector but cannot be for old compilers // These are both conceptually std::vector but cannot be for old compilers
// that expect contained classes to support copy constructors // that expect contained classes to support copy constructors
grpc::ClientContext* context_; grpc::ClientContext* context_;
std::unique_ptr< std::unique_ptr<grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>*
grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>* stream_; stream_;
}; };
std::unique_ptr<Client> CreateSynchronousUnaryClient( std::unique_ptr<Client> CreateSynchronousUnaryClient(

@ -79,6 +79,7 @@ static deque<string> get_hosts(const string& name) {
// Namespace for classes and functions used only in RunScenario // Namespace for classes and functions used only in RunScenario
// Using this rather than local definitions to workaround gcc-4.4 limitations // Using this rather than local definitions to workaround gcc-4.4 limitations
// regarding using templates without linkage
namespace runsc { namespace runsc {
// ClientContext allocator // ClientContext allocator
@ -149,6 +150,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Start servers // Start servers
using runsc::ServerData; using runsc::ServerData;
// servers is array rather than std::vector to avoid gcc-4.4 issues
// where class contained in std::vector must have a copy constructor
ServerData servers[num_servers]; ServerData servers[num_servers];
for (size_t i = 0; i < num_servers; i++) { for (size_t i = 0; i < num_servers; i++) {
servers[i].stub = std::move(Worker::NewStub( servers[i].stub = std::move(Worker::NewStub(
@ -157,7 +160,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
result_server_config = server_config; result_server_config = server_config;
result_server_config.set_host(workers[i]); result_server_config.set_host(workers[i]);
*args.mutable_setup() = server_config; *args.mutable_setup() = server_config;
servers[i].stream = std::move(servers[i].stub->RunServer(runsc::AllocContext(&contexts))); servers[i].stream =
std::move(servers[i].stub->RunServer(runsc::AllocContext(&contexts)));
GPR_ASSERT(servers[i].stream->Write(args)); GPR_ASSERT(servers[i].stream->Write(args));
ServerStatus init_status; ServerStatus init_status;
GPR_ASSERT(servers[i].stream->Read(&init_status)); GPR_ASSERT(servers[i].stream->Read(&init_status));
@ -174,6 +178,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Start clients // Start clients
using runsc::ClientData; using runsc::ClientData;
// clients is array rather than std::vector to avoid gcc-4.4 issues
// where class contained in std::vector must have a copy constructor
ClientData clients[num_clients]; ClientData clients[num_clients];
for (size_t i = 0; i < num_clients; i++) { for (size_t i = 0; i < num_clients; i++) {
clients[i].stub = std::move(Worker::NewStub(CreateChannel( clients[i].stub = std::move(Worker::NewStub(CreateChannel(
@ -182,7 +188,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
result_client_config = client_config; result_client_config = client_config;
result_client_config.set_host(workers[i + num_servers]); result_client_config.set_host(workers[i + num_servers]);
*args.mutable_setup() = client_config; *args.mutable_setup() = client_config;
clients[i].stream = std::move(clients[i].stub->RunTest(runsc::AllocContext(&contexts))); clients[i].stream =
std::move(clients[i].stub->RunTest(runsc::AllocContext(&contexts)));
GPR_ASSERT(clients[i].stream->Write(args)); GPR_ASSERT(clients[i].stream->Write(args));
ClientStatus init_status; ClientStatus init_status;
GPR_ASSERT(clients[i].stream->Read(&init_status)); GPR_ASSERT(clients[i].stream->Read(&init_status));
@ -217,6 +224,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
// Wait some time // Wait some time
gpr_log(GPR_INFO, "Running"); gpr_log(GPR_INFO, "Running");
// Use gpr_sleep_until rather than this_thread::sleep_until to support
// compilers that don't work with this_thread
gpr_sleep_until(gpr_time_add( gpr_sleep_until(gpr_time_add(
start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN))); start, gpr_time_from_seconds(benchmark_seconds, GPR_TIMESPAN)));

Loading…
Cancel
Save