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 LOG_UTIL_H
16 #define LOG_UTIL_H
17 
18 #include <map>
19 #include <sstream>
20 #include <string>
21 #include <tuple>
22 #include <utility>
23 #include <vector>
24 
25 namespace OHOS {
26 namespace HiviewDFX {
27 struct IpcItem {
28     std::string pidTid;
29     std::string packageName;
30     std::string threadName;
31 };
32 
33 struct IpcTrans {
34     double waitTime;
35     std::string code;
36     std::string line;
37     IpcItem cIpcItem;
38     IpcItem sIpcItem;
39 };
40 
41 class LogUtil {
42 public:
LogUtil()43     LogUtil() {};
~LogUtil()44     ~LogUtil() {};
45     LogUtil(const LogUtil&) = delete;
46     LogUtil& operator=(const LogUtil&) = delete;
47     static void GetTrace(std::stringstream& buffer, int cursor, const std::string& reg, std::string& result,
48         std::string startReg = "");
49     static bool ReadFileBuff(const std::string& file, std::stringstream& buffer);
50     static bool IsTestModel(const std::string& sourceFile, const std::string& name,
51         const std::string& pattern, std::string& desPath);
52     static bool FileExist(const std::string& file);
53 
54 public:
55     static const std::string SPLIT_PATTERN;
56     static const std::string SMART_PARSER_TEST_DIR;
57     static const int TOTAL_LINE_NUM;
58 
59 private:
60     static int GetFileFd(const std::string& file);
61 };
62 } // namespace HiviewDFX
63 } // namespace OHOS
64 #endif /* LOG_UTIL_H */
65