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> 22namespace OHOS { 23namespace SmartPerf { 24namespace SPUtils { 25/** 26 * @brief Check if the file has permission to access 27 * 28 * @param fileName 29 * @return true 30 * @return false 31 */ 32bool HasNumber(const std::string &str); 33bool 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 */ 42bool 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 */ 51bool 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 */ 60bool LoadCmdWithLinkBreak(const std::string &cmd, bool isClearLinkBreak, std::string &result); 61/** 62 * @brief 63 * 64 * @param path 65 * @return std::string 66 */ 67 68bool LoadCmd(const std::string &cmd, std::string &result); 69/** 70 * @brief 71 * 72 * @param path 73 * @return std::string 74 */ 75std::string IncludePathDelimiter(const std::string &path); 76/** 77 * @brief 78 * @param path 79 * @param files 80 */ 81void 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 */ 91bool 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 */ 99void 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 */ 106std::string ExtractNumber(const std::string &str); 107/** 108 * @brief replace '' \r\n from str 109 * @param res 110 */ 111void ReplaceString(std::string &res); 112/** 113 * @brief get cur Time longlong 114 * 115 */ 116long long GetCurTime(); 117/** 118 * @brief get top pkg 119 * 120 */ 121std::string GetTopPkgName(); 122std::string GetRadar(); 123std::string GetRadarResponse(); 124std::string GetRadarComplete(); 125std::string GetRadarFrame(); 126std::map<std::string, std::string> GetDeviceInfo(); 127std::map<std::string, std::string> GetCpuInfo(bool isTcpMessage); 128std::map<std::string, std::string> GetGpuInfo(bool isTcpMessage); 129std::string GetDeviceInfoMap(); 130std::string GetScreen(); 131void RemoveSpace(std::string &str); 132bool IntegerVerification(std::string str, std::string errorInfo); 133bool VeriyParameter(std::set<std::string>& keys, std::string param, std::string& errorInfo); 134bool VeriyKey(std::set<std::string>& keys, std::map<std::string, std::string>& mapInfo, std::string& errorInfo); 135bool VerifyValueStr(std::map<std::string, std::string>& mapInfo, std::string& errorInfo); 136bool IntegerValueVerification(std::set<std::string> &keys, std::map<std::string, std::string> &mapInfo, 137 std::string &errorInfo); 138bool IsHmKernel(); 139std::string GetCpuNum(); 140void GetCurrentTime(int num, int prevTime); 141bool IsForeGround(std::string &pkg); 142bool IsFindForeGround(std::string line); 143bool IsFindAbilist(); 144void SetRkFlag(); 145}; 146} 147} 148 149#endif // SP_UTILS_H 150