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