1 /*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <memory>
16
17 #include "common.h"
18 #include "grpc/impl/codegen/log.h"
19 #include "grpcpp/health_check_service_interface.h"
20 #include "logging.h"
21 #include "plugin_service.h"
22 #include "profiler_service.h"
23
24 namespace {
25 const std::string DEFAULT_SERVICE_LISTEN_URI = "0.0.0.0:";
26 }
27
main(int argc,char * argv[])28 int main(int argc, char* argv[])
29 {
30 int lockFileFd = -1;
31 if (COMMON::IsProcessRunning(lockFileFd)) { // process is running
32 return 0;
33 }
34
35 gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG);
36 grpc::EnableDefaultHealthCheckService(true);
37
38 auto service = std::make_shared<ProfilerService>(std::make_shared<PluginService>());
39 CHECK_NOTNULL(service, -1, "ProfilerService create failed!");
40
41 std::string listenUri = DEFAULT_SERVICE_LISTEN_URI + std::to_string(COMMON::GetServicePort());
42 if (argc > 1) {
43 listenUri = argv[1];
44 }
45 if (service->StartService(listenUri)) {
46 PROFILER_LOG_INFO(LOG_CORE, "ProfilerService start SUCCESS!");
47 service->WaitServiceDone();
48 }
49 close(lockFileFd);
50 return 0;
51 }
52