• 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 "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, 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     std::shared_ptr<SysEvent> event_;
56     std::vector<std::shared_ptr<EventLogCatcher>> tasks_;
57     uint32_t maxLogSize_;
58     uint32_t taskLogSize_;
59     volatile Status status_;
60     std::map<std::string, capture> captureList_;
61     int pid_;
62 
63     bool ShouldStopLogTask(int fd, uint32_t curTaskIndex, int curLogSize, std::shared_ptr<EventLogCatcher> catcher);
64     void AddStopReason(int fd, std::shared_ptr<EventLogCatcher> catcher, const std::string& reason);
65     void AddSeparator(int fd, std::shared_ptr<EventLogCatcher> catcher) const;
66 
67     void AppStackCapture();
68     void SystemStackCapture();
69     void BinderLogCapture();
70     bool PeerBinderCapture(const std::string &cmd);
71     void CpuUsageCapture();
72     void MemoryUsageCapture();
73     void WMSUsageCapture();
74     void AMSUsageCapture();
75     void PMSUsageCapture();
76     void DPMSUsageCapture();
77     void HilogCapture();
78     void DmesgCapture();
79     void SysrqCapture(bool isWriteNewFile);
80 };
81 } // namespace HiviewDFX
82 } // namespace OHOS
83 #endif // EVENT_LOGGER_LOG_TASK_H
84