• 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 enum DumpStackState {
36     DEFAULT = 0,
37     COMPLETE = 1,
38     SAMPLE_COMPLETE = 2
39 };
40 constexpr char WMS_FULL_NAME[] = "WindowManagerService";
41 constexpr char IPC_FULL[] = "IPC_FULL";
42 constexpr char IPC_CHECKER[] = "IpcChecker";
43 constexpr char STACK_CHECKER[] = "ThreadSampler";
44 constexpr char TRACE_CHECKER[] = "TraceCollector";
45 constexpr int64_t SEC_TO_MANOSEC = 1000000000;
46 constexpr int64_t SEC_TO_MICROSEC = 1000000;
47 constexpr uint64_t MIN_APP_UID = 20000;
48 constexpr int64_t ONE_DAY_LIMIT = 86400000;
49 constexpr int64_t ONE_HOUR_LIMIT = 3600000;
50 constexpr int64_t MILLISEC_TO_NANOSEC = 1000000;
51 constexpr uint64_t MAX_FILE_SIZE = 10 * 1024 * 1024; // 10M
52 const int BUFF_STACK_SIZE = 20 * 1024;
53 const int FFRT_BUFFER_SIZE = 512 * 1024;
54 const int MAX_NAME_SIZE = 128;
55 const int MIN_WAIT_NUM = 3;
56 const int TIME_INDEX_MAX = 32;
57 const int DETECT_STACK_COUNT = 2;
58 const int COLLECT_STACK_COUNT = 10;
59 const int COLLECT_TRACE_MIN = 1;
60 const int COLLECT_TRACE_MAX = 20;
61 const int TASK_INTERVAL = 155;
62 const int DURATION_TIME = 150;
63 const int INIT_PID = 1;
64 const int DISTRIBUTE_TIME = 2000;
65 const int DUMPTRACE_TIME = 450;
66 const inline std::string LOGGER_BINDER_PROC_PATH = "/proc/transaction_proc";
67 const std::string WATCHDOG_DIR = "/data/storage/el2/log/watchdog";
68 const std::string KEY_HIVIEW_USER_TYPE = "const.logsystem.versiontype";
69 const std::string KEY_ANCO_ENABLE_TYPE = "persist.hmos_fusion_mgr.ctl.support_hmos";
70 const std::string KEY_DEVELOPER_MODE_STATE = "const.security.developermode.state";
71 const std::string ENABLE_VAULE = "true";
72 const std::string ENABLE_HIVIEW_USER_VAULE = "commercial";
73 
74 #define XCOLLIE_LOGF(...) HILOG_FATAL(LOG_CORE, ##__VA_ARGS__)
75 #define XCOLLIE_LOGE(...) HILOG_ERROR(LOG_CORE, ##__VA_ARGS__)
76 #define XCOLLIE_LOGW(...) HILOG_WARN(LOG_CORE, ##__VA_ARGS__)
77 #define XCOLLIE_LOGI(...) HILOG_INFO(LOG_CORE, ##__VA_ARGS__)
78 #define XCOLLIE_LOGD(...) HILOG_DEBUG(LOG_CORE, ##__VA_ARGS__)
79 #define MAGIC_NUM           0x9517
80 #define HTRANSIO            0xAB
81 #define LOGGER_GET_STACK    _IO(HTRANSIO, 9)
82 
83 uint64_t GetCurrentTickMillseconds();
84 
85 bool IsFileNameFormat(char c);
86 
87 std::string GetSelfProcName();
88 
89 std::string GetFirstLine(const std::string& path);
90 
91 std::string GetProcessNameFromProcCmdline(int32_t pid);
92 
93 std::string GetLimitedSizeName(std::string name);
94 
95 bool IsProcessDebug(int32_t pid);
96 
97 void DelayBeforeExit(unsigned int leftTime);
98 
99 std::string TrimStr(const std::string& str, const char cTrim = ' ');
100 
101 void SplitStr(const std::string& str, const std::string& sep,
102     std::vector<std::string>& strs, bool canEmpty = false, bool needTrim = true);
103 
104 int ParsePeerBinderPid(std::ifstream& fin, int32_t pid);
105 
106 bool KillProcessByPid(int32_t pid);
107 
108 bool IsBetaVersion();
109 
110 std::string GetFormatDate();
111 
112 bool CreateWatchdogDir();
113 
114 bool WriteStackToFd(int32_t pid, std::string& path, std::string& stack,
115     const std::string& eventName);
116 
117 int64_t GetTimeStamp();
118 
119 bool IsEnableVersion(const std::string& key, const std::string& type);
120 
121 void* FunctionOpen(void* funcHandler, const char* funcName);
122 } // end of HiviewDFX
123 } // end of OHOS
124 #endif
125