• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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_SHELL_CATCHER
16 #define EVENT_LOGGER_SHELL_CATCHER
17 
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 #include "event_log_catcher.h"
23 #include "sys_event.h"
24 namespace OHOS {
25 namespace HiviewDFX {
26 class ShellCatcher : public EventLogCatcher {
27 public:
28     explicit ShellCatcher();
~ShellCatcher()29     ~ShellCatcher() override {};
30     bool Initialize(const std::string& cmd, int type, int intParam2) override;
31     void SetCmdArgument(const char* arg[], size_t argSize);
32     int Catch(int fd, int jsonFd) override;
33     void SetEvent(std::shared_ptr<SysEvent> event);
34     void SetFocusWindowId(const std::string& focusWindowId);
35 
36     enum CATCHER_TYPE {
37         CATCHER_UNKNOWN = -1,
38         CATCHER_CPU,
39         CATCHER_WMS,
40         CATCHER_AMS,
41         CATCHER_PMS,
42         CATCHER_DPMS,
43         CATCHER_RS,
44         CATCHER_MMI,
45         CATCHER_DMS,
46         CATCHER_EEC,
47         CATCHER_GEC,
48         CATCHER_UI,
49         CATCHER_SNAPSHOT,
50         CATCHER_HILOG,
51         CATCHER_TAGHILOG,
52         CATCHER_LIGHT_HILOG,
53         CATCHER_SCBSESSION,
54         CATCHER_SCBVIEWPARAM,
55         CATCHER_SCBWMS,
56         CATCHER_SCBWMSEVT,
57         CATCHER_DAM,
58         CATCHER_INPUT_EVENT_HILOG,
59         CATCHER_INPUT_HILOG,
60         CATCHER_SCBWMSV,
61     };
62 private:
63     std::string catcherCmd_ = "";
64     std::string focusWindowId_ = "";
65     int pid_ = -1;
66     CATCHER_TYPE catcherType_ = CATCHER_TYPE::CATCHER_UNKNOWN;
67     std::shared_ptr<SysEvent> event_ = nullptr;
68 
69     int DoOtherChildProcesscatcher(int writeFd);
70     void DoChildProcess(int writeFd);
71     bool ReadShellToFile(int fd, const std::string& cmd);
72 
73 #ifdef HILOG_CATCHER_ENABLE
74     int DoHilogCatcher(int writeFd);
75 #endif // HILOG_CATCHER_ENABLE
76 
77 #ifdef USAGE_CATCHER_ENABLE
78     int DoUsageCatcher(int writeFd);
79     void GetCpuCoreFreqInfo(int fd) const;
80 #endif // USAGE_CATCHER_ENABLE
81 
82 #ifdef SCB_CATCHER_ENABLE
83     int DoScbCatcher(int writeFd);
84 #endif // SCB_CATCHER_ENABLE
85 
86 #ifdef OTHER_CATCHER_ENABLE
87     int DoOtherCatcher(int writeFd);
88 #endif // OTHER_CATCHER_ENABLE
89 };
90 } // namespace HiviewDFX
91 } // namespace OHOS
92 #endif // EVENT_LOGGER_SHELL_CATCHER
93