• 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 
38 #define XCOLLIE_LOGF(...) HILOG_FATAL(LOG_CORE, ##__VA_ARGS__)
39 #define XCOLLIE_LOGE(...) HILOG_ERROR(LOG_CORE, ##__VA_ARGS__)
40 #define XCOLLIE_LOGW(...) HILOG_WARN(LOG_CORE, ##__VA_ARGS__)
41 #define XCOLLIE_LOGI(...) HILOG_INFO(LOG_CORE, ##__VA_ARGS__)
42 #define XCOLLIE_LOGD(...) HILOG_DEBUG(LOG_CORE, ##__VA_ARGS__)
43 #define MAGIC_NUM           0x9517
44 #define HTRANSIO            0xAB
45 #define LOGGER_GET_STACK    _IO(HTRANSIO, 9)
46 
47 constexpr OHOS::HiviewDFX::HiLogLabel KLOG_LABEL = {
48     LOG_KMSG,
49     LOG_DOMAIN,
50     LOG_TAG
51 };
52 #define XCOLLIE_KLOGI(...) \
53     do { \
54         (void)OHOS::HiviewDFX::HiLog::Info(KLOG_LABEL, __VA_ARGS__); \
55     } while (0)
56 
57 #define XCOLLIE_KLOGE(...) \
58     do { \
59         (void)OHOS::HiviewDFX::HiLog::Error(KLOG_LABEL, __VA_ARGS__); \
60     } while (0)
61 
62 uint64_t GetCurrentTickMillseconds();
63 
64 uint64_t GetCurrentBootMillseconds();
65 
66 void CalculateTimes(uint64_t& bootTimeStart, uint64_t& monoTimeStart);
67 
68 uint64_t GetNumsDiffAbs(const uint64_t& numOne, const uint64_t& numTwo);
69 
70 bool IsFileNameFormat(char c);
71 
72 std::string GetSelfProcName();
73 
74 std::string GetFirstLine(const std::string& path);
75 
76 std::string GetProcessNameFromProcCmdline(int32_t pid = 0);
77 
78 std::string GetLimitedSizeName(std::string name);
79 
80 bool IsProcessDebug(int32_t pid);
81 
82 void DelayBeforeExit(unsigned int leftTime);
83 
84 std::string TrimStr(const std::string& str, const char cTrim = ' ');
85 
86 void SplitStr(const std::string& str, const std::string& sep,
87     std::vector<std::string>& strs, bool canEmpty = false, bool needTrim = true);
88 
89 int ParsePeerBinderPid(std::ifstream& fin, int32_t pid);
90 
91 bool KillProcessByPid(int32_t pid);
92 
93 bool IsDeveloperOpen();
94 
95 bool IsBetaVersion();
96 
97 std::string GetFormatDate();
98 
99 std::string FormatTime(const std::string &format);
100 
101 bool CreateWatchdogDir();
102 
103 bool WriteStackToFd(int32_t pid, std::string& path, std::string& stack,
104     const std::string& eventName, bool& isOverLimit);
105 
106 int64_t GetTimeStamp();
107 
108 void* FunctionOpen(void* funcHandler, const char* funcName);
109 
110 int32_t GetUidByPid(const int32_t pid);
111 
112 int64_t GetAppStartTime(int32_t pid, int64_t tid);
113 } // end of HiviewDFX
114 } // end of OHOS
115 #endif
116