• 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 
16 #ifndef SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_DUMPER_H
17 #define SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_DUMPER_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "schedule/system_ability_state_scheduler.h"
23 #include "system_ability_manager.h"
24 #include "if_local_ability_manager.h"
25 
26 namespace OHOS {
27 enum {
28     IPC_STAT_PREFIX_INDEX = 0,
29     IPC_STAT_PROCESS_INDEX = 1,
30     IPC_STAT_CMD_INDEX = 2
31 };
32 
33 enum {
34     FFRT_STAT_PREFIX_INDEX = 0,
35     FFRT_STAT_PROCESS_INDEX = 1,
36     FFRT_STAT_CMD_INDEX = 2
37 };
38 constexpr int32_t IPC_STAT_CMD_LEN = 3;
39 
40 class SystemAbilityManagerDumper {
41 public:
42     static bool Dump(std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler,
43         const std::vector<std::string>& args, std::string& result);
44     static bool IpcDumpCmdParser(int32_t& cmd, const std::vector<std::string>& args);
45     static bool IpcDumpIsAllProcess(const std::string& processName);
46     static bool IpcDumpIsSamgr(const std::string& processName);
47     static bool StartSamgrIpcStatistics(std::string& result);
48     static bool StopSamgrIpcStatistics(std::string& result);
49     static bool GetSamgrIpcStatistics(std::string& result);
50     static bool FfrtDumpParser(std::vector<int32_t>& processIds, const std::string& processIdsStr);
51     static int32_t FfrtDumpProc(std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler,
52         int32_t fd, const std::vector<std::string>& args);
53     static void GetFfrtLoadMetrics(std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler,
54         int32_t fd, const std::vector<std::string>& args, std::string& result);
55     static bool FfrtStatCmdParser(int32_t& cmd, const std::vector<std::string>& args);
56     static void CollectFfrtMetricInfoInProcs(int32_t fd, const std::vector<int32_t>& processIds,
57         std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler, int32_t cmd, std::string& result);
58     static sptr<ILocalAbilityManager> GetProcByProcessId(
59         std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler, int32_t processId);
60     static bool GetFfrtDumpInfoProc(std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler,
61         const std::vector<std::string>& args, std::string& result);
62     static int32_t ListenerDumpProc(std::map<int32_t, std::list<SAListener>>& listeners,
63         int32_t fd, const std::vector<std::string>& args);
64 
65 private:
66     SystemAbilityManagerDumper() = default;
67     ~SystemAbilityManagerDumper() = default;
68     static bool CollectFfrtStatistics(int32_t cmd, std::string& result);
69     static bool StartFfrtStatistics(std::string& result);
70     static bool StopFfrtStatistics(std::string& result);
71     static bool GetFfrtStatistics(std::string& result);
72     static void FfrtStatisticsParser(std::string& result);
73     static void ClearFfrtStatisticsBufferLocked();
74     static void ClearFfrtStatistics();
75     static bool CanDump();
76     static void ShowHelp(std::string& result);
77     static void ShowAllSystemAbilityInfo(std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler,
78         std::string& result);
79     static void ShowSystemAbilityInfo(int32_t said,
80         std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler, std::string& result);
81     static void ShowProcessInfo(const std::string& processName,
82         std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler, std::string& result);
83     static void ShowAllSystemAbilityInfoInState(const std::string& state,
84         std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler, std::string& result);
85     static void IllegalInput(std::string& result);
86     static void DumpFfrtInfoInProc(
87         std::shared_ptr<SystemAbilityStateScheduler> abilityStateScheduler, int32_t pid, std::string& result);
88     static int32_t SaveDumpResultToFd(int32_t fd, const std::string& result);
89     static void GetSAMgrFfrtInfo(std::string& result);
90     static void GetListenerDumpProc(std::map<int32_t, std::list<SAListener>>& listeners,
91         const std::vector<std::string>& args, std::string& result);
92     static void ShowAllBySA(std::map<int32_t, std::list<SAListener>>& listeners, std::string& result);
93     static void ShowAllByCallingPid(std::map<int32_t, std::list<SAListener>>& listeners,
94         std::string& result);
95     static void ShowCallingPidBySA(std::map<int32_t, std::list<SAListener>>& listeners,
96         int32_t said, std::string& result);
97     static void ShowSAByCallingPid(std::map<int32_t, std::list<SAListener>>& listeners,
98         int32_t pid, std::string& result);
99     static void ShowListenerHelp(std::string& result);
100     static std::shared_ptr<FFRTHandler> handler_;
101     static char* ffrtMetricBuffer;
102     static bool collectEnable;
103     static samgr::mutex ffrtMetricLock;
104 };
105 } // namespace OHOS
106 #endif // SERVICES_SAMGR_NATIVE_INCLUDE_SYSTEM_ABILITY_MANAGER_DUMPER_H