1 /* 2 * Copyright (c) 2025 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 FAULTLOG_PROCESSOR_BASE_H 16 #define FAULTLOG_PROCESSOR_BASE_H 17 18 #include "faultlog_hilog_helper.h" 19 #include "faultlog_manager.h" 20 #include "event_publish.h" 21 #include "faultlog_processor_interface.h" 22 23 namespace OHOS { 24 namespace HiviewDFX { 25 using namespace FaultlogHilogHelper; 26 class FaultLogProcessorBase : public FaultLogProcessorInterface { 27 public: 28 ~FaultLogProcessorBase() override = default; 29 static void GetProcMemInfo(FaultLogInfo& info); 30 static std::list<std::string> GetDigtStrArr(const std::string &target); 31 void AddFaultLog(FaultLogInfo& info, const std::shared_ptr<EventLoop>& workLoop, 32 const std::shared_ptr<FaultLogManager>& faultLogManager) override; 33 protected: 34 std::string ReadLogFile(const std::string& logPath) const; 35 void WriteLogFile(const std::string& logPath, const std::string& content) const; 36 void AddPagesHistory(FaultLogInfo& info) const; 37 38 private: 39 virtual void AddSpecificInfo(FaultLogInfo& info) = 0; DoFaultLogLimit(const std::string & logPath,int32_t faultType)40 virtual void DoFaultLogLimit(const std::string& logPath, int32_t faultType) const {} ReportEventToAppEvent(const FaultLogInfo & info)41 bool ReportEventToAppEvent(const FaultLogInfo& info) override { return false; } 42 void ProcessFaultLog(FaultLogInfo& info); 43 void AddCommonInfo(FaultLogInfo& info); 44 void DoFaultLogLimit(const FaultLogInfo& info); 45 void SaveFaultInfoToRawDb(FaultLogInfo& info); 46 void SaveFaultLogToFile(FaultLogInfo& info); 47 bool VerifyModule(FaultLogInfo& info); 48 void AddBundleInfo(FaultLogInfo& info); 49 void AddForegroundInfo(FaultLogInfo& info); 50 void UpdateTerminalThreadStack(FaultLogInfo& info); 51 void PrintFaultLogInfo(const FaultLogInfo& info); 52 protected: 53 std::shared_ptr<EventLoop> workLoop_; 54 std::shared_ptr<FaultLogManager> faultLogManager_; 55 }; 56 } // namespace HiviewDFX 57 } // namespace OHOS 58 #endif 59