1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SRC_BIGTRACE_ORCHESTRATOR_ORCHESTRATOR_IMPL_H_ 18 #define SRC_BIGTRACE_ORCHESTRATOR_ORCHESTRATOR_IMPL_H_ 19 20 #include <grpcpp/client_context.h> 21 #include <memory> 22 #include <mutex> 23 #include <optional> 24 #include "perfetto/ext/base/threading/thread_pool.h" 25 #include "protos/perfetto/bigtrace/orchestrator.grpc.pb.h" 26 #include "protos/perfetto/bigtrace/worker.grpc.pb.h" 27 28 namespace perfetto::bigtrace { 29 namespace { 30 const uint64_t kDefaultMaxQueryConcurrency = 8; 31 } // namespace 32 33 class OrchestratorImpl final : public protos::BigtraceOrchestrator::Service { 34 public: 35 explicit OrchestratorImpl(std::unique_ptr<protos::BigtraceWorker::Stub> stub, 36 uint32_t max_query_concurrency); 37 38 grpc::Status Query( 39 grpc::ServerContext*, 40 const protos::BigtraceQueryArgs* args, 41 grpc::ServerWriter<protos::BigtraceQueryResponse>* writer) override; 42 43 private: 44 std::unique_ptr<protos::BigtraceWorker::Stub> stub_; 45 std::unique_ptr<base::ThreadPool> pool_; 46 uint32_t max_query_concurrency_ = kDefaultMaxQueryConcurrency; 47 uint32_t query_count_ = 0; 48 std::mutex query_count_mutex_; 49 }; 50 51 } // namespace perfetto::bigtrace 52 53 #endif // SRC_BIGTRACE_ORCHESTRATOR_ORCHESTRATOR_IMPL_H_ 54