• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #ifndef DUMP_UTILS_H
16 #define DUMP_UTILS_H
17 #include <string>
18 #include <vector>
19 #include <unistd.h>
20 namespace OHOS {
21 namespace HiviewDFX {
22 #ifndef TEMP_FAILURE_RETRY
23 #define TEMP_FAILURE_RETRY
24 #endif
25 class DumpUtils {
26 public:
27     // system operations
28     static void IgnoreOom();
29     static void IgnorePipeQuit();
30     static void IgnoreStdoutCache();
31     static void SetAdj(int adj);
32     static void BoostPriority();
33 
34     // string operations
35     static void RemoveDuplicateString(std::vector<std::string> &vector);
36 
37     // file operations
38     static bool FileWriteable(const std::string &file);
39     static int FdToRead(const std::string &file);
40     static int FdToWrite(const std::string &file);
41 
42     // process operations
43     static bool CheckProcessAlive(uint32_t pid);
44 
45     // ability string to ID
46     static int StrToId(const std::string &name); // 0:invalid
47     static std::string ConvertSaIdToSaName(const std::string &saIdStr);
48 
49     static bool DirectoryExists(const std::string &path);
50     static bool PathIsValid(const std::string &path);
51     static bool CopyFile(const std::string &src, const std::string &des);
52 
53     static constexpr int TOP_PRIORITY = -20;
54     static constexpr int TOP_OOM_ADJ = -1000;
55     static constexpr char FILE_CUR_OOM_ADJ[] = "/proc/self/oom_score_adj";
56     static constexpr auto& SPACE = " ";
57     static const int INVALID_PID = -1;
58 private:
59     static std::string ErrnoToMsg(const int &error);
60 };
61 } // namespace HiviewDFX
62 } // namespace OHOS
63 #endif
64