• 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 "command_catcher.h"
29 #include "event_log_catcher.h"
30 namespace OHOS {
31 namespace HiviewDFX {
32 class EventLogTask {
33     static constexpr int DEFAULT_LOG_SIZE = 1024 * 1024; // 1M
34 public:
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, 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 private:
53     using capture = std::function<void()>;
54 
55     int targetFd_;
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     std::shared_ptr<CommandCatcher> cmdCatcher_;
63 
64     bool ShouldStopLogTask(int fd, uint32_t curTaskIndex, int curLogSize, std::shared_ptr<EventLogCatcher> catcher);
65     void AddStopReason(int fd, std::shared_ptr<EventLogCatcher> catcher, const std::string& reason);
66     void AddSeparator(int fd, std::shared_ptr<EventLogCatcher> catcher) const;
67 
68     std::shared_ptr<CommandCatcher> GetCmdCatcher();
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 };
80 } // namespace HiviewDFX
81 } // namespace OHOS
82 #endif // EVENT_LOGGER_LOG_TASK_H