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 public: 33 enum Status { 34 TASK_RUNNABLE = 0, 35 TASK_RUNNING = 1, 36 TASK_SUCCESS = 2, 37 TASK_TIMEOUT = 3, 38 TASK_EXCEED_SIZE = 4, 39 TASK_SUB_TASK_FAIL = 5, 40 TASK_FAIL = 6, 41 TASK_DESTROY = 7, 42 }; 43 44 EventLogTask(int fd, int jsonFd, std::shared_ptr<SysEvent> event); ~EventLogTask()45 virtual ~EventLogTask() {}; 46 void AddLog(const std::string &cmd); 47 EventLogTask::Status StartCompose(); 48 EventLogTask::Status GetTaskStatus() const; 49 long GetLogSize() const; 50 void SetFocusWindowId(const std::string& focusWindowId); 51 private: 52 static constexpr uint32_t MAX_DUMP_TRACE_LIMIT = 15; 53 54 using capture = std::function<void()>; 55 56 int targetFd_; 57 int targetJsonFd_; 58 std::shared_ptr<SysEvent> event_; 59 std::vector<std::shared_ptr<EventLogCatcher>> tasks_; 60 uint32_t maxLogSize_; 61 uint32_t taskLogSize_; 62 volatile Status status_; 63 std::map<std::string, capture> captureList_; 64 int pid_; 65 std::set<int> catchedPids_; 66 std::string focusWindowId_ = ""; 67 68 bool ShouldStopLogTask(int fd, uint32_t curTaskIndex, int curLogSize, std::shared_ptr<EventLogCatcher> catcher); 69 void AddStopReason(int fd, std::shared_ptr<EventLogCatcher> catcher, const std::string& reason); 70 void AddSeparator(int fd, std::shared_ptr<EventLogCatcher> catcher) const; 71 void RecordCatchedPids(const std::string& packageName); 72 73 void AppStackCapture(); 74 void SystemStackCapture(); 75 void BinderLogCapture(); 76 void FfrtCapture(); 77 void MemoryUsageCapture(); 78 bool PeerBinderCapture(const std::string &cmd); 79 void CpuUsageCapture(); 80 void WMSUsageCapture(); 81 void AMSUsageCapture(); 82 void PMSUsageCapture(); 83 void DPMSUsageCapture(); 84 void RSUsageCapture(); 85 void MMIUsageCapture(); 86 void DMSUsageCapture(); 87 void EECStateCapture(); 88 void GECStateCapture(); 89 void UIStateCapture(); 90 void Screenshot(); 91 void HilogCapture(); 92 void LightHilogCapture(); 93 void DmesgCapture(); 94 void SysrqCapture(bool isWriteNewFile); 95 void HitraceCapture(); 96 void SCBSessionCapture(); 97 void SCBViewParamCapture(); 98 void SCBWMSCapture(); 99 void SCBWMSEVTCapture(); 100 void DumpAppMapCapture(); 101 void InputHilogCapture(); 102 }; 103 } // namespace HiviewDFX 104 } // namespace OHOS 105 #endif // EVENT_LOGGER_LOG_TASK_H 106