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 SP_UTILS_H 16 #define SP_UTILS_H 17 #include <iostream> 18 #include <vector> 19 #include <map> 20 #include <set> 21 #include <string> 22 namespace OHOS { 23 namespace SmartPerf { 24 namespace SPUtils { 25 /** 26 * @brief Check if the file has permission to access 27 * 28 * @param fileName 29 * @return true 30 * @return false 31 */ 32 bool HasNumber(const std::string &str); 33 bool Cmp(const std::string &a, const std::string &b); 34 /** 35 * @brief Comparison key name 36 * 37 * @param a 38 * @param b 39 * @return true 40 * @return false 41 */ 42 bool FileAccess(const std::string &fileName); 43 /** 44 * @brief Load content from file node 45 * 46 * @param filePath 47 * @param content 48 * @return true 49 * @return false 50 */ 51 bool LoadFile(const std::string &filePath, std::string &content); 52 /** 53 * @brief read command return result 54 * 55 * @param cmd 56 * @param result 57 * @return true 58 * @return false 59 */ 60 bool LoadCmdWithLinkBreak(const std::string &cmd, bool isClearLinkBreak, std::string &result); 61 /** 62 * @brief 63 * 64 * @param path 65 * @return std::string 66 */ 67 68 bool LoadCmd(const std::string &cmd, std::string &result); 69 /** 70 * @brief 71 * 72 * @param path 73 * @return std::string 74 */ 75 std::string IncludePathDelimiter(const std::string &path); 76 /** 77 * @brief 78 * @param path 79 * @param files 80 */ 81 void ForDirFiles(const std::string &path, std::vector<std::string> &files); 82 83 /** 84 * @brief check if substr in parentstr 85 * 86 * @param str 87 * @param sub 88 * @return true 89 * @return false 90 */ 91 bool IsSubString(const std::string &str, const std::string &sub); 92 /** 93 * @brief split content by delimiter 94 * 95 * @param content 96 * @param sp 97 * @param out 98 */ 99 void StrSplit(const std::string &content, const std::string &sp, std::vector<std::string> &out); 100 /** 101 * @brief extract number from str 102 * 103 * @param str 104 * @return std::string 105 */ 106 std::string ExtractNumber(const std::string &str); 107 /** 108 * @brief replace '' \r\n from str 109 * @param res 110 */ 111 void ReplaceString(std::string &res); 112 /** 113 * @brief get cur Time longlong 114 * 115 */ 116 long long GetCurTime(); 117 /** 118 * @brief get top pkg 119 * 120 */ 121 std::string GetTopPkgName(); 122 std::string GetRadar(); 123 std::string GetRadarResponse(); 124 std::string GetRadarComplete(); 125 std::string GetRadarFrame(); 126 std::map<std::string, std::string> GetDeviceInfo(); 127 std::map<std::string, std::string> GetCpuInfo(bool isTcpMessage); 128 std::map<std::string, std::string> GetGpuInfo(bool isTcpMessage); 129 std::string GetDeviceInfoMap(); 130 std::string GetScreen(); 131 void RemoveSpace(std::string &str); 132 bool IntegerVerification(std::string str, std::string errorInfo); 133 bool VeriyParameter(std::set<std::string>& keys, std::string param, std::string& errorInfo); 134 bool VeriyKey(std::set<std::string>& keys, std::map<std::string, std::string>& mapInfo, std::string& errorInfo); 135 bool VerifyValueStr(std::map<std::string, std::string>& mapInfo, std::string& errorInfo); 136 bool IntegerValueVerification(std::set<std::string> &keys, std::map<std::string, std::string> &mapInfo, 137 std::string &errorInfo); 138 bool IsHmKernel(); 139 std::string GetCpuNum(); 140 void GetCurrentTime(int num, int prevTime); 141 bool IsForeGround(std::string &pkg); 142 bool IsFindForeGround(std::string line); 143 bool IsFindAbilist(); 144 void SetRkFlag(); 145 }; 146 } 147 } 148 149 #endif // SP_UTILS_H 150