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 LoadCmd(const std::string &cmd, std::string &result); 61 /** 62 * @brief 63 * 64 * @param path 65 * @return std::string 66 */ 67 std::string IncludePathDelimiter(const std::string &path); 68 /** 69 * @brief 70 * @param path 71 * @param files 72 */ 73 void ForDirFiles(const std::string &path, std::vector<std::string> &files); 74 75 /** 76 * @brief check if substr in parentstr 77 * 78 * @param str 79 * @param sub 80 * @return true 81 * @return false 82 */ 83 bool IsSubString(const std::string &str, const std::string &sub); 84 /** 85 * @brief split content by delimiter 86 * 87 * @param content 88 * @param sp 89 * @param out 90 */ 91 void StrSplit(const std::string &content, const std::string &sp, std::vector<std::string> &out); 92 /** 93 * @brief extract number from str 94 * 95 * @param str 96 * @return std::string 97 */ 98 std::string ExtractNumber(const std::string &str); 99 /** 100 * @brief replace '' \r\n from str 101 * @param res 102 */ 103 void ReplaceString(std::string &res); 104 /** 105 * @brief get cur Time longlong 106 * 107 */ 108 long long GetCurTime(); 109 /** 110 * @brief get top pkg 111 * 112 */ 113 std::string GetTopPkgName(); 114 std::string GetRadar(); 115 std::string GetRadarResponse(); 116 std::string GetRadarComplete(); 117 std::string GetRadarFrame(); 118 std::map<std::string, std::string> GetDeviceInfo(); 119 std::map<std::string, std::string> GetCpuInfo(); 120 std::map<std::string, std::string> GetGpuInfo(); 121 std::string GetScreen(); 122 void RemoveSpace(std::string &str); 123 bool IntegerVerification(std::string str, std::string errorInfo); 124 bool VeriyParameter(std::set<std::string>& keys, std::string param, std::string& errorInfo); 125 bool VeriyKey(std::set<std::string>& keys, std::map<std::string, std::string>& mapInfo, std::string& errorInfo); 126 bool VerifyValueStr(std::map<std::string, std::string>& mapInfo, std::string& errorInfo); 127 bool IntegerValueVerification(std::set<std::string> &keys, std::map<std::string, std::string> &mapInfo, 128 std::string &errorInfo); 129 }; 130 } 131 } 132 133 #endif // SP_UTILS_H 134