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{0}; 29 std::string packageName; 30 std::string threadName; 31 }; 32 33 struct IpcTrans { 34 double waitTime{0}; 35 std::string code; 36 std::string line; 37 IpcItem cIpcItem; 38 IpcItem sIpcItem; 39 }; 40 41 class LogUtil { 42 public: 43 LogUtil(const LogUtil&) = delete; 44 LogUtil& operator=(const LogUtil&) = delete; 45 static void GetTrace(std::stringstream& buffer, int cursor, const std::string& reg, std::string& result, 46 std::string startReg = ""); 47 static bool ReadFileBuff(const std::string& file, std::stringstream& buffer); 48 static bool IsTestModel(const std::string& sourceFile, const std::string& name, 49 const std::string& pattern, std::string& desPath); 50 static bool FileExist(const std::string& file); 51 52 public: 53 static constexpr const char *SPLIT_PATTERN = "\n"; 54 static constexpr const char *SMART_PARSER_TEST_DIR = "/data/test/test_data/SmartParser"; 55 static constexpr int TOTAL_LINE_NUM = 200; 56 57 private: 58 static int GetFileFd(const std::string& file); 59 }; 60 } // namespace HiviewDFX 61 } // namespace OHOS 62 #endif /* LOG_UTIL_H */ 63