1 /* 2 * Copyright (C) 2024 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 OHOS_IPC_PAYLOAD_STATISTICS_H 17 #define OHOS_IPC_PAYLOAD_STATISTICS_H 18 19 #include "ipc_payload_statistics_impl.h" 20 21 namespace OHOS { 22 class IPCPayloadStatistics { 23 public: 24 IPCPayloadStatistics() = default; 25 ~IPCPayloadStatistics() = default; 26 27 /** 28 * @brief Obtain the total number of times the entire process has been processed. 29 * @return Returns the total number of times the entire process has been retrieved. 30 * @since 12 31 */ 32 static uint64_t GetTotalCount(); 33 34 /** 35 * @brief Obtain the total time spent on all processes. 36 * @return Returns the total time spent on all processes. 37 * @since 12 38 */ 39 static uint64_t GetTotalCost(); 40 41 /** 42 * @brief Obtain the PID of all processes as a whole. 43 * @return Return a vector<int32_t>, which internally stores the PID of all processes obtained. 44 * @since 12 45 */ 46 static std::vector<int32_t> GetPids(); 47 48 /** 49 * @brief Obtain the total number of times the corresponding process has been processed. 50 * @param pid is the process number. 51 * @return Return the total number of times the corresponding process has been processed. 52 * @since 12 53 */ 54 static uint64_t GetCount(const int32_t pid); 55 56 /** 57 * @brief Obtain the total time spent on the corresponding process. 58 * @param pid is the process number. 59 * @return Return the total time taken by the corresponding process. 60 * @since 12 61 */ 62 static uint64_t GetCost(const int32_t pid); 63 64 /** 65 * @brief Obtain the descriptor and code of the corresponding process. 66 * @param pid is the process number. 67 * @return Return a vector<IPCInterfaceInfo>, which contains all the descriptor and 68 * code of the corresponding process in the container. 69 * @since 12 70 */ 71 static std::vector<IPCInterfaceInfo> GetDescriptorCodes(const int32_t pid); 72 73 /** 74 * @brief Obtain the number of times corresponding to the specified pid, decs, and code. 75 * @param pid is the process number. 76 * @param desc is the interface descriptor used for IPC communication. 77 * @param code is the communication code used for IPC communication. 78 * @return Return the number of times corresponding to the specified pid, decs, and code. 79 * @since 12 80 */ 81 static uint64_t GetDescriptorCodeCount(const int32_t pid, const std::u16string &desc, const int32_t code); 82 83 /** 84 * @brief Obtain the total time consumption corresponding to the specified pid, decs, and code. 85 * @param pid is the process number. 86 * @param desc is the interface descriptor used for IPC communication. 87 * @param code is the communication code used for IPC communication. 88 * @return Returns the total time consumption corresponding to the specified pid, decs, and code. 89 * @since 12 90 */ 91 static IPCPayloadCost GetDescriptorCodeCost(const int32_t pid, const std::u16string &desc, const int32_t code); 92 93 /** 94 * @brief Start IPC load statistics. 95 * @return Returns <b>true</b> if the operation succeeds; return <b>false</b> Otherwise. 96 * @since 12 97 */ 98 static bool StartStatistics(); 99 100 /** 101 * @brief Stop IPC load statistics. 102 * @return Returns <b>true</b> if the operation succeeds; return <b>false</b> Otherwise. 103 * @since 12 104 */ 105 static bool StopStatistics(); 106 107 /** 108 * @brief Obtain the current IPC load statistics status. 109 * @return Returns <b>true</b> if the operation succeeds,Indicates that statistics are currently enabled; 110 * return <b>false</b>,Indicates that the statistics have been stopped currently. 111 * @since 12 112 */ 113 static bool GetStatisticsStatus(); 114 115 /** 116 * @brief Clear all the data that has already been counted. 117 * @return Returns <b>true</b> if the operation succeeds; return <b>false</b> Otherwise. 118 * @since 12 119 */ 120 static bool ClearStatisticsData(); 121 }; 122 } // namespace OHOS 123 #endif // OHOS_IPC_PAYLOAD_STATISTICS_H