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 std::string terminalThreadStack_ = ""; 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 void SetFocusWindowId(const std::string& focusWindowId); 52 private: 53 static constexpr uint32_t MAX_DUMP_TRACE_LIMIT = 15; 54 55 using capture = std::function<void()>; 56 57 int targetFd_; 58 int targetJsonFd_; 59 std::shared_ptr<SysEvent> event_; 60 std::vector<std::shared_ptr<EventLogCatcher>> tasks_; 61 uint32_t maxLogSize_; 62 uint32_t taskLogSize_; 63 volatile Status status_; 64 std::map<std::string, capture> captureList_; 65 int pid_; 66 std::set<int> catchedPids_; 67 std::string focusWindowId_ = ""; 68 bool memoryCatched_ = false; 69 70 void AddCapture(); 71 bool ShouldStopLogTask(int fd, uint32_t curTaskIndex, int curLogSize, std::shared_ptr<EventLogCatcher> catcher); 72 void AddStopReason(int fd, std::shared_ptr<EventLogCatcher> catcher, const std::string& reason); 73 void AddSeparator(int fd, std::shared_ptr<EventLogCatcher> catcher) const; 74 void RecordCatchedPids(const std::string& packageName); 75 void GetThermalInfo(int fd); 76 77 #ifdef STACKTRACE_CATCHER_ENABLE 78 void AppStackCapture(); 79 void SystemStackCapture(); 80 void RemoteStackCapture(); 81 void GetProcessStack(const std::string& processName); 82 void GetGPUProcessStack(); 83 void GetSpecificProcessStack(); 84 #endif // STACKTRACE_CATCHER_ENABLE 85 86 #ifdef BINDER_CATCHER_ENABLE 87 void BinderLogCapture(); 88 bool PeerBinderCapture(const std::string &cmd); 89 #endif // BINDER_CATCHER_ENABLE 90 91 #ifdef DMESG_CATCHER_ENABLE 92 void DmesgCapture(); 93 void SysrqCapture(bool isWriteNewFile); 94 #endif // DMESG_CATCHER_ENABLE 95 96 #ifdef HILOG_CATCHER_ENABLE 97 void HilogCapture(); 98 void HilogTagCapture(); 99 void LightHilogCapture(); 100 void InputHilogCapture(); 101 #endif // HILOG_CATCHER_ENABLE 102 103 #ifdef HITRACE_CATCHER_ENABLE 104 void HitraceCapture(); 105 #endif // HITRACE_CATCHER_ENABLE 106 107 #ifdef USAGE_CATCHER_ENABLE 108 void MemoryUsageCapture(); 109 void CpuUsageCapture(); 110 void WMSUsageCapture(); 111 void AMSUsageCapture(); 112 void PMSUsageCapture(); 113 void DPMSUsageCapture(); 114 void RSUsageCapture(); 115 void DumpAppMapCapture(); 116 #endif // USAGE_CATCHER_ENABLE 117 118 #ifdef SCB_CATCHER_ENABLE 119 void SCBSessionCapture(); 120 void SCBViewParamCapture(); 121 void SCBWMSCapture(); 122 void SCBWMSEVTCapture(); 123 #endif // SCB_CATCHER_ENABLE 124 125 #ifdef OTHER_CATCHER_ENABLE 126 void FfrtCapture(); 127 void MMIUsageCapture(); 128 void DMSUsageCapture(); 129 void EECStateCapture(); 130 void GECStateCapture(); 131 void UIStateCapture(); 132 void Screenshot(); 133 #endif // OTHER_CATCHER_ENABLE 134 }; 135 } // namespace HiviewDFX 136 } // namespace OHOS 137 #endif // EVENT_LOGGER_LOG_TASK_H 138