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 writeNewFile, int writeType) override; 33 int Catch(int fd, int jsonFd) override; 34 bool Init(std::shared_ptr<SysEvent> event); 35 void WriteNewFile(int pid); 36 37 enum WRITE_TYPE { 38 DMESG, 39 SYS_RQ, 40 HUNG_TASK 41 }; 42 private: 43 int writeNewFile_ = 0; 44 int writeType_ = 0; 45 std::shared_ptr<SysEvent> event_; 46 47 bool DumpDmesgLog(int fd); 48 bool WriteSysrqTrigger(); 49 bool DumpToFile(int fd, const std::string& dataStr); 50 #ifdef KERNELSTACK_CATCHER_ENABLE 51 void GetTidsByPid(int pid, std::vector<pid_t>& tids); 52 int DumpKernelStacktrace(int fd, int pid); 53 #endif 54 }; 55 #endif // DMESG_CATCHER_ENABLE 56 } // namespace HiviewDFX 57 } // namespace OHOS 58 #endif // EVENT_LOGGER_DMESG_CATCHER 59