aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp/qps/qps_worker.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp/qps/qps_worker.cc')
-rw-r--r--test/cpp/qps/qps_worker.cc19
1 files changed, 15 insertions, 4 deletions
diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc
index 9442017ddf..ce4b773d92 100644
--- a/test/cpp/qps/qps_worker.cc
+++ b/test/cpp/qps/qps_worker.cc
@@ -101,6 +101,19 @@ static std::unique_ptr<Server> CreateServer(const ServerConfig& config) {
abort();
}
+class ScopedProfile GRPC_FINAL {
+ public:
+ ScopedProfile(const char *filename, bool enable) : enable_(enable) {
+ if (enable_) grpc_profiler_start(filename);
+ }
+ ~ScopedProfile() {
+ if (enable_) grpc_profiler_stop();
+ }
+
+ private:
+ const bool enable_;
+};
+
class WorkerServiceImpl GRPC_FINAL : public WorkerService::Service {
public:
WorkerServiceImpl(int server_port, QpsWorker* worker)
@@ -114,9 +127,8 @@ class WorkerServiceImpl GRPC_FINAL : public WorkerService::Service {
return Status(StatusCode::RESOURCE_EXHAUSTED, "");
}
- grpc_profiler_start("qps_client.prof");
+ ScopedProfile profile("qps_client.prof", false);
Status ret = RunClientBody(ctx, stream);
- grpc_profiler_stop();
return ret;
}
@@ -128,9 +140,8 @@ class WorkerServiceImpl GRPC_FINAL : public WorkerService::Service {
return Status(StatusCode::RESOURCE_EXHAUSTED, "");
}
- grpc_profiler_start("qps_server.prof");
+ ScopedProfile profile("qps_server.prof", false);
Status ret = RunServerBody(ctx, stream);
- grpc_profiler_stop();
return ret;
}