• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 
16 #ifndef RELIABILITY_XCOLLIE_UTILS_H
17 #define RELIABILITY_XCOLLIE_UTILS_H
18 
19 #include <chrono>
20 #include <string>
21 #include <sys/ioctl.h>
22 #include <fstream>
23 #include <vector>
24 
25 #include "hilog/log.h"
26 
27 #undef LOG_DOMAIN
28 #define LOG_DOMAIN 0xD002D06
29 
30 #undef LOG_TAG
31 #define LOG_TAG "XCollie"
32 
33 namespace OHOS {
34 namespace HiviewDFX {
35 constexpr char IPC_FULL[] = "IPC_FULL";
36 constexpr uint64_t MIN_APP_UID = 20000;
37 const int BUFF_STACK_SIZE = 20 * 1024;
38 
39 #define XCOLLIE_LOGF(...) HILOG_FATAL(LOG_CORE, ##__VA_ARGS__)
40 #define XCOLLIE_LOGE(...) HILOG_ERROR(LOG_CORE, ##__VA_ARGS__)
41 #define XCOLLIE_LOGW(...) HILOG_WARN(LOG_CORE, ##__VA_ARGS__)
42 #define XCOLLIE_LOGI(...) HILOG_INFO(LOG_CORE, ##__VA_ARGS__)
43 #define XCOLLIE_LOGD(...) HILOG_DEBUG(LOG_CORE, ##__VA_ARGS__)
44 #define MAGIC_NUM           0x9517
45 #define HTRANSIO            0xAB
46 #define LOGGER_GET_STACK    _IO(HTRANSIO, 9)
47 
48 uint64_t GetCurrentTickMillseconds();
49 
50 bool IsFileNameFormat(char c);
51 
52 std::string GetSelfProcName();
53 
54 std::string GetFirstLine(const std::string& path);
55 
56 std::string GetProcessNameFromProcCmdline(int32_t pid = 0);
57 
58 std::string GetLimitedSizeName(std::string name);
59 
60 bool IsProcessDebug(int32_t pid);
61 
62 void DelayBeforeExit(unsigned int leftTime);
63 
64 std::string TrimStr(const std::string& str, const char cTrim = ' ');
65 
66 void SplitStr(const std::string& str, const std::string& sep,
67     std::vector<std::string>& strs, bool canEmpty = false, bool needTrim = true);
68 
69 int ParsePeerBinderPid(std::ifstream& fin, int32_t pid);
70 
71 bool KillProcessByPid(int32_t pid);
72 
73 bool IsDeveloperOpen();
74 
75 bool IsBetaVersion();
76 
77 std::string GetFormatDate();
78 
79 bool CreateWatchdogDir();
80 
81 bool WriteStackToFd(int32_t pid, std::string& path, std::string& stack,
82     const std::string& eventName);
83 
84 int64_t GetTimeStamp();
85 
86 void* FunctionOpen(void* funcHandler, const char* funcName);
87 
88 int64_t GetAppStartTime(int32_t pid, int64_t tid);
89 } // end of HiviewDFX
90 } // end of OHOS
91 #endif
92