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 <string> 21 namespace OHOS { 22 namespace SmartPerf { 23 namespace SPUtils { 24 /** 25 * @brief Check if the file has permission to access 26 * 27 * @param fileName 28 * @return true 29 * @return false 30 */ 31 bool HasNumber(const std::string& str); 32 bool Cmp(const std::string &a, const std::string &b); 33 /** 34 * @brief Comparison key name 35 * 36 * @param a 37 * @param b 38 * @return true 39 * @return false 40 */ 41 bool FileAccess(const std::string &fileName); 42 /** 43 * @brief Load content from file node 44 * 45 * @param filePath 46 * @param content 47 * @return true 48 * @return false 49 */ 50 bool LoadFile(const std::string &filePath, std::string &content); 51 /** 52 * @brief read command return result 53 * 54 * @param cmd 55 * @param result 56 * @return true 57 * @return false 58 */ 59 bool LoadCmd(const std::string &cmd, std::string &result); 60 /** 61 * @brief 62 * 63 * @param path 64 * @return std::string 65 */ 66 std::string IncludePathDelimiter(const std::string &path); 67 /** 68 * @brief 69 * @param path 70 * @param files 71 */ 72 void ForDirFiles(const std::string &path, std::vector<std::string> &files); 73 74 /** 75 * @brief check if substr in parentstr 76 * 77 * @param str 78 * @param sub 79 * @return true 80 * @return false 81 */ 82 bool IsSubString(const std::string &str, const std::string &sub); 83 /** 84 * @brief split content by delimiter 85 * 86 * @param content 87 * @param sp 88 * @param out 89 */ 90 void StrSplit(const std::string &content, const std::string &sp, std::vector<std::string> &out); 91 /** 92 * @brief extract number from str 93 * 94 * @param str 95 * @return std::string 96 */ 97 std::string ExtractNumber(const std::string &str); 98 /** 99 * @brief replace '' \r\n from str 100 * @param res 101 */ 102 void ReplaceString(std::string &res); 103 /** 104 * @brief get cur Time longlong 105 * 106 */ 107 long long GetCurTime(); 108 /** 109 * @brief get top pkg 110 * 111 */ 112 std::string GetTopPkgName(); 113 std::string GetRadar(); 114 std::string GetRadarResponse(); 115 std::string GetRadarComplete(); 116 std::string GetRadarFrame(); 117 std::map<std::string, std::string> GetDeviceInfo(); 118 std::map<std::string, std::string> GetCpuInfo(); 119 std::map<std::string, std::string> GetGpuInfo(); 120 std::string GetScreen(); 121 }; 122 } 123 } 124 125 #endif // SP_UTILS_H 126