1 /* 2 * Copyright (C) 2023 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 EVENT_LOGGER_DMESG_CATCHER 16 #define EVENT_LOGGER_DMESG_CATCHER 17 18 #include <map> 19 #include <string> 20 #include <vector> 21 22 #include "sys_event.h" 23 24 #include "event_log_catcher.h" 25 namespace OHOS { 26 namespace HiviewDFX { 27 #ifdef DMESG_CATCHER_ENABLE 28 class DmesgCatcher : public EventLogCatcher { 29 public: 30 explicit DmesgCatcher(); ~DmesgCatcher()31 ~DmesgCatcher() override {}; 32 bool Initialize(const std::string& packageNam, int isWriteNewFile, int needWriteSysrq) override; 33 int Catch(int fd, int jsonFd) override; 34 bool Init(std::shared_ptr<SysEvent> event); 35 void WriteNewSysrq(); 36 37 private: 38 bool isWriteNewFile_ = false; 39 bool needWriteSysrq_ = false; 40 std::shared_ptr<SysEvent> event_; 41 42 bool DumpDmesgLog(int fd); 43 bool WriteSysrq(); 44 bool DumpSysrqToFile(int fd, char *buffer, int size); 45 }; 46 #endif // DMESG_CATCHER_ENABLE 47 } // namespace HiviewDFX 48 } // namespace OHOS 49 #endif // EVENT_LOGGER_DMESG_CATCHER 50