1 /* 2 * Copyright (c) 2022 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 BBOX_DETECTOR_PLUGIN_H 16 #define BBOX_DETECTOR_PLUGIN_H 17 18 #include <mutex> 19 #include <string> 20 21 #include "event_source.h" 22 #include "plugin.h" 23 #include "sys_event.h" 24 #include "bbox_event_recorder.h" 25 namespace OHOS { 26 namespace HiviewDFX { 27 class BBoxDetectorPlugin : public Plugin { 28 public: BBoxDetectorPlugin()29 BBoxDetectorPlugin() {}; ~BBoxDetectorPlugin()30 ~BBoxDetectorPlugin() {}; 31 void OnLoad() override; 32 void OnUnload() override; 33 bool OnEvent(std::shared_ptr<Event> &event) override; 34 35 private: 36 void StartBootScan(); 37 void WaitForLogs(const std::string& logDir); 38 void HandleBBoxEvent(std::shared_ptr<SysEvent> &sysEvent); 39 uint64_t GetHappenTime(std::string& line, bool isHisiHistory); 40 int CheckAndHiSysEventWrite(std::string& name, std::map<std::string, std::string>& historyMap, 41 uint64_t& happenTime); 42 std::map<std::string, std::string> GetValueFromHistory(std::string& line, bool isHisiHistory); 43 void AddDetectBootCompletedTask(); 44 void RemoveDetectBootCompletedTask(); 45 void NotifyBootStable(); 46 void NotifyBootCompleted(); 47 void InitPanicReporter(); 48 void AddBootScanEvent(); 49 50 static constexpr int SECONDS = 60; 51 static constexpr int READ_LINE_NUM = 5; 52 static constexpr int MILLSECONDS = 1000; 53 uint64_t timeEventId_ = 0; 54 std::mutex lock_; 55 bool timeEventAdded_ = false; 56 class BBoxListener; 57 std::shared_ptr<BBoxListener> eventListener_; 58 std::shared_ptr<BboxEventRecorder> eventRecorder_; 59 }; 60 } 61 } 62 #endif /* BBOX_DETECTOR_PLUGIN_H */ 63