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 HIVIEWDFX_HIVIEW_FAULTLOGGER_H 16 #define HIVIEWDFX_HIVIEW_FAULTLOGGER_H 17 #include <cstdint> 18 #include <memory> 19 #include <string> 20 #include <unordered_map> 21 #include <vector> 22 23 #include "event.h" 24 #include "plugin.h" 25 26 #include "faultlog_info.h" 27 #include "faultlog_manager.h" 28 #include "faultlog_query_result_inner.h" 29 #include "faultlogger_plugin.h" 30 31 namespace OHOS { 32 namespace HiviewDFX { 33 struct DumpRequest { 34 bool requestDetail; 35 bool requestList; 36 std::string fileName; 37 std::string moduleName; 38 time_t time; 39 }; 40 41 class Faultlogger : public FaultloggerPlugin, public EventListener { 42 public: Faultlogger()43 Faultlogger() : mgr_(nullptr), hasInit_(false) {}; ~Faultlogger()44 virtual ~Faultlogger(){}; 45 46 // implementations of Plugin interfaces 47 // for intercepting AppFreeze from collectors pipeline 48 bool OnEvent(std::shared_ptr<Event> &event) override; 49 bool IsInterestedPipelineEvent(std::shared_ptr<Event> event) override; 50 bool CanProcessEvent(std::shared_ptr<Event> event) override; 51 bool ReadyToLoad() override; 52 void OnLoad() override; 53 54 // dump debug infos through cmdline 55 void Dump(int fd, const std::vector<std::string> &cmds) override; 56 57 // implementations of FaultloggerPlugin interfaces 58 void AddFaultLog(FaultLogInfo& info) override; 59 std::unique_ptr<FaultLogInfo> GetFaultLogInfo(const std::string& logPath) override; 60 std::unique_ptr<FaultLogQueryResultInner> QuerySelfFaultLog(int32_t uid, 61 int32_t pid, int32_t faultType, int32_t maxNum) override; 62 63 // implementations of EventListener interfaces 64 // for intercepting JsCrash from engine pipeline 65 void OnUnorderedEvent(const Event &msg) override; 66 std::string GetListenerName() override; 67 static int RunSanitizerd(); 68 69 private: 70 void AddFaultLogIfNeed(FaultLogInfo& info, std::shared_ptr<Event> event); 71 void AddPublicInfo(FaultLogInfo& info); 72 void Dump(int fd, const DumpRequest& request) const; 73 void StartBootScan(); 74 bool JudgmentRateLimiting(std::shared_ptr<Event> event); 75 std::unique_ptr<FaultLogManager> mgr_; 76 volatile bool hasInit_; 77 std::unordered_map<std::string, std::time_t> eventTagTime_; 78 static void HandleNotify(int32_t type, const std::string& fname); 79 }; 80 } // namespace HiviewDFX 81 } // namespace OHOS 82 #endif // HIVIEWDFX_HIVIEW_FAULTLOGGER_H 83 84