• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ffrt.h"
26 #include "singleton.h"
27 #include "sys_event.h"
28 
29 #include "event_log_catcher.h"
30 namespace OHOS {
31 namespace HiviewDFX {
32 class EventLogTask {
33 public:
34     std::string terminalThreadStack_ = "";
35     enum Status {
36         TASK_RUNNABLE = 0,
37         TASK_RUNNING = 1,
38         TASK_SUCCESS = 2,
39         TASK_TIMEOUT = 3,
40         TASK_EXCEED_SIZE = 4,
41         TASK_SUB_TASK_FAIL = 5,
42         TASK_FAIL = 6,
43         TASK_DESTROY = 7,
44     };
45 
46     EventLogTask(int fd, int jsonFd, std::shared_ptr<SysEvent> event);
~EventLogTask()47     virtual ~EventLogTask() {};
48     void AddLog(const std::string &cmd);
49     EventLogTask::Status StartCompose();
50     EventLogTask::Status GetTaskStatus() const;
51     long GetLogSize() const;
52     void SetFocusWindowId(const std::string& focusWindowId);
53 private:
54     static constexpr uint32_t MAX_DUMP_TRACE_LIMIT = 15;
55 
56     using capture = std::function<void()>;
57 
58     int targetFd_;
59     int targetJsonFd_;
60     std::shared_ptr<SysEvent> event_;
61     std::vector<std::shared_ptr<EventLogCatcher>> tasks_;
62     uint32_t maxLogSize_;
63     uint32_t taskLogSize_;
64     volatile Status status_;
65     std::map<std::string, capture> captureList_;
66     int pid_;
67     std::set<int> catchedPids_;
68     std::string focusWindowId_ = "";
69     bool memoryCatched_ = false;
70     uint64_t faultTime_ = 0;
71     ffrt::mutex faultTimeMutex_;
72 
73     void AddCapture();
74     bool ShouldStopLogTask(int fd, uint32_t curTaskIndex, int curLogSize, std::shared_ptr<EventLogCatcher> catcher);
75     void AddStopReason(int fd, std::shared_ptr<EventLogCatcher> catcher, const std::string& reason);
76     void AddSeparator(int fd, std::shared_ptr<EventLogCatcher> catcher) const;
77     void RecordCatchedPids(const std::string& packageName);
78     void GetThermalInfoCapture();
79     void SaveRsVulKanError();
80     void SaveSummaryLogInfo();
81     uint64_t GetFaultTime();
82 
83 #ifdef STACKTRACE_CATCHER_ENABLE
84     void AppStackCapture();
85     void SystemStackCapture();
86     void RemoteStackCapture();
87     void GetProcessStack(const std::string& processName);
88     void GetGPUProcessStack();
89     void GetStackByProcessName();
90 #endif // STACKTRACE_CATCHER_ENABLE
91 
92 #ifdef BINDER_CATCHER_ENABLE
93     void BinderLogCapture();
94     bool PeerBinderCapture(const std::string &cmd);
95 #endif // BINDER_CATCHER_ENABLE
96 
97 #ifdef DMESG_CATCHER_ENABLE
98     void DmesgCapture(bool writeNewFile, int type);
99 #endif // DMESG_CATCHER_ENABLE
100 
101 #ifdef HILOG_CATCHER_ENABLE
102     void HilogCapture();
103     void HilogTagCapture();
104     void LightHilogCapture();
105     void InputHilogCapture();
106 #endif // HILOG_CATCHER_ENABLE
107 
108 #ifdef HITRACE_CATCHER_ENABLE
109     void HitraceCapture(bool isBetaVersion);
110 #endif // HITRACE_CATCHER_ENABLE
111 
112 #ifdef USAGE_CATCHER_ENABLE
113     void MemoryUsageCapture();
114     void CpuUsageCapture();
115     void WMSUsageCapture();
116     void AMSUsageCapture();
117     void PMSUsageCapture();
118     void DPMSUsageCapture();
119     void RSUsageCapture();
120     void DumpAppMapCapture();
121     void CpuCoreInfoCapture();
122 #endif // USAGE_CATCHER_ENABLE
123 
124 #ifdef SCB_CATCHER_ENABLE
125     void SCBSessionCapture();
126     void SCBViewParamCapture();
127     void SCBWMSCapture();
128     void SCBWMSEVTCapture();
129     void SCBWMSVCapture();
130 #endif // SCB_CATCHER_ENABLE
131 
132 #ifdef OTHER_CATCHER_ENABLE
133     void FfrtCapture();
134     void MMIUsageCapture();
135     void DMSUsageCapture();
136     void EECStateCapture();
137     void GECStateCapture();
138     void UIStateCapture();
139     void Screenshot();
140 #endif // OTHER_CATCHER_ENABLE
141 };
142 } // namespace HiviewDFX
143 } // namespace OHOS
144 #endif // EVENT_LOGGER_LOG_TASK_H
145