106f6ba60Sopenharmony_ci/* 206f6ba60Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License. 506f6ba60Sopenharmony_ci * You may obtain a copy of the License at 606f6ba60Sopenharmony_ci * 706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 806f6ba60Sopenharmony_ci * 906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and 1306f6ba60Sopenharmony_ci * limitations under the License. 1406f6ba60Sopenharmony_ci */ 1506f6ba60Sopenharmony_ci#ifndef SP_UTILS_H 1606f6ba60Sopenharmony_ci#define SP_UTILS_H 1706f6ba60Sopenharmony_ci#include <iostream> 1806f6ba60Sopenharmony_ci#include <vector> 1906f6ba60Sopenharmony_ci#include <map> 2006f6ba60Sopenharmony_ci#include <set> 2106f6ba60Sopenharmony_ci#include <string> 2206f6ba60Sopenharmony_cinamespace OHOS { 2306f6ba60Sopenharmony_cinamespace SmartPerf { 2406f6ba60Sopenharmony_cinamespace SPUtils { 2506f6ba60Sopenharmony_ci/** 2606f6ba60Sopenharmony_ci * @brief Check if the file has permission to access 2706f6ba60Sopenharmony_ci * 2806f6ba60Sopenharmony_ci * @param fileName 2906f6ba60Sopenharmony_ci * @return true 3006f6ba60Sopenharmony_ci * @return false 3106f6ba60Sopenharmony_ci */ 3206f6ba60Sopenharmony_cibool HasNumber(const std::string &str); 3306f6ba60Sopenharmony_cibool Cmp(const std::string &a, const std::string &b); 3406f6ba60Sopenharmony_ci/** 3506f6ba60Sopenharmony_ci * @brief Comparison key name 3606f6ba60Sopenharmony_ci * 3706f6ba60Sopenharmony_ci * @param a 3806f6ba60Sopenharmony_ci * @param b 3906f6ba60Sopenharmony_ci * @return true 4006f6ba60Sopenharmony_ci * @return false 4106f6ba60Sopenharmony_ci */ 4206f6ba60Sopenharmony_cibool FileAccess(const std::string &fileName); 4306f6ba60Sopenharmony_ci/** 4406f6ba60Sopenharmony_ci * @brief Load content from file node 4506f6ba60Sopenharmony_ci * 4606f6ba60Sopenharmony_ci * @param filePath 4706f6ba60Sopenharmony_ci * @param content 4806f6ba60Sopenharmony_ci * @return true 4906f6ba60Sopenharmony_ci * @return false 5006f6ba60Sopenharmony_ci */ 5106f6ba60Sopenharmony_cibool LoadFile(const std::string &filePath, std::string &content); 5206f6ba60Sopenharmony_ci/** 5306f6ba60Sopenharmony_ci * @brief read command return result 5406f6ba60Sopenharmony_ci * 5506f6ba60Sopenharmony_ci * @param cmd 5606f6ba60Sopenharmony_ci * @param result 5706f6ba60Sopenharmony_ci * @return true 5806f6ba60Sopenharmony_ci * @return false 5906f6ba60Sopenharmony_ci */ 6006f6ba60Sopenharmony_cibool LoadCmdWithLinkBreak(const std::string &cmd, bool isClearLinkBreak, std::string &result); 6106f6ba60Sopenharmony_ci/** 6206f6ba60Sopenharmony_ci * @brief 6306f6ba60Sopenharmony_ci * 6406f6ba60Sopenharmony_ci * @param path 6506f6ba60Sopenharmony_ci * @return std::string 6606f6ba60Sopenharmony_ci */ 6706f6ba60Sopenharmony_ci 6806f6ba60Sopenharmony_cibool LoadCmd(const std::string &cmd, std::string &result); 6906f6ba60Sopenharmony_ci/** 7006f6ba60Sopenharmony_ci * @brief 7106f6ba60Sopenharmony_ci * 7206f6ba60Sopenharmony_ci * @param path 7306f6ba60Sopenharmony_ci * @return std::string 7406f6ba60Sopenharmony_ci */ 7506f6ba60Sopenharmony_cistd::string IncludePathDelimiter(const std::string &path); 7606f6ba60Sopenharmony_ci/** 7706f6ba60Sopenharmony_ci * @brief 7806f6ba60Sopenharmony_ci * @param path 7906f6ba60Sopenharmony_ci * @param files 8006f6ba60Sopenharmony_ci */ 8106f6ba60Sopenharmony_civoid ForDirFiles(const std::string &path, std::vector<std::string> &files); 8206f6ba60Sopenharmony_ci 8306f6ba60Sopenharmony_ci/** 8406f6ba60Sopenharmony_ci * @brief check if substr in parentstr 8506f6ba60Sopenharmony_ci * 8606f6ba60Sopenharmony_ci * @param str 8706f6ba60Sopenharmony_ci * @param sub 8806f6ba60Sopenharmony_ci * @return true 8906f6ba60Sopenharmony_ci * @return false 9006f6ba60Sopenharmony_ci */ 9106f6ba60Sopenharmony_cibool IsSubString(const std::string &str, const std::string &sub); 9206f6ba60Sopenharmony_ci/** 9306f6ba60Sopenharmony_ci * @brief split content by delimiter 9406f6ba60Sopenharmony_ci * 9506f6ba60Sopenharmony_ci * @param content 9606f6ba60Sopenharmony_ci * @param sp 9706f6ba60Sopenharmony_ci * @param out 9806f6ba60Sopenharmony_ci */ 9906f6ba60Sopenharmony_civoid StrSplit(const std::string &content, const std::string &sp, std::vector<std::string> &out); 10006f6ba60Sopenharmony_ci/** 10106f6ba60Sopenharmony_ci * @brief extract number from str 10206f6ba60Sopenharmony_ci * 10306f6ba60Sopenharmony_ci * @param str 10406f6ba60Sopenharmony_ci * @return std::string 10506f6ba60Sopenharmony_ci */ 10606f6ba60Sopenharmony_cistd::string ExtractNumber(const std::string &str); 10706f6ba60Sopenharmony_ci/** 10806f6ba60Sopenharmony_ci * @brief replace '' \r\n from str 10906f6ba60Sopenharmony_ci * @param res 11006f6ba60Sopenharmony_ci */ 11106f6ba60Sopenharmony_civoid ReplaceString(std::string &res); 11206f6ba60Sopenharmony_ci/** 11306f6ba60Sopenharmony_ci * @brief get cur Time longlong 11406f6ba60Sopenharmony_ci * 11506f6ba60Sopenharmony_ci */ 11606f6ba60Sopenharmony_cilong long GetCurTime(); 11706f6ba60Sopenharmony_ci/** 11806f6ba60Sopenharmony_ci * @brief get top pkg 11906f6ba60Sopenharmony_ci * 12006f6ba60Sopenharmony_ci */ 12106f6ba60Sopenharmony_cistd::string GetTopPkgName(); 12206f6ba60Sopenharmony_cistd::string GetRadar(); 12306f6ba60Sopenharmony_cistd::string GetRadarResponse(); 12406f6ba60Sopenharmony_cistd::string GetRadarComplete(); 12506f6ba60Sopenharmony_cistd::string GetRadarFrame(); 12606f6ba60Sopenharmony_cistd::map<std::string, std::string> GetDeviceInfo(); 12706f6ba60Sopenharmony_cistd::map<std::string, std::string> GetCpuInfo(bool isTcpMessage); 12806f6ba60Sopenharmony_cistd::map<std::string, std::string> GetGpuInfo(bool isTcpMessage); 12906f6ba60Sopenharmony_cistd::string GetDeviceInfoMap(); 13006f6ba60Sopenharmony_cistd::string GetScreen(); 13106f6ba60Sopenharmony_civoid RemoveSpace(std::string &str); 13206f6ba60Sopenharmony_cibool IntegerVerification(std::string str, std::string errorInfo); 13306f6ba60Sopenharmony_cibool VeriyParameter(std::set<std::string>& keys, std::string param, std::string& errorInfo); 13406f6ba60Sopenharmony_cibool VeriyKey(std::set<std::string>& keys, std::map<std::string, std::string>& mapInfo, std::string& errorInfo); 13506f6ba60Sopenharmony_cibool VerifyValueStr(std::map<std::string, std::string>& mapInfo, std::string& errorInfo); 13606f6ba60Sopenharmony_cibool IntegerValueVerification(std::set<std::string> &keys, std::map<std::string, std::string> &mapInfo, 13706f6ba60Sopenharmony_ci std::string &errorInfo); 13806f6ba60Sopenharmony_cibool IsHmKernel(); 13906f6ba60Sopenharmony_cistd::string GetCpuNum(); 14006f6ba60Sopenharmony_civoid GetCurrentTime(int num, int prevTime); 14106f6ba60Sopenharmony_cibool IsForeGround(std::string &pkg); 14206f6ba60Sopenharmony_cibool IsFindForeGround(std::string line); 14306f6ba60Sopenharmony_cibool IsFindAbilist(); 14406f6ba60Sopenharmony_civoid SetRkFlag(); 14506f6ba60Sopenharmony_ci}; 14606f6ba60Sopenharmony_ci} 14706f6ba60Sopenharmony_ci} 14806f6ba60Sopenharmony_ci 14906f6ba60Sopenharmony_ci#endif // SP_UTILS_H 150