@@ -109,6 +109,60 @@ class WorkerImpl GRPC_FINAL : public Worker::Service {
109109 return Status (RESOURCE_EXHAUSTED);
110110 }
111111
112+ grpc_profiler_start (" qps_client.prof" );
113+ Status ret = RunTestBody (ctx,stream);
114+ grpc_profiler_stop ();
115+ return ret;
116+ }
117+
118+ Status RunServer (ServerContext* ctx,
119+ ServerReaderWriter<ServerStatus, ServerArgs>* stream)
120+ GRPC_OVERRIDE {
121+ InstanceGuard g (this );
122+ if (!g.Acquired ()) {
123+ return Status (RESOURCE_EXHAUSTED);
124+ }
125+
126+ grpc_profiler_start (" qps_server.prof" );
127+ Status ret = RunServerBody (ctx,stream);
128+ grpc_profiler_stop ();
129+ return ret;
130+ }
131+
132+ private:
133+ // Protect against multiple clients using this worker at once.
134+ class InstanceGuard {
135+ public:
136+ InstanceGuard (WorkerImpl* impl)
137+ : impl_(impl), acquired_(impl->TryAcquireInstance ()) {}
138+ ~InstanceGuard () {
139+ if (acquired_) {
140+ impl_->ReleaseInstance ();
141+ }
142+ }
143+
144+ bool Acquired () const { return acquired_; }
145+
146+ private:
147+ WorkerImpl* const impl_;
148+ const bool acquired_;
149+ };
150+
151+ bool TryAcquireInstance () {
152+ std::lock_guard<std::mutex> g (mu_);
153+ if (acquired_) return false ;
154+ acquired_ = true ;
155+ return true ;
156+ }
157+
158+ void ReleaseInstance () {
159+ std::lock_guard<std::mutex> g (mu_);
160+ GPR_ASSERT (acquired_);
161+ acquired_ = false ;
162+ }
163+
164+ Status RunTestBody (ServerContext* ctx,
165+ ServerReaderWriter<ClientStatus, ClientArgs>* stream) {
112166 ClientArgs args;
113167 if (!stream->Read (&args)) {
114168 return Status (INVALID_ARGUMENT);
@@ -135,14 +189,8 @@ class WorkerImpl GRPC_FINAL : public Worker::Service {
135189 return Status::OK;
136190 }
137191
138- Status RunServer (ServerContext* ctx,
139- ServerReaderWriter<ServerStatus, ServerArgs>* stream)
140- GRPC_OVERRIDE {
141- InstanceGuard g (this );
142- if (!g.Acquired ()) {
143- return Status (RESOURCE_EXHAUSTED);
144- }
145-
192+ Status RunServerBody (ServerContext* ctx,
193+ ServerReaderWriter<ServerStatus, ServerArgs>* stream) {
146194 ServerArgs args;
147195 if (!stream->Read (&args)) {
148196 return Status (INVALID_ARGUMENT);
@@ -170,38 +218,6 @@ class WorkerImpl GRPC_FINAL : public Worker::Service {
170218 return Status::OK;
171219 }
172220
173- private:
174- // Protect against multiple clients using this worker at once.
175- class InstanceGuard {
176- public:
177- InstanceGuard (WorkerImpl* impl)
178- : impl_(impl), acquired_(impl->TryAcquireInstance ()) {}
179- ~InstanceGuard () {
180- if (acquired_) {
181- impl_->ReleaseInstance ();
182- }
183- }
184-
185- bool Acquired () const { return acquired_; }
186-
187- private:
188- WorkerImpl* const impl_;
189- const bool acquired_;
190- };
191-
192- bool TryAcquireInstance () {
193- std::lock_guard<std::mutex> g (mu_);
194- if (acquired_) return false ;
195- acquired_ = true ;
196- return true ;
197- }
198-
199- void ReleaseInstance () {
200- std::lock_guard<std::mutex> g (mu_);
201- GPR_ASSERT (acquired_);
202- acquired_ = false ;
203- }
204-
205221 std::mutex mu_;
206222 bool acquired_;
207223};
0 commit comments