xref: /base/hiviewdfx/hiview/main.cpp (revision 020a203a)
1/*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
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#include <unistd.h>
17
18#include "hiview_platform.h"
19#include "hiview_service.h"
20
21#include "defines.h"
22#include "hiview_logger.h"
23#include "memory_util.h"
24#include "dump_manager_cpu_service.h"
25
26DEFINE_LOG_TAG("HiView-Main");
27using namespace OHOS::HiviewDFX;
28
29int main(int argc __UNUSED, char* argv[] __UNUSED)
30{
31    if (MemoryUtil::DisableThreadCache() != 0 || MemoryUtil::DisableDelayFree() != 0) {
32        HIVIEW_LOGW("Failed to optimize memory for current thread");
33    }
34
35    auto& hiview = HiviewPlatform::GetInstance();
36    // process cmdline
37    hiview.ProcessArgsRequest(argc, argv);
38
39    // parse configs and load plugin
40    if (!hiview.InitEnvironment()) {
41        HIVIEW_LOGW("Fail to init plugin environment. exit");
42        _exit(-1); // user _exit to avoid double-free of HiviewPlatform
43    }
44
45    auto hidumperCpuService = std::make_unique<DumpManagerCpuService>();
46    hidumperCpuService->StartService();
47
48    // start service
49    auto hiviewService = std::make_unique<HiviewService>();
50    hiviewService->StartService();
51
52    return 0;
53}
54