1209bc2fbSopenharmony_ci/*
2209bc2fbSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3209bc2fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4209bc2fbSopenharmony_ci * you may not use this file except in compliance with the License.
5209bc2fbSopenharmony_ci * You may obtain a copy of the License at
6209bc2fbSopenharmony_ci *
7209bc2fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8209bc2fbSopenharmony_ci *
9209bc2fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10209bc2fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11209bc2fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12209bc2fbSopenharmony_ci * See the License for the specific language governing permissions and
13209bc2fbSopenharmony_ci * limitations under the License.
14209bc2fbSopenharmony_ci */
15209bc2fbSopenharmony_ci
16209bc2fbSopenharmony_ci#ifndef RELIABILITY_XCOLLIE_UTILS_H
17209bc2fbSopenharmony_ci#define RELIABILITY_XCOLLIE_UTILS_H
18209bc2fbSopenharmony_ci
19209bc2fbSopenharmony_ci#include <chrono>
20209bc2fbSopenharmony_ci#include <string>
21209bc2fbSopenharmony_ci#include <sys/ioctl.h>
22209bc2fbSopenharmony_ci#include <fstream>
23209bc2fbSopenharmony_ci#include <vector>
24209bc2fbSopenharmony_ci
25209bc2fbSopenharmony_ci#include "hilog/log.h"
26209bc2fbSopenharmony_ci
27209bc2fbSopenharmony_ci#undef LOG_DOMAIN
28209bc2fbSopenharmony_ci#define LOG_DOMAIN 0xD002D06
29209bc2fbSopenharmony_ci
30209bc2fbSopenharmony_ci#undef LOG_TAG
31209bc2fbSopenharmony_ci#define LOG_TAG "XCollie"
32209bc2fbSopenharmony_ci
33209bc2fbSopenharmony_cinamespace OHOS {
34209bc2fbSopenharmony_cinamespace HiviewDFX {
35209bc2fbSopenharmony_ciconstexpr char IPC_FULL[] = "IPC_FULL";
36209bc2fbSopenharmony_ciconstexpr uint64_t MIN_APP_UID = 20000;
37209bc2fbSopenharmony_ci
38209bc2fbSopenharmony_ci#define XCOLLIE_LOGF(...) HILOG_FATAL(LOG_CORE, ##__VA_ARGS__)
39209bc2fbSopenharmony_ci#define XCOLLIE_LOGE(...) HILOG_ERROR(LOG_CORE, ##__VA_ARGS__)
40209bc2fbSopenharmony_ci#define XCOLLIE_LOGW(...) HILOG_WARN(LOG_CORE, ##__VA_ARGS__)
41209bc2fbSopenharmony_ci#define XCOLLIE_LOGI(...) HILOG_INFO(LOG_CORE, ##__VA_ARGS__)
42209bc2fbSopenharmony_ci#define XCOLLIE_LOGD(...) HILOG_DEBUG(LOG_CORE, ##__VA_ARGS__)
43209bc2fbSopenharmony_ci#define MAGIC_NUM           0x9517
44209bc2fbSopenharmony_ci#define HTRANSIO            0xAB
45209bc2fbSopenharmony_ci#define LOGGER_GET_STACK    _IO(HTRANSIO, 9)
46209bc2fbSopenharmony_ci
47209bc2fbSopenharmony_ciuint64_t GetCurrentTickMillseconds();
48209bc2fbSopenharmony_ci
49209bc2fbSopenharmony_cibool IsFileNameFormat(char c);
50209bc2fbSopenharmony_ci
51209bc2fbSopenharmony_cistd::string GetSelfProcName();
52209bc2fbSopenharmony_ci
53209bc2fbSopenharmony_cistd::string GetFirstLine(const std::string& path);
54209bc2fbSopenharmony_ci
55209bc2fbSopenharmony_cistd::string GetProcessNameFromProcCmdline(int32_t pid);
56209bc2fbSopenharmony_ci
57209bc2fbSopenharmony_cistd::string GetLimitedSizeName(std::string name);
58209bc2fbSopenharmony_ci
59209bc2fbSopenharmony_cibool IsProcessDebug(int32_t pid);
60209bc2fbSopenharmony_ci
61209bc2fbSopenharmony_civoid DelayBeforeExit(unsigned int leftTime);
62209bc2fbSopenharmony_ci
63209bc2fbSopenharmony_cistd::string TrimStr(const std::string& str, const char cTrim = ' ');
64209bc2fbSopenharmony_ci
65209bc2fbSopenharmony_civoid SplitStr(const std::string& str, const std::string& sep,
66209bc2fbSopenharmony_ci    std::vector<std::string>& strs, bool canEmpty = false, bool needTrim = true);
67209bc2fbSopenharmony_ci
68209bc2fbSopenharmony_ciint ParsePeerBinderPid(std::ifstream& fin, int32_t pid);
69209bc2fbSopenharmony_ci
70209bc2fbSopenharmony_cibool KillProcessByPid(int32_t pid);
71209bc2fbSopenharmony_ci
72209bc2fbSopenharmony_cibool IsDeveloperOpen();
73209bc2fbSopenharmony_ci
74209bc2fbSopenharmony_cibool IsBetaVersion();
75209bc2fbSopenharmony_ci
76209bc2fbSopenharmony_cistd::string GetFormatDate();
77209bc2fbSopenharmony_ci
78209bc2fbSopenharmony_cibool CreateWatchdogDir();
79209bc2fbSopenharmony_ci
80209bc2fbSopenharmony_cibool WriteStackToFd(int32_t pid, std::string& path, std::string& stack,
81209bc2fbSopenharmony_ci    const std::string& eventName);
82209bc2fbSopenharmony_ci
83209bc2fbSopenharmony_ciint64_t GetTimeStamp();
84209bc2fbSopenharmony_ci
85209bc2fbSopenharmony_cibool IsEnableVersion();
86209bc2fbSopenharmony_ci
87209bc2fbSopenharmony_civoid* FunctionOpen(void* funcHandler, const char* funcName);
88209bc2fbSopenharmony_ci} // end of HiviewDFX
89209bc2fbSopenharmony_ci} // end of OHOS
90209bc2fbSopenharmony_ci#endif
91