From dd2fa5646d192f768616960746216455cd71aa31 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Mon, 26 Aug 2024 23:10:05 +0800 Subject: [PATCH 1/9] hdf ipc dump Signed-off-by: xiongchangwu --- adapter/uhdf2/hdi/src/idevmgr_client.cpp | 6 ++++++ interfaces/inner_api/hdi/idevmgr_hdi.h | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/adapter/uhdf2/hdi/src/idevmgr_client.cpp b/adapter/uhdf2/hdi/src/idevmgr_client.cpp index a339d7243..1843260b4 100644 --- a/adapter/uhdf2/hdi/src/idevmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/idevmgr_client.cpp @@ -49,6 +49,7 @@ public: int32_t LoadDevice(const std::string &serviceName) override; int32_t UnloadDevice(const std::string &serviceName) override; int32_t ListAllDevice(std::vector &deviceInfos) override; + int32_t ListAllHost(std::vector &pidList) override; private: static inline BrokerDelegator delegator_; @@ -183,6 +184,11 @@ int32_t DeviceManagerProxy::ListAllDevice(std::vector &deviceInf return status; } +int32_t DeviceManagerProxy::ListAllHost(std::vector &pidList) +{ + return HDF_SUCCESS; +} + sptr IDeviceManager::Get() { auto servmgr = ServiceManager::V1_0::IServiceManager::Get(); diff --git a/interfaces/inner_api/hdi/idevmgr_hdi.h b/interfaces/inner_api/hdi/idevmgr_hdi.h index 05f5caf4a..d7440e663 100644 --- a/interfaces/inner_api/hdi/idevmgr_hdi.h +++ b/interfaces/inner_api/hdi/idevmgr_hdi.h @@ -108,6 +108,14 @@ public: * @return Returns HDF_SUCCESS if the operation is successful; otherwise, the operation fails. */ virtual int32_t ListAllDevice(std::vector &deviceInfos) = 0; + + /** + * @brief Obtains pid about all hosts. + * + * @param pidList Indicates information about all hosts. + * @return Returns HDF_SUCCESS if the operation is successful; otherwise, the operation fails. + */ + virtual int32_t ListAllHost(std::vector &pidList) = 0; }; } // namespace V1_0 } // namespace DeviceManager -- Gitee From 3c9695b57919e09aaf05d4763ed0210071f73a43 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Tue, 27 Aug 2024 10:27:45 +0800 Subject: [PATCH 2/9] hdf ipc dump Signed-off-by: xiongchangwu --- adapter/uhdf2/hdi/src/idevmgr_client.cpp | 39 ++++- adapter/uhdf2/host/src/devhost_dump.c | 10 ++ adapter/uhdf2/ipc/src/hdf_dump.cpp | 106 ++++++++++++++ adapter/uhdf2/manager/src/devmgr_dump.c | 137 +++++++++++++++++- .../uhdf2/manager/src/devmgr_service_stub.c | 13 ++ .../manager/include/devhost_service_clnt.h | 1 + framework/core/manager/src/devmgr_service.c | 22 +++ .../core/shared/include/devmgr_service_if.h | 1 + interfaces/inner_api/ipc/hdf_dump_reg.h | 2 + 9 files changed, 329 insertions(+), 2 deletions(-) diff --git a/adapter/uhdf2/hdi/src/idevmgr_client.cpp b/adapter/uhdf2/hdi/src/idevmgr_client.cpp index 1843260b4..ab0c50026 100644 --- a/adapter/uhdf2/hdi/src/idevmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/idevmgr_client.cpp @@ -40,6 +40,7 @@ enum DevmgrCmdId : uint32_t { DEVMGR_SERVICE_UNLOAD_DEVICE, DEVMGR_SERVICE_QUERY_DEVICE, DEVMGR_SERVICE_LIST_ALL_DEVICE, + DEVMGR_SERVICE_LIST_ALL_HOST, }; class DeviceManagerProxy : public IProxyBroker { @@ -184,9 +185,45 @@ int32_t DeviceManagerProxy::ListAllDevice(std::vector &deviceInf return status; } +static void HdfDevMgrFillPidList(std::vector &pidList, MessageParcel &reply) +{ + uint32_t count = 0; + HdfSbufReadUint32(reply, &count); + + int pid = -1; + for(uint32_t i = 0; i < count; ++i) { + HdfSbufReadInt32(reply, &pid); + pidList.push_back(pid); + } + + return; +} + int32_t DeviceManagerProxy::ListAllHost(std::vector &pidList) { - return HDF_SUCCESS; + MessageParcel data; + MessageParcel reply; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return HDF_FAILURE; + } + + MessageOption option; + std::unique_lock lock(g_remoteMutex); + if (Remote() == nullptr) { + HDF_LOGE("invalid param Remote()"); + return HDF_ERR_INVALID_PARAM; + } + int status = Remote()->SendRequest( + static_cast(HdfDeviceManagerInterfaceCode::DEVMGR_SERVICE_LIST_ALL_HOST), data, reply, option); + lock.unlock(); + if (status != HDF_SUCCESS) { + HDF_LOGE("list all service info failed, %{public}d", status); + return status; + } else { + HdfDevMgrFillPidList(pidList, reply); + } + HDF_LOGD("get all service info success"); + return status; } sptr IDeviceManager::Get() diff --git a/adapter/uhdf2/host/src/devhost_dump.c b/adapter/uhdf2/host/src/devhost_dump.c index 7fb9ab93f..4ec75d917 100644 --- a/adapter/uhdf2/host/src/devhost_dump.c +++ b/adapter/uhdf2/host/src/devhost_dump.c @@ -21,6 +21,7 @@ #include "hdf_log.h" #include "osal_mem.h" #include "osal_mutex.h" +#include "hdf_dump_reg.h" #define HDF_LOG_TAG devhost_dump @@ -157,6 +158,15 @@ void DevHostDump(struct HdfSBuf *data, struct HdfSBuf *reply) if (!dumpFlag) { (void)HdfSbufWriteString(reply, "The service does not register dump function\n"); } + } else if (strcmp(option, "--ipc") == 0) { + int32_t fd = -1; + HdfSbufReadInt32(data, &fd); + HDF_LOGI("%{public}s %{public}d", option, fd); + const char *dumpCmd = HdfSbufReadString(data); + if (dumpCmd == NULL) { + return; + } + HdfDumpIpcStat(fd, dumpCmd); } else { HDF_LOGE("%{public}s invalid parameter %{public}s", __func__, option); } diff --git a/adapter/uhdf2/ipc/src/hdf_dump.cpp b/adapter/uhdf2/ipc/src/hdf_dump.cpp index 082becd47..c981c2ed0 100644 --- a/adapter/uhdf2/ipc/src/hdf_dump.cpp +++ b/adapter/uhdf2/ipc/src/hdf_dump.cpp @@ -15,21 +15,123 @@ #include "hdf_dump.h" +#include "ipc_payload_statistics.h" + #include "file_ex.h" #include "string_ex.h" +#include "unistd.h" #include "hdf_base.h" #include "hdf_dump_reg.h" #include "hdf_log.h" #include "hdf_sbuf.h" +#include "securec.h" #define HDF_LOG_TAG hdf_dump +using namespace OHOS; + static DevHostDumpFunc g_dump = nullptr; +const char *HDF_DUMP_SUCCESS_STR = " success\n"; +const char *HDF_DUMP_FAIL_STR = " fail\n"; + // The maximum parameter is the parameter sent to the host, including public(num=2) and private(mux_num=20) parameters static constexpr int32_t MAX_PARA_NUM = 22; +static bool HdfDumpIpcStatStart(std::string& result) +{ + result = std::string("HdfDumperIpcStatStart pid:") + std::to_string(getpid()); + bool ret = IPCPayloadStatistics::StartStatistics(); + result += ret ? HDF_DUMP_SUCCESS_STR : HDF_DUMP_FAIL_STR; + return ret; +} + +static int32_t HdfDumpIpcStatStop(std::string& result) +{ + result = std::string("HdfDumperIpcStatStop pid:") + std::to_string(getpid()); + bool ret = IPCPayloadStatistics::StopStatistics(); + result += ret ? HDF_DUMP_SUCCESS_STR : HDF_DUMP_FAIL_STR; + return ret; +} + +static int32_t HdfDumpIpcStatGet(std::string& result) +{ + result += "********************************GlobalStatisticsInfo********************************"; + result += "\nCurrentPid:"; + result += std::to_string(getpid()); + result += "\nTotalCount:"; + result += std::to_string(IPCPayloadStatistics::GetTotalCount()); + result += "\nTotalTimeCost:"; + result += std::to_string(IPCPayloadStatistics::GetTotalCost()); + std::vector pids; + pids = IPCPayloadStatistics::GetPids(); + for (unsigned int i = 0; i < pids.size(); i++) { + result += "\n--------------------------------ProcessStatisticsInfo-------------------------------"; + result += "\nCallingPid:"; + result += std::to_string(pids[i]); + result += "\nCallingPidTotalCount:"; + result += std::to_string(IPCPayloadStatistics::GetCount(pids[i])); + result += "\nCallingPidTotalTimeCost:"; + result += std::to_string(IPCPayloadStatistics::GetCost(pids[i])); + std::vector intfs; + intfs = IPCPayloadStatistics::GetDescriptorCodes(pids[i]); + for (unsigned int j = 0; j < intfs.size(); j++) { + result += "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~InterfaceStatisticsInfo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; + result += "\nDescriptorCode:"; + result += Str16ToStr8(intfs[j].desc) + std::string("_") + std::to_string(intfs[j].code); + result += "\nDescriptorCodeCount:"; + result += std::to_string( + IPCPayloadStatistics::GetDescriptorCodeCount(pids[i], intfs[j].desc, intfs[j].code)); + result += "\nDescriptorCodeTimeCost:"; + result += "\nTotal:"; + result += std::to_string( + IPCPayloadStatistics::GetDescriptorCodeCost(pids[i], intfs[j].desc, intfs[j].code).totalCost); + result += " | Max:"; + result += std::to_string( + IPCPayloadStatistics::GetDescriptorCodeCost(pids[i], intfs[j].desc, intfs[j].code).maxCost); + result += " | Min:"; + result += std::to_string( + IPCPayloadStatistics::GetDescriptorCodeCost(pids[i], intfs[j].desc, intfs[j].code).minCost); + result += " | Avg:"; + result += std::to_string( + IPCPayloadStatistics::GetDescriptorCodeCost(pids[i], intfs[j].desc, intfs[j].code).averCost); + result += "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; + } + result += "\n------------------------------------------------------------------------------------"; + } + result += "\n************************************************************************************\n"; + + return true; +} + +bool HdfDumpIpcStat(int32_t fd, const char *cmd) +{ + if (cmd == NULL) { + HDF_LOGE("%{public}s cmd is null", __func__); + return HDF_FAILURE; + } + + bool ret = false; + std::string result; + HDF_LOGI("%{public}s %{public}d", cmd, fd); + if (strcmp(cmd, "--start-stat") == 0) { + ret = HdfDumpIpcStatStart(result); + } else if (strcmp(cmd, "--stop-stat") == 0) { + ret = HdfDumpIpcStatStop(result); + } else if (strcmp(cmd, "--stat") == 0) { + ret = HdfDumpIpcStatGet(result); + } else { + return ret; + } + + if (!OHOS::SaveStringToFd(fd, result)) { + ret = false; + } + + return ret; +} + void HdfRegisterDumpFunc(DevHostDumpFunc dump) { g_dump = dump; @@ -64,6 +166,10 @@ int32_t HdfDump(int32_t fd, const std::vector &args) goto FINISHED; } + if (!HdfSbufWriteInt32(data, fd)) { + goto FINISHED; + } + if (!HdfSbufWriteUint32(data, argv)) { goto FINISHED; } diff --git a/adapter/uhdf2/manager/src/devmgr_dump.c b/adapter/uhdf2/manager/src/devmgr_dump.c index 8a0b7bfdb..c93889bd9 100644 --- a/adapter/uhdf2/manager/src/devmgr_dump.c +++ b/adapter/uhdf2/manager/src/devmgr_dump.c @@ -29,7 +29,7 @@ #include "devmgr_dump.h" #define HDF_LOG_TAG devmgr_dump - + static const char *HELP_COMMENT = " usage:\n" " -help :display help information\n" @@ -192,6 +192,136 @@ static int32_t DevMgrDumpService(uint32_t argv, struct HdfSBuf *data, struct Hdf return ret; } +static int32_t DevMgrDumpAllHostIpcStats(struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance(); + if (devMgrSvc == NULL) { + return HDF_FAILURE; + } + + struct DevHostServiceClnt *hostClnt = NULL; + int32_t ret = HDF_FAILURE; + DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { + HDF_LOGI("%{public}s hostName:%{public}s", __func__, hostClnt->hostName); + if (hostClnt->hostService == NULL || hostClnt->hostService->Dump == NULL) { + HDF_LOGI("The host does not start\n"); + continue; + } + ret = hostClnt->hostService->Dump(hostClnt->hostService, data, reply); + } + + return ret; +} + +static int32_t DevMgrDumpAllHostIpcStat(int32_t fd, const char *cmd, struct HdfSBuf *reply) +{ + struct HdfSBuf *ipcData = HdfSbufTypedObtain(SBUF_IPC); + if (ipcData == NULL) { + return HDF_FAILURE; + } + + if (!HdfSbufWriteString(ipcData, "--ipc")) { + HdfSbufRecycle(ipcData); + return HDF_FAILURE; + } + + if (!HdfSbufWriteInt32(ipcData, fd)) { + HdfSbufRecycle(ipcData); + return HDF_FAILURE; + } + + if (!HdfSbufWriteString(ipcData, cmd)) { + HdfSbufRecycle(ipcData); + return HDF_FAILURE; + } + + int32_t ret = DevMgrDumpAllHostIpcStats(ipcData, reply); + HdfSbufRecycle(ipcData); + return ret; +} + +static int32_t DevMgrDumpSingleHostIpcStats(int32_t pid, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + struct DevmgrService *devMgrSvc = (struct DevmgrService *)DevmgrServiceGetInstance(); + if (devMgrSvc == NULL) { + return HDF_FAILURE; + } + + struct DevHostServiceClnt *hostClnt = NULL; + int32_t ret = HDF_FAILURE; + DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { + HDF_LOGI("%{public}s hostName:%{public}s %{public}d %{public}d", __func__, + hostClnt->hostName, hostClnt->hostProcessId, pid); + if (hostClnt->hostService == NULL || hostClnt->hostService->Dump == NULL) { + HDF_LOGI("The host does not start\n"); + continue; + } + if (hostClnt->hostProcessId == pid) { + ret = hostClnt->hostService->Dump(hostClnt->hostService, data, reply); + break; + } + } + + return ret; +} + +static int32_t DevMgrDumpSingleHostIpcStat(int32_t pid, int32_t fd, const char *cmd, struct HdfSBuf *reply) +{ + struct HdfSBuf *ipcData = HdfSbufTypedObtain(SBUF_IPC); + if (ipcData == NULL) { + return HDF_FAILURE; + } + + if (!HdfSbufWriteString(ipcData, "--ipc")) { + HdfSbufRecycle(ipcData); + return HDF_FAILURE; + } + + if (!HdfSbufWriteInt32(ipcData, fd)) { + HdfSbufRecycle(ipcData); + return HDF_FAILURE; + } + + if (!HdfSbufWriteString(ipcData, cmd)) { + HdfSbufRecycle(ipcData); + return HDF_FAILURE; + } + + int32_t ret = DevMgrDumpSingleHostIpcStats(pid, ipcData, reply); + HdfSbufRecycle(ipcData); + return ret; +} + +static int32_t DevMgrDumpIpc(int32_t fd, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + const char *value = HdfSbufReadString(data); + if (value == NULL) { + HDF_LOGE("%{public}s value is null", __func__); + return HDF_FAILURE; + } + + const char *dumpCmd = HdfSbufReadString(data); + if (dumpCmd == NULL) { + HDF_LOGE("%{public}s dumpCmd is null", __func__); + return HDF_FAILURE; + } + + HDF_LOGI("%{public}s %{public}s fd:%{public}d", value, dumpCmd, fd); + if (strcmp(value, "all") == 0) { + HdfDumpIpcStat(fd, dumpCmd); + return DevMgrDumpAllHostIpcStat(fd, dumpCmd, reply); + } else { + int32_t pid = stoi(value); + if (pid == getpid()){ + HdfDumpIpcStat(fd, dumpCmd); + } else { + DevMgrDumpSingleHostIpcStat(pid, fd, dumpCmd, reply); + } + } + + return HDF_SUCCESS; +} + static int32_t DevMgrFillDeviceHostInfo(struct HdfSBuf *data, struct HdfSBuf *reply) { const char *name = HdfSbufReadString(data); @@ -470,6 +600,9 @@ static int32_t DevMgrDump(struct HdfSBuf *data, struct HdfSBuf *reply) return HDF_FAILURE; } + int32_t fd = -1; + HdfSbufReadInt32(data, &fd); + uint32_t argv = 0; HdfSbufReadUint32(data, &argv); @@ -501,6 +634,8 @@ static int32_t DevMgrDump(struct HdfSBuf *data, struct HdfSBuf *reply) return DevMgrDumpHost(argv - 1, data, reply); } else if (strcmp(value, "-service") == 0) { return DevMgrDumpService(argv - 1, data, reply); + } else if (strcmp(value, "--ipc") == 0) { + return DevMgrDumpIpc(fd, data, reply); } else { (void)HdfSbufWriteString(reply, HELP_COMMENT); return HDF_SUCCESS; diff --git a/adapter/uhdf2/manager/src/devmgr_service_stub.c b/adapter/uhdf2/manager/src/devmgr_service_stub.c index ad7b82989..61e21d5f6 100644 --- a/adapter/uhdf2/manager/src/devmgr_service_stub.c +++ b/adapter/uhdf2/manager/src/devmgr_service_stub.c @@ -109,6 +109,16 @@ static int32_t DevmgrServiceStubDispatchListAllDevice(struct IDevmgrService *dev return devmgrSvc->ListAllDevice(devmgrSvc, reply); } +static int32_t DevmgrServiceStubListAllHost(struct IDevmgrService *devmgrSvc, struct HdfSBuf *reply) +{ + if (reply == NULL) { + HDF_LOGE("%{public}s:service name is null", __func__); + return HDF_ERR_INVALID_PARAM; + } + HDF_LOGD("%{public}s:get all device info", __func__); + return devmgrSvc->ListAllHost(devmgrSvc, reply); +} + int32_t DevmgrServiceStubDispatch(struct HdfRemoteService *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t ret = HDF_FAILURE; @@ -145,6 +155,9 @@ int32_t DevmgrServiceStubDispatch(struct HdfRemoteService *stub, int code, struc case DEVMGR_SERVICE_LIST_ALL_DEVICE: ret = DevmgrServiceStubDispatchListAllDevice(super, reply); break; + case DEVMGR_SERVICE_LIST_ALL_HOST: + ret = DevmgrServiceStubListAllHost(super, data, reply); + break; default: return HdfRemoteServiceDefaultDispatch(serviceStub->remote, code, data, reply); } diff --git a/framework/core/manager/include/devhost_service_clnt.h b/framework/core/manager/include/devhost_service_clnt.h index 8faabae06..6416755e6 100644 --- a/framework/core/manager/include/devhost_service_clnt.h +++ b/framework/core/manager/include/devhost_service_clnt.h @@ -25,6 +25,7 @@ struct DevHostServiceClnt { uint16_t devCount; uint16_t hostId; int hostPid; + int hostProcessId; const char *hostName; bool stopFlag; }; diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index e5d115b48..411563543 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -298,6 +298,8 @@ static int DevmgrServiceAttachDeviceHost( return HDF_FAILURE; } + hostClnt->hostProcessId = HdfRemoteGetCallingPid(); + (void)OsalMutexLock(&hostClnt->hostLock); hostClnt->hostService = hostService; (void)OsalMutexUnlock(&hostClnt->hostLock); @@ -394,6 +396,25 @@ static int32_t DevmgrServiceListAllDevice(struct IDevmgrService *inst, struct Hd return HDF_SUCCESS; } +static int32_t DevmgrServiceListAllHost(struct IDevmgrService *inst, struct HdfSBuf *reply) +{ + struct DevmgrService *devMgrSvc = (struct DevmgrService *)inst; + struct DevHostServiceClnt *hostClnt = NULL; + + if (devMgrSvc == NULL || reply == NULL) { + HDF_LOGE("%{public}s failed, parameter is null", __func__); + return HDF_FAILURE; + } + + HdfSbufWriteUint32(reply, DListGetCount(&devMgrSvc->hosts) + 1); + HdfSbufWriteInt32(reply, getpid()); + DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { + HdfSbufWriteInt32(reply, hostClnt->hostProcessId); + } + + return HDF_SUCCESS; +} + int DevmgrServiceStartService(struct IDevmgrService *inst) { int ret; @@ -469,6 +490,7 @@ bool DevmgrServiceConstruct(struct DevmgrService *inst) devMgrSvcIf->StartService = DevmgrServiceStartService; devMgrSvcIf->PowerStateChange = DevmgrServicePowerStateChange; devMgrSvcIf->ListAllDevice = DevmgrServiceListAllDevice; + devMgrSvcIf->ListAllHost = DevmgrServiceListAllHost; DListHeadInit(&inst->hosts); return true; } else { diff --git a/framework/core/shared/include/devmgr_service_if.h b/framework/core/shared/include/devmgr_service_if.h index 872822883..21dcb4d78 100644 --- a/framework/core/shared/include/devmgr_service_if.h +++ b/framework/core/shared/include/devmgr_service_if.h @@ -28,6 +28,7 @@ struct IDevmgrService { int (*StartService)(struct IDevmgrService *); int (*PowerStateChange)(struct IDevmgrService *, enum HdfPowerState pEvent); int (*ListAllDevice)(struct IDevmgrService *, struct HdfSBuf *); + int (*ListAllHost)(struct IDevmgrService *, struct HdfSBuf *); }; #endif /* DEVMGR_SERVICE_IF_H */ diff --git a/interfaces/inner_api/ipc/hdf_dump_reg.h b/interfaces/inner_api/ipc/hdf_dump_reg.h index 4bec26130..d59d59293 100644 --- a/interfaces/inner_api/ipc/hdf_dump_reg.h +++ b/interfaces/inner_api/ipc/hdf_dump_reg.h @@ -44,6 +44,8 @@ extern "C" { #endif /* __cplusplus */ +bool HdfDumpIpcStat(int32_t fd, const char *cmd); + /** * @brief Implements IPC dump. * -- Gitee From 92f81416ec45e4b79f438d75b9a70f7494723e77 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Tue, 27 Aug 2024 12:01:09 +0800 Subject: [PATCH 3/9] hdf ipc dump Signed-off-by: xiongchangwu --- adapter/uhdf2/hdi/src/idevmgr_client.cpp | 6 +++--- adapter/uhdf2/manager/include/devmgr_service_stub.h | 1 + adapter/uhdf2/manager/src/devmgr_dump.c | 2 +- adapter/uhdf2/manager/src/devmgr_service_stub.c | 2 +- framework/core/manager/src/devmgr_service.c | 3 +++ 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/adapter/uhdf2/hdi/src/idevmgr_client.cpp b/adapter/uhdf2/hdi/src/idevmgr_client.cpp index ab0c50026..11a5205f1 100644 --- a/adapter/uhdf2/hdi/src/idevmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/idevmgr_client.cpp @@ -188,11 +188,11 @@ int32_t DeviceManagerProxy::ListAllDevice(std::vector &deviceInf static void HdfDevMgrFillPidList(std::vector &pidList, MessageParcel &reply) { uint32_t count = 0; - HdfSbufReadUint32(reply, &count); + reply.ReadUint32(count); int pid = -1; for(uint32_t i = 0; i < count; ++i) { - HdfSbufReadInt32(reply, &pid); + reply.ReadInt32(pid); pidList.push_back(pid); } @@ -214,7 +214,7 @@ int32_t DeviceManagerProxy::ListAllHost(std::vector &pidList) return HDF_ERR_INVALID_PARAM; } int status = Remote()->SendRequest( - static_cast(HdfDeviceManagerInterfaceCode::DEVMGR_SERVICE_LIST_ALL_HOST), data, reply, option); + static_cast(DEVMGR_SERVICE_LIST_ALL_HOST), data, reply, option); lock.unlock(); if (status != HDF_SUCCESS) { HDF_LOGE("list all service info failed, %{public}d", status); diff --git a/adapter/uhdf2/manager/include/devmgr_service_stub.h b/adapter/uhdf2/manager/include/devmgr_service_stub.h index 246aa53a6..e88a345be 100644 --- a/adapter/uhdf2/manager/include/devmgr_service_stub.h +++ b/adapter/uhdf2/manager/include/devmgr_service_stub.h @@ -40,6 +40,7 @@ enum { DEVMGR_SERVICE_UNLOAD_DEVICE, DEVMGR_SERVICE_QUERY_DEVICE, DEVMGR_SERVICE_LIST_ALL_DEVICE, + DEVMGR_SERVICE_LIST_ALL_HOST, }; struct HdfObject *DevmgrServiceStubCreate(void); diff --git a/adapter/uhdf2/manager/src/devmgr_dump.c b/adapter/uhdf2/manager/src/devmgr_dump.c index c93889bd9..774075c3c 100644 --- a/adapter/uhdf2/manager/src/devmgr_dump.c +++ b/adapter/uhdf2/manager/src/devmgr_dump.c @@ -311,7 +311,7 @@ static int32_t DevMgrDumpIpc(int32_t fd, struct HdfSBuf *data, struct HdfSBuf *r HdfDumpIpcStat(fd, dumpCmd); return DevMgrDumpAllHostIpcStat(fd, dumpCmd, reply); } else { - int32_t pid = stoi(value); + int32_t pid = atoi(value); if (pid == getpid()){ HdfDumpIpcStat(fd, dumpCmd); } else { diff --git a/adapter/uhdf2/manager/src/devmgr_service_stub.c b/adapter/uhdf2/manager/src/devmgr_service_stub.c index 61e21d5f6..571e8a917 100644 --- a/adapter/uhdf2/manager/src/devmgr_service_stub.c +++ b/adapter/uhdf2/manager/src/devmgr_service_stub.c @@ -156,7 +156,7 @@ int32_t DevmgrServiceStubDispatch(struct HdfRemoteService *stub, int code, struc ret = DevmgrServiceStubDispatchListAllDevice(super, reply); break; case DEVMGR_SERVICE_LIST_ALL_HOST: - ret = DevmgrServiceStubListAllHost(super, data, reply); + ret = DevmgrServiceStubListAllHost(super, reply); break; default: return HdfRemoteServiceDefaultDispatch(serviceStub->remote, code, data, reply); diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index 411563543..a62e004f7 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -6,6 +6,8 @@ * See the LICENSE file in the root of this repository for complete details. */ +#include + #include "devmgr_service.h" #include "devhost_service_clnt.h" #include "device_token_clnt.h" @@ -17,6 +19,7 @@ #include "hdf_log.h" #include "hdf_object_manager.h" #include "osal_time.h" +#include "hdf_remote_service.h" #define HDF_LOG_TAG devmgr_service #define INVALID_PID (-1) -- Gitee From e17a16d968979ab692fd9e173fe02dcf4b6a00b8 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Tue, 27 Aug 2024 15:55:46 +0800 Subject: [PATCH 4/9] hdf ipc dump Signed-off-by: xiongchangwu --- .../uhdf2/manager/src/devmgr_service_stub.c | 20 +++++++++++++++++++ framework/core/manager/src/devmgr_service.c | 3 --- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/adapter/uhdf2/manager/src/devmgr_service_stub.c b/adapter/uhdf2/manager/src/devmgr_service_stub.c index 571e8a917..b36c85221 100644 --- a/adapter/uhdf2/manager/src/devmgr_service_stub.c +++ b/adapter/uhdf2/manager/src/devmgr_service_stub.c @@ -20,6 +20,7 @@ #include #include "devhost_service_proxy.h" +#include "devhost_service_clnt.h" #include "device_token_proxy.h" #include "devmgr_query_device.h" #include "devsvc_manager.h" @@ -35,6 +36,24 @@ #define HDF_LOG_TAG devmgr_service_stub +static void DevmgrServicehostClntGetPid(struct IDevmgrService *devmgrSvc, uint16_t hostId) +{ + struct DevmgrService *dmService = (struct DevmgrService *)devmgrSvc; + if (dmService == NULL) { + return; + } + + struct DevHostServiceClnt *hostClnt = NULL; + DLIST_FOR_EACH_ENTRY(hostClnt, &dmService->hosts, struct DevHostServiceClnt, node) { + if (hostClnt->hostId == hostId) { + hostClnt->hostProcessId = HdfRemoteGetCallingPid(); + break; + } + } + + return; +} + static int32_t DevmgrServiceStubDispatchAttachDeviceHost(struct IDevmgrService *devmgrSvc, struct HdfSBuf *data) { uint32_t hostId = 0; @@ -44,6 +63,7 @@ static int32_t DevmgrServiceStubDispatchAttachDeviceHost(struct IDevmgrService * } struct HdfRemoteService *service = HdfSbufReadRemoteService(data); struct IDevHostService *hostIf = DevHostServiceProxyObtain(hostId, service); + DevmgrServicehostClntGetPid(devmgrSvc, hostId); return devmgrSvc->AttachDeviceHost(devmgrSvc, hostId, hostIf); } diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index a62e004f7..b54cf2160 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -19,7 +19,6 @@ #include "hdf_log.h" #include "hdf_object_manager.h" #include "osal_time.h" -#include "hdf_remote_service.h" #define HDF_LOG_TAG devmgr_service #define INVALID_PID (-1) @@ -301,8 +300,6 @@ static int DevmgrServiceAttachDeviceHost( return HDF_FAILURE; } - hostClnt->hostProcessId = HdfRemoteGetCallingPid(); - (void)OsalMutexLock(&hostClnt->hostLock); hostClnt->hostService = hostService; (void)OsalMutexUnlock(&hostClnt->hostLock); -- Gitee From 1a986a6590f55c9ba31313ed07979b0d0231e732 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Tue, 27 Aug 2024 16:36:13 +0800 Subject: [PATCH 5/9] hdf ipc dump Signed-off-by: xiongchangwu --- adapter/uhdf2/manager/src/devmgr_service_stub.c | 5 ++++- framework/core/manager/src/devmgr_service.c | 3 --- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/adapter/uhdf2/manager/src/devmgr_service_stub.c b/adapter/uhdf2/manager/src/devmgr_service_stub.c index b36c85221..e4ec2609c 100644 --- a/adapter/uhdf2/manager/src/devmgr_service_stub.c +++ b/adapter/uhdf2/manager/src/devmgr_service_stub.c @@ -136,7 +136,10 @@ static int32_t DevmgrServiceStubListAllHost(struct IDevmgrService *devmgrSvc, st return HDF_ERR_INVALID_PARAM; } HDF_LOGD("%{public}s:get all device info", __func__); - return devmgrSvc->ListAllHost(devmgrSvc, reply); + + int32_t ret = devmgrSvc->ListAllHost(devmgrSvc, reply); + HdfSbufWriteInt32(reply, getpid()); + return ret; } int32_t DevmgrServiceStubDispatch(struct HdfRemoteService *stub, int code, struct HdfSBuf *data, struct HdfSBuf *reply) diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index b54cf2160..5bba91f58 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -6,8 +6,6 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include - #include "devmgr_service.h" #include "devhost_service_clnt.h" #include "device_token_clnt.h" @@ -407,7 +405,6 @@ static int32_t DevmgrServiceListAllHost(struct IDevmgrService *inst, struct HdfS } HdfSbufWriteUint32(reply, DListGetCount(&devMgrSvc->hosts) + 1); - HdfSbufWriteInt32(reply, getpid()); DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { HdfSbufWriteInt32(reply, hostClnt->hostProcessId); } -- Gitee From 6289fdf6c550860e551ba4a1e359cc7f31be7443 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Tue, 27 Aug 2024 19:00:53 +0800 Subject: [PATCH 6/9] hdf ipc dump Signed-off-by: xiongchangwu --- adapter/uhdf2/host/test/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/adapter/uhdf2/host/test/BUILD.gn b/adapter/uhdf2/host/test/BUILD.gn index 279a46b8f..05bf9dbe3 100644 --- a/adapter/uhdf2/host/test/BUILD.gn +++ b/adapter/uhdf2/host/test/BUILD.gn @@ -51,6 +51,7 @@ ohos_unittest("DevMgrTest") { external_deps = [ "c_utils:utils", "hilog:libhilog", + "ipc:ipc_single", ] } else { external_deps = [ "hilog:libhilog" ] -- Gitee From 75eaff4151613ecd9898e71af71f9f3bc49fe06d Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Tue, 27 Aug 2024 22:13:04 +0800 Subject: [PATCH 7/9] hdf ipc dump Signed-off-by: xiongchangwu --- adapter/uhdf2/host/src/devhost_dump.c | 4 +--- adapter/uhdf2/ipc/src/hdf_dump.cpp | 6 +++--- adapter/uhdf2/manager/src/devmgr_dump.c | 11 +++++------ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/adapter/uhdf2/host/src/devhost_dump.c b/adapter/uhdf2/host/src/devhost_dump.c index 4ec75d917..b9ef1d73c 100644 --- a/adapter/uhdf2/host/src/devhost_dump.c +++ b/adapter/uhdf2/host/src/devhost_dump.c @@ -122,7 +122,6 @@ int32_t DevHostRegisterDumpHost(DevHostDumpFunc dump) void DevHostDump(struct HdfSBuf *data, struct HdfSBuf *reply) { - HDF_LOGI("%{public}s enter", __func__); if (data == NULL || reply == NULL) { return; } @@ -159,8 +158,7 @@ void DevHostDump(struct HdfSBuf *data, struct HdfSBuf *reply) (void)HdfSbufWriteString(reply, "The service does not register dump function\n"); } } else if (strcmp(option, "--ipc") == 0) { - int32_t fd = -1; - HdfSbufReadInt32(data, &fd); + int32_t fd = HdfSbufReadFileDescriptor(data); HDF_LOGI("%{public}s %{public}d", option, fd); const char *dumpCmd = HdfSbufReadString(data); if (dumpCmd == NULL) { diff --git a/adapter/uhdf2/ipc/src/hdf_dump.cpp b/adapter/uhdf2/ipc/src/hdf_dump.cpp index c981c2ed0..18b4af660 100644 --- a/adapter/uhdf2/ipc/src/hdf_dump.cpp +++ b/adapter/uhdf2/ipc/src/hdf_dump.cpp @@ -41,7 +41,7 @@ static constexpr int32_t MAX_PARA_NUM = 22; static bool HdfDumpIpcStatStart(std::string& result) { - result = std::string("HdfDumperIpcStatStart pid:") + std::to_string(getpid()); + result = std::string("HdfDumpIpcStatStart pid:") + std::to_string(getpid()); bool ret = IPCPayloadStatistics::StartStatistics(); result += ret ? HDF_DUMP_SUCCESS_STR : HDF_DUMP_FAIL_STR; return ret; @@ -49,7 +49,7 @@ static bool HdfDumpIpcStatStart(std::string& result) static int32_t HdfDumpIpcStatStop(std::string& result) { - result = std::string("HdfDumperIpcStatStop pid:") + std::to_string(getpid()); + result = std::string("HdfDumpIpcStatStop pid:") + std::to_string(getpid()); bool ret = IPCPayloadStatistics::StopStatistics(); result += ret ? HDF_DUMP_SUCCESS_STR : HDF_DUMP_FAIL_STR; return ret; @@ -166,7 +166,7 @@ int32_t HdfDump(int32_t fd, const std::vector &args) goto FINISHED; } - if (!HdfSbufWriteInt32(data, fd)) { + if (!HdfSbufWriteFileDescriptor(data, fd)) { goto FINISHED; } diff --git a/adapter/uhdf2/manager/src/devmgr_dump.c b/adapter/uhdf2/manager/src/devmgr_dump.c index 774075c3c..eb5ba8b16 100644 --- a/adapter/uhdf2/manager/src/devmgr_dump.c +++ b/adapter/uhdf2/manager/src/devmgr_dump.c @@ -225,7 +225,7 @@ static int32_t DevMgrDumpAllHostIpcStat(int32_t fd, const char *cmd, struct HdfS return HDF_FAILURE; } - if (!HdfSbufWriteInt32(ipcData, fd)) { + if (!HdfSbufWriteFileDescriptor(ipcData, fd)) { HdfSbufRecycle(ipcData); return HDF_FAILURE; } @@ -250,13 +250,13 @@ static int32_t DevMgrDumpSingleHostIpcStats(int32_t pid, struct HdfSBuf *data, s struct DevHostServiceClnt *hostClnt = NULL; int32_t ret = HDF_FAILURE; DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { - HDF_LOGI("%{public}s hostName:%{public}s %{public}d %{public}d", __func__, - hostClnt->hostName, hostClnt->hostProcessId, pid); if (hostClnt->hostService == NULL || hostClnt->hostService->Dump == NULL) { HDF_LOGI("The host does not start\n"); continue; } if (hostClnt->hostProcessId == pid) { + HDF_LOGI("%{public}s hostName:%{public}s %{public}d %{public}d", __func__, + hostClnt->hostName, hostClnt->hostProcessId, pid); ret = hostClnt->hostService->Dump(hostClnt->hostService, data, reply); break; } @@ -277,7 +277,7 @@ static int32_t DevMgrDumpSingleHostIpcStat(int32_t pid, int32_t fd, const char * return HDF_FAILURE; } - if (!HdfSbufWriteInt32(ipcData, fd)) { + if (!HdfSbufWriteFileDescriptor(ipcData, fd)) { HdfSbufRecycle(ipcData); return HDF_FAILURE; } @@ -600,8 +600,7 @@ static int32_t DevMgrDump(struct HdfSBuf *data, struct HdfSBuf *reply) return HDF_FAILURE; } - int32_t fd = -1; - HdfSbufReadInt32(data, &fd); + int32_t fd = HdfSbufReadFileDescriptor(data); uint32_t argv = 0; HdfSbufReadUint32(data, &argv); -- Gitee From 922d94fa473ce4538c2700fbcc8cf0a65d4a2ba0 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Wed, 28 Aug 2024 00:36:21 +0800 Subject: [PATCH 8/9] hdf ipc dump Signed-off-by: xiongchangwu --- adapter/uhdf2/hdi/src/idevmgr_client.cpp | 4 ++-- adapter/uhdf2/ipc/src/hdf_dump.cpp | 9 +++++++-- adapter/uhdf2/manager/src/devmgr_dump.c | 2 +- framework/core/manager/src/devmgr_service.c | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/adapter/uhdf2/hdi/src/idevmgr_client.cpp b/adapter/uhdf2/hdi/src/idevmgr_client.cpp index 11a5205f1..467fb0e1c 100644 --- a/adapter/uhdf2/hdi/src/idevmgr_client.cpp +++ b/adapter/uhdf2/hdi/src/idevmgr_client.cpp @@ -191,9 +191,9 @@ static void HdfDevMgrFillPidList(std::vector &pidList, MessageParcel &reply reply.ReadUint32(count); int pid = -1; - for(uint32_t i = 0; i < count; ++i) { + for (uint32_t i = 0; i < count; ++i) { reply.ReadInt32(pid); - pidList.push_back(pid); + pidList.push_back(pid); } return; diff --git a/adapter/uhdf2/ipc/src/hdf_dump.cpp b/adapter/uhdf2/ipc/src/hdf_dump.cpp index 18b4af660..79f0d03fa 100644 --- a/adapter/uhdf2/ipc/src/hdf_dump.cpp +++ b/adapter/uhdf2/ipc/src/hdf_dump.cpp @@ -107,14 +107,14 @@ static int32_t HdfDumpIpcStatGet(std::string& result) bool HdfDumpIpcStat(int32_t fd, const char *cmd) { - if (cmd == NULL) { + if (cmd == nullptr) { HDF_LOGE("%{public}s cmd is null", __func__); return HDF_FAILURE; } bool ret = false; std::string result; - HDF_LOGI("%{public}s %{public}d", cmd, fd); + HDF_LOGI("%{public}s %{public}d", cmd, fd); if (strcmp(cmd, "--start-stat") == 0) { ret = HdfDumpIpcStatStart(result); } else if (strcmp(cmd, "--stop-stat") == 0) { @@ -139,6 +139,11 @@ void HdfRegisterDumpFunc(DevHostDumpFunc dump) int32_t HdfDump(int32_t fd, const std::vector &args) { + if (fd < 0) { + HDF_LOGE("fd is %{public}d", fd); + return HDF_FAILURE; + } + if (g_dump == nullptr) { HDF_LOGE("%{public}s g_dump is null", __func__); return HDF_FAILURE; diff --git a/adapter/uhdf2/manager/src/devmgr_dump.c b/adapter/uhdf2/manager/src/devmgr_dump.c index eb5ba8b16..e2eccf70c 100644 --- a/adapter/uhdf2/manager/src/devmgr_dump.c +++ b/adapter/uhdf2/manager/src/devmgr_dump.c @@ -312,7 +312,7 @@ static int32_t DevMgrDumpIpc(int32_t fd, struct HdfSBuf *data, struct HdfSBuf *r return DevMgrDumpAllHostIpcStat(fd, dumpCmd, reply); } else { int32_t pid = atoi(value); - if (pid == getpid()){ + if (pid == getpid()) { HdfDumpIpcStat(fd, dumpCmd); } else { DevMgrDumpSingleHostIpcStat(pid, fd, dumpCmd, reply); diff --git a/framework/core/manager/src/devmgr_service.c b/framework/core/manager/src/devmgr_service.c index 5bba91f58..0ca8e609a 100644 --- a/framework/core/manager/src/devmgr_service.c +++ b/framework/core/manager/src/devmgr_service.c @@ -406,7 +406,7 @@ static int32_t DevmgrServiceListAllHost(struct IDevmgrService *inst, struct HdfS HdfSbufWriteUint32(reply, DListGetCount(&devMgrSvc->hosts) + 1); DLIST_FOR_EACH_ENTRY(hostClnt, &devMgrSvc->hosts, struct DevHostServiceClnt, node) { - HdfSbufWriteInt32(reply, hostClnt->hostProcessId); + HdfSbufWriteInt32(reply, hostClnt->hostProcessId); } return HDF_SUCCESS; -- Gitee From 1542c126dbf8955eba8d5621b8e913d431d94853 Mon Sep 17 00:00:00 2001 From: xiongchangwu Date: Wed, 28 Aug 2024 09:08:07 +0800 Subject: [PATCH 9/9] hdf ipc dump Signed-off-by: xiongchangwu --- adapter/uhdf2/ipc/src/hdf_dump.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/adapter/uhdf2/ipc/src/hdf_dump.cpp b/adapter/uhdf2/ipc/src/hdf_dump.cpp index 79f0d03fa..3cea81892 100644 --- a/adapter/uhdf2/ipc/src/hdf_dump.cpp +++ b/adapter/uhdf2/ipc/src/hdf_dump.cpp @@ -139,13 +139,8 @@ void HdfRegisterDumpFunc(DevHostDumpFunc dump) int32_t HdfDump(int32_t fd, const std::vector &args) { - if (fd < 0) { - HDF_LOGE("fd is %{public}d", fd); - return HDF_FAILURE; - } - - if (g_dump == nullptr) { - HDF_LOGE("%{public}s g_dump is null", __func__); + if (g_dump == nullptr || fd < 0) { + HDF_LOGE("%{public}s g_dump fd:%{public}d", __func__, fd); return HDF_FAILURE; } -- Gitee