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