diff options
author | 2015-03-31 12:50:56 -0700 | |
---|---|---|
committer | 2015-03-31 12:50:56 -0700 | |
commit | 54e16ee548ee18cc6d203d487e17f15ba5cd879b (patch) | |
tree | 74d06c475796b8452b82dd04aa87148f009948aa /test/cpp/qps/worker.cc | |
parent | 49673133b383f9ec71b9a4627aba7c4a722c3332 (diff) |
Put in calls to profiling
Diffstat (limited to 'test/cpp/qps/worker.cc')
-rw-r--r-- | test/cpp/qps/worker.cc | 96 |
1 files changed, 56 insertions, 40 deletions
diff --git a/test/cpp/qps/worker.cc b/test/cpp/qps/worker.cc index dddc4c9850..378151c571 100644 --- a/test/cpp/qps/worker.cc +++ b/test/cpp/qps/worker.cc @@ -109,6 +109,60 @@ class WorkerImpl GRPC_FINAL : public Worker::Service { return Status(RESOURCE_EXHAUSTED); } + grpc_profiler_start("qps_client.prof"); + Status ret = RunTestBody(ctx,stream); + grpc_profiler_stop(); + return ret; + } + + Status RunServer(ServerContext* ctx, + ServerReaderWriter<ServerStatus, ServerArgs>* stream) + GRPC_OVERRIDE { + InstanceGuard g(this); + if (!g.Acquired()) { + return Status(RESOURCE_EXHAUSTED); + } + + grpc_profiler_start("qps_server.prof"); + Status ret = RunServerBody(ctx,stream); + grpc_profiler_stop(); + return ret; + } + + private: + // Protect against multiple clients using this worker at once. + class InstanceGuard { + public: + InstanceGuard(WorkerImpl* impl) + : impl_(impl), acquired_(impl->TryAcquireInstance()) {} + ~InstanceGuard() { + if (acquired_) { + impl_->ReleaseInstance(); + } + } + + bool Acquired() const { return acquired_; } + + private: + WorkerImpl* const impl_; + const bool acquired_; + }; + + bool TryAcquireInstance() { + std::lock_guard<std::mutex> g(mu_); + if (acquired_) return false; + acquired_ = true; + return true; + } + + void ReleaseInstance() { + std::lock_guard<std::mutex> g(mu_); + GPR_ASSERT(acquired_); + acquired_ = false; + } + + Status RunTestBody(ServerContext* ctx, + ServerReaderWriter<ClientStatus, ClientArgs>* stream) { ClientArgs args; if (!stream->Read(&args)) { return Status(INVALID_ARGUMENT); @@ -135,14 +189,8 @@ class WorkerImpl GRPC_FINAL : public Worker::Service { return Status::OK; } - Status RunServer(ServerContext* ctx, - ServerReaderWriter<ServerStatus, ServerArgs>* stream) - GRPC_OVERRIDE { - InstanceGuard g(this); - if (!g.Acquired()) { - return Status(RESOURCE_EXHAUSTED); - } - + Status RunServerBody(ServerContext* ctx, + ServerReaderWriter<ServerStatus, ServerArgs>* stream) { ServerArgs args; if (!stream->Read(&args)) { return Status(INVALID_ARGUMENT); @@ -170,38 +218,6 @@ class WorkerImpl GRPC_FINAL : public Worker::Service { return Status::OK; } - private: - // Protect against multiple clients using this worker at once. - class InstanceGuard { - public: - InstanceGuard(WorkerImpl* impl) - : impl_(impl), acquired_(impl->TryAcquireInstance()) {} - ~InstanceGuard() { - if (acquired_) { - impl_->ReleaseInstance(); - } - } - - bool Acquired() const { return acquired_; } - - private: - WorkerImpl* const impl_; - const bool acquired_; - }; - - bool TryAcquireInstance() { - std::lock_guard<std::mutex> g(mu_); - if (acquired_) return false; - acquired_ = true; - return true; - } - - void ReleaseInstance() { - std::lock_guard<std::mutex> g(mu_); - GPR_ASSERT(acquired_); - acquired_ = false; - } - std::mutex mu_; bool acquired_; }; |