diff options
author | Vijay Pai <vpai@google.com> | 2016-11-10 14:57:05 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-10 14:57:05 -0800 |
commit | aaefa958d796e8f9ec1fe48df61ca0fd9425be48 (patch) | |
tree | 929560f2323e99bed593a728816b0d11dfd0ddbb /test/cpp/qps | |
parent | f612a36d1ce5e6448d451765614fedae4bbd54e4 (diff) | |
parent | ef2298948432cc2a8ebf77f6bec0701f1e4b1bdf (diff) |
Merge pull request #8638 from vjpai/conform
Improve C++11 conformance
Diffstat (limited to 'test/cpp/qps')
-rw-r--r-- | test/cpp/qps/client.h | 7 | ||||
-rw-r--r-- | test/cpp/qps/client_async.cc | 1 | ||||
-rw-r--r-- | test/cpp/qps/client_sync.cc | 14 | ||||
-rw-r--r-- | test/cpp/qps/driver.cc | 57 |
4 files changed, 26 insertions, 53 deletions
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index 3a0c359b4c..fdd78ebb89 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -163,10 +163,9 @@ class Client { MaybeStartRequests(); - // avoid std::vector for old compilers that expect a copy constructor if (reset) { - Histogram* to_merge = new Histogram[threads_.size()]; - StatusHistogram* to_merge_status = new StatusHistogram[threads_.size()]; + std::vector<Histogram> to_merge(threads_.size()); + std::vector<StatusHistogram> to_merge_status(threads_.size()); for (size_t i = 0; i < threads_.size(); i++) { threads_[i]->BeginSwap(&to_merge[i], &to_merge_status[i]); @@ -177,8 +176,6 @@ class Client { latencies.Merge(to_merge[i]); MergeStatusHistogram(to_merge_status[i], &statuses); } - delete[] to_merge; - delete[] to_merge_status; timer_result = timer->Mark(); } else { // merge snapshots of each thread histogram diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc index 2ec6a5a23b..4032039ea1 100644 --- a/test/cpp/qps/client_async.cc +++ b/test/cpp/qps/client_async.cc @@ -177,7 +177,6 @@ class AsyncClient : public ClientImpl<StubType, RequestType> { shutdown_state_.emplace_back(new PerThreadShutdownState()); } - using namespace std::placeholders; int t = 0; for (int ch = 0; ch < config.client_channels(); ch++) { for (int i = 0; i < config.outstanding_rpcs_per_channel(); i++) { diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc index a88a24d89c..b1e61865e7 100644 --- a/test/cpp/qps/client_sync.cc +++ b/test/cpp/qps/client_sync.cc @@ -138,10 +138,9 @@ class SynchronousUnaryClient final : public SynchronousClient { class SynchronousStreamingClient final : public SynchronousClient { public: SynchronousStreamingClient(const ClientConfig& config) - : SynchronousClient(config) { - context_ = new grpc::ClientContext[num_threads_]; - stream_ = new std::unique_ptr< - grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>[num_threads_]; + : SynchronousClient(config), + context_(num_threads_), + stream_(num_threads_) { for (size_t thread_idx = 0; thread_idx < num_threads_; thread_idx++) { auto* stub = channels_[thread_idx % channels_.size()].get_stub(); stream_[thread_idx] = stub->StreamingCall(&context_[thread_idx]); @@ -161,8 +160,6 @@ class SynchronousStreamingClient final : public SynchronousClient { } } } - delete[] stream_; - delete[] context_; } bool ThreadFunc(HistogramEntry* entry, size_t thread_idx) override { @@ -182,8 +179,9 @@ class SynchronousStreamingClient final : public SynchronousClient { private: // These are both conceptually std::vector but cannot be for old compilers // that expect contained classes to support copy constructors - grpc::ClientContext* context_; - std::unique_ptr<grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>* + std::vector<grpc::ClientContext> context_; + std::vector< + std::unique_ptr<grpc::ClientReaderWriter<SimpleRequest, SimpleResponse>>> stream_; }; diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index cf3372c3cf..ea0b38e8ad 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -192,30 +192,6 @@ static void postprocess_scenario_result(ScenarioResult* result) { } } -// Namespace for classes and functions used only in RunScenario -// Using this rather than local definitions to workaround gcc-4.4 limitations -// regarding using templates without linkage -namespace runsc { - -// ClientContext allocator -static ClientContext* AllocContext(list<ClientContext>* contexts) { - contexts->emplace_back(); - auto context = &contexts->back(); - context->set_wait_for_ready(true); - return context; -} - -struct ServerData { - unique_ptr<WorkerService::Stub> stub; - unique_ptr<ClientReaderWriter<ServerArgs, ServerStatus>> stream; -}; - -struct ClientData { - unique_ptr<WorkerService::Stub> stub; - unique_ptr<ClientReaderWriter<ClientArgs, ClientStatus>> stream; -}; -} // namespace runsc - std::unique_ptr<ScenarioResult> RunScenario( const ClientConfig& initial_client_config, size_t num_clients, const ServerConfig& initial_server_config, size_t num_servers, @@ -225,6 +201,12 @@ std::unique_ptr<ScenarioResult> RunScenario( // ClientContext allocations (all are destroyed at scope exit) list<ClientContext> contexts; + auto alloc_context = [](list<ClientContext>* contexts) { + contexts->emplace_back(); + auto context = &contexts->back(); + context->set_wait_for_ready(true); + return context; + }; // To be added to the result, containing the final configuration used for // client and config (including host, etc.) @@ -277,10 +259,11 @@ std::unique_ptr<ScenarioResult> RunScenario( workers.resize(num_clients + num_servers); // Start servers - 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 - auto* servers = new ServerData[num_servers]; + struct ServerData { + unique_ptr<WorkerService::Stub> stub; + unique_ptr<ClientReaderWriter<ServerArgs, ServerStatus>> stream; + }; + std::vector<ServerData> servers(num_servers); for (size_t i = 0; i < num_servers; i++) { gpr_log(GPR_INFO, "Starting server on %s (worker #%" PRIuPTR ")", workers[i].c_str(), i); @@ -324,8 +307,7 @@ std::unique_ptr<ScenarioResult> RunScenario( ServerArgs args; *args.mutable_setup() = server_config; - servers[i].stream = - servers[i].stub->RunServer(runsc::AllocContext(&contexts)); + servers[i].stream = servers[i].stub->RunServer(alloc_context(&contexts)); if (!servers[i].stream->Write(args)) { gpr_log(GPR_ERROR, "Could not write args to server %zu", i); } @@ -343,10 +325,11 @@ std::unique_ptr<ScenarioResult> RunScenario( // Targets are all set by now result_client_config = client_config; // Start clients - 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 - auto* clients = new ClientData[num_clients]; + struct ClientData { + unique_ptr<WorkerService::Stub> stub; + unique_ptr<ClientReaderWriter<ClientArgs, ClientStatus>> stream; + }; + std::vector<ClientData> clients(num_clients); size_t channels_allocated = 0; for (size_t i = 0; i < num_clients; i++) { const auto& worker = workers[i + num_servers]; @@ -395,8 +378,7 @@ std::unique_ptr<ScenarioResult> RunScenario( ClientArgs args; *args.mutable_setup() = per_client_config; - clients[i].stream = - clients[i].stub->RunClient(runsc::AllocContext(&contexts)); + clients[i].stream = clients[i].stub->RunClient(alloc_context(&contexts)); if (!clients[i].stream->Write(args)) { gpr_log(GPR_ERROR, "Could not write args to client %zu", i); } @@ -516,7 +498,6 @@ std::unique_ptr<ScenarioResult> RunScenario( s.error_message().c_str()); } } - delete[] clients; merged_latencies.FillProto(result->mutable_latencies()); for (std::unordered_map<int, int64_t>::iterator it = merged_statuses.begin(); @@ -559,8 +540,6 @@ std::unique_ptr<ScenarioResult> RunScenario( } } - delete[] servers; - postprocess_scenario_result(result.get()); return result; } |