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 EVENT_LOGGER_EVENT_LOG_TASK_H 16 #define EVENT_LOGGER_EVENT_LOG_TASK_H 17 18 #include <functional> 19 #include <memory> 20 #include <map> 21 #include <string> 22 #include <vector> 23 24 #include "event.h" 25 #include "singleton.h" 26 #include "sys_event.h" 27 28 #include "event_log_catcher.h" 29 namespace OHOS { 30 namespace HiviewDFX { 31 class EventLogTask { 32 static constexpr int DEFAULT_LOG_SIZE = 1024 * 1024; // 1M 33 public: 34 enum Status { 35 TASK_RUNNABLE = 0, 36 TASK_RUNNING = 1, 37 TASK_SUCCESS = 2, 38 TASK_TIMEOUT = 3, 39 TASK_EXCEED_SIZE = 4, 40 TASK_SUB_TASK_FAIL = 5, 41 TASK_FAIL = 6, 42 TASK_DESTROY = 7, 43 }; 44 45 EventLogTask(int fd, int jsonFd, std::shared_ptr<SysEvent> event); ~EventLogTask()46 virtual ~EventLogTask() {}; 47 void AddLog(const std::string &cmd); 48 EventLogTask::Status StartCompose(); 49 EventLogTask::Status GetTaskStatus() const; 50 long GetLogSize() const; 51 private: 52 using capture = std::function<void()>; 53 54 int targetFd_; 55 int targetJsonFd_; 56 std::shared_ptr<SysEvent> event_; 57 std::vector<std::shared_ptr<EventLogCatcher>> tasks_; 58 uint32_t maxLogSize_; 59 uint32_t taskLogSize_; 60 volatile Status status_; 61 std::map<std::string, capture> captureList_; 62 int pid_; 63 std::set<int> catchedPids_; 64 65 bool ShouldStopLogTask(int fd, uint32_t curTaskIndex, int curLogSize, std::shared_ptr<EventLogCatcher> catcher); 66 void AddStopReason(int fd, std::shared_ptr<EventLogCatcher> catcher, const std::string& reason); 67 void AddSeparator(int fd, std::shared_ptr<EventLogCatcher> catcher) const; 68 void RecordCatchedPids(const std::string& packageName); 69 70 void AppStackCapture(); 71 void SystemStackCapture(); 72 void BinderLogCapture(); 73 bool PeerBinderCapture(const std::string &cmd); 74 void CpuUsageCapture(); 75 void MemoryUsageCapture(); 76 void WMSUsageCapture(); 77 void AMSUsageCapture(); 78 void PMSUsageCapture(); 79 void DPMSUsageCapture(); 80 void RSUsageCapture(); 81 void Screenshot(); 82 void HilogCapture(); 83 void LightHilogCapture(); 84 void DmesgCapture(); 85 void SysrqCapture(bool isWriteNewFile); 86 void HitraceCapture(); 87 void SCBSessionCapture(); 88 void SCBViewParamCapture(); 89 }; 90 } // namespace HiviewDFX 91 } // namespace OHOS 92 #endif // EVENT_LOGGER_LOG_TASK_H 93