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 16 #ifndef FREEZE_VENDOR_H 17 #define FREEZE_VENDOR_H 18 19 #include <set> 20 #include <string> 21 #include <vector> 22 23 #include "faultlog_info.h" 24 #include "freeze_common.h" 25 #include "log_store_ex.h" 26 #include "power_mgr_client.h" 27 #include "smart_parser.h" 28 #include "watch_point.h" 29 30 namespace OHOS { 31 namespace HiviewDFX { 32 class Vendor { 33 public: Vendor(std::shared_ptr<FreezeCommon> fc)34 explicit Vendor(std::shared_ptr<FreezeCommon> fc) : freezeCommon_(fc) {}; ~Vendor()35 ~Vendor() {}; 36 Vendor& operator=(const Vendor&) = delete; 37 Vendor(const Vendor&) = delete; 38 39 bool Init(); 40 std::string GetTimeString(unsigned long long timestamp) const; 41 void DumpEventInfo(std::ostringstream& oss, const std::string& header, const WatchPoint& watchPoint) const; 42 void InitLogInfo(const WatchPoint& watchPoint, std::string& type, std::string& pubLogPathName, 43 std::string& processName, std::string& isScbPro) const; 44 void InitLogBody(const std::vector<WatchPoint>& list, std::ostringstream& body, 45 bool& isFileExists) const; 46 bool JudgeSysWarningEvent(const std::string& stringId, std::string& type, const std::string& processName, 47 const std::vector<WatchPoint>& list, const std::vector<FreezeResult>& result) const; 48 std::string MergeEventLog( 49 const WatchPoint &watchPoint, const std::vector<WatchPoint>& list, 50 const std::vector<FreezeResult>& result) const; 51 bool ReduceRelevanceEvents(std::list<WatchPoint>& list, const FreezeResult& result) const; 52 53 private: 54 static const int MAX_LINE_NUM = 100; 55 static const int TIME_STRING_LEN = 16; 56 static const int MAX_FILE_NUM = 5; 57 static const int MAX_FOLDER_SIZE = 5 * 1024 * 1024; 58 static const inline std::string TRIGGER_HEADER = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"; 59 static const inline std::string HEADER = "*******************************************"; 60 static const inline std::string HYPHEN = "-"; 61 static const inline std::string NEW_LINE = "\n"; 62 static const inline std::string EVENT_SUMMARY = "SUMMARY"; 63 static const inline std::string POSTFIX = ".tmp"; 64 static const inline std::string APPFREEZE = "appfreeze"; 65 static const inline std::string SYSFREEZE = "sysfreeze"; 66 static const inline std::string SP_SYSTEMHUNGFAULT = "SystemHungFault"; 67 static const inline std::string SP_APPFREEZE = "AppFreeze"; 68 static const inline std::string SP_ENDSTACK = "END_STACK"; 69 static const inline std::string FREEZE_DETECTOR_PATH = "/data/log/faultlog/freeze/"; 70 static const inline std::string FAULT_LOGGER_PATH = "/data/log/faultlog/faultlogger/"; 71 static const inline std::string SMART_PARSER_PATH = "/system/etc/hiview/"; 72 73 std::string SendFaultLog(const WatchPoint &watchPoint, const std::string& logPath, const std::string& type, 74 const std::string& processName, const std::string& isScbPro) const; 75 void MergeFreezeJsonFile(const WatchPoint &watchPoint, const std::vector<WatchPoint>& list) const; 76 static void InitLogFfrt(const WatchPoint &watchPoint, std::ostringstream& ffrt); 77 static std::string GetDisPlayPowerInfo(); 78 static std::string GetPowerStateString(OHOS::PowerMgr::PowerState state); 79 static std::string IsScbProName(std::string& processName); 80 81 std::unique_ptr<LogStoreEx> logStore_ = nullptr; 82 std::shared_ptr<FreezeCommon> freezeCommon_ = nullptr; 83 }; 84 } // namespace HiviewDFX 85 } // namespace OHOS 86 #endif // FREEZE_VENDOR_H 87