1 /* 2 * Copyright (c) 2021-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_MANAGER_H 16 #define FAULTLOG_MANAGER_H 17 #include <cstdint> 18 #include <ctime> 19 #include <list> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 24 #include "event_loop.h" 25 #include "log_store_ex.h" 26 27 #include "faultlog_info.h" 28 #include "i_faultlog_database.h" 29 30 namespace OHOS { 31 namespace HiviewDFX { 32 class FaultLogManager { 33 public: 34 // use rawdb manage fault log infos FaultLogManager(const std::shared_ptr<EventLoop> & looper)35 explicit FaultLogManager(const std::shared_ptr<EventLoop>& looper) : looper_(looper) {}; 36 void Init(); 37 bool GetFaultLogContent(const std::string& name, std::string& content) const; 38 int32_t CreateTempFaultLogFile(time_t time, int32_t id, int32_t faultType, const std::string& module) const; 39 std::list<std::string> GetFaultLogFileList(const std::string& module, time_t time, int32_t id, int32_t faultType, 40 int32_t maxNum) const; 41 std::string SaveFaultLogToFile(FaultLogInfo& info) const; 42 void RemoveOldFile(FaultLogInfo& info) const; 43 void SaveFaultInfoToRawDb(FaultLogInfo& info) const; 44 std::list<FaultLogInfo> GetFaultInfoList( 45 const std::string& module, int32_t id, int32_t faultType, int32_t maxNum) const; 46 bool IsProcessedFault(int32_t pid, int32_t uid, int32_t faultType); 47 private: 48 void InitWarningLogStore(); 49 std::string GetFaultLogFilePath(int32_t faultLogType, const std::string& fileName) const; 50 int GetFaultLogFileFd(int32_t faultLogType, const std::string& fileName) const; 51 void ReduceLogFileListSize(std::list<std::string>& infoVec, int32_t maxNum) const; 52 std::shared_ptr<EventLoop> looper_; 53 std::unique_ptr<LogStoreEx> store_; 54 std::unique_ptr<LogStoreEx> warningLogStore_; 55 std::unique_ptr<IFaultLogDatabase> faultLogDb_; 56 }; 57 } // namespace HiviewDFX 58 } // namespace OHOS 59 #endif 60