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 std::tuple<std::pair<int, int>, std::vector<std::string>> ParseIpcInfo( 48 std::stringstream& buffer, const int offset, const std::pair<int, int>& pidTid); 49 static void GetTrace(std::stringstream& buffer, int cursor, const std::string& reg, std::string& result, 50 std::string startReg = ""); 51 static bool ReadFileBuff(const std::string& file, std::stringstream& buffer); 52 static bool IsTestModel(const std::string& sourceFile, const std::string& name, 53 const std::string& pattern, std::string& desPath); 54 static bool FileExist(const std::string& file); 55 56 public: 57 static const std::string SPLIT_PATTERN; 58 static const std::string SMART_PARSER_TEST_DIR; 59 static const int TOTAL_LINE_NUM; 60 61 62 private: 63 void ReadIpcInfo(std::stringstream& buffer, const int offset); 64 IpcItem ParseIpcStr(std::string IpcStr) const; 65 void GetIpcInfo(const std::string& line); 66 IpcTrans ParseZeroIpc(const IpcTrans& beginIpc) const; 67 void ParseIpcList(const std::string& clientPidTid, std::vector<IpcTrans>& IpcNode) const; 68 static int GetFileFd(const std::string& file); 69 70 private: 71 std::map<std::string, std::pair<std::string, IpcTrans>> IpcInfo_; 72 }; 73 } // namespace HiviewDFX 74 } // namespace OHOS 75 #endif /* LOG_UTIL_H */