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 int FdToRead(const std::string &file); 39 static int FdToWrite(const std::string &file); 40 41 // process operations 42 static bool CheckProcessAlive(uint32_t pid); 43 44 // ability string to ID 45 static int StrToId(const std::string &name); // -1:invalid 46 static std::string ConvertSaIdToSaName(const std::string &saIdStr); 47 48 static bool DirectoryExists(const std::string &path); 49 static bool PathIsValid(const std::string &path); 50 static bool CopyFile(const std::string &src, const std::string &des); 51 static bool IsCommercialVersion(); 52 static bool IsUserMode(); 53 static bool CheckAppDebugVersion(int pid); 54 55 static constexpr int TOP_PRIORITY = -20; 56 static constexpr int TOP_OOM_ADJ = -1000; 57 static constexpr char FILE_CUR_OOM_ADJ[] = "/proc/self/oom_score_adj"; 58 static constexpr auto& SPACE = " "; 59 static const int INVALID_PID = -1; 60 private: 61 static std::string ErrnoToMsg(const int &error); 62 }; 63 } // namespace HiviewDFX 64 } // namespace OHOS 65 #endif 66