diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 64eca50a294fac5094d5289a2f1a2e4302c62340..6985c8347cf057a4a096d8099b6667669b6f0a94 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -25,6 +25,7 @@ if (defined(ohos_lite)) { "${innerkits_path}/native_cpp/include", "${innerkits_path}/native_cpp/include/notify", "${utils_path}/include", + "${utils_path}/include/hitrace/lite", "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", @@ -42,6 +43,7 @@ if (defined(ohos_lite)) { "${innerkits_path}/native_cpp/src/mini/device_manager.cpp", "${innerkits_path}/native_cpp/src/mini/device_manager_impl.cpp", "${innerkits_path}/native_cpp/src/mini/device_manager_notify.cpp", + "${utils_path}/src/hitrace/lite/dm_hitrace.cpp", ] defines = [ @@ -70,6 +72,7 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "${utils_path}/include", + "${utils_path}/include/hitrace/lite", "${utils_path}/include/ipc/lite", ] include_dirs += [ @@ -90,6 +93,7 @@ if (defined(ohos_lite)) { "src/ipc/lite/ipc_client_stub.cpp", "src/ipc/lite/ipc_cmd_parser.cpp", "src/notify/device_manager_notify.cpp", + "${utils_path}/src/hitrace/lite/dm_hitrace.cpp", ] deps = [ "${utils_path}:devicemanagerutils", @@ -116,6 +120,7 @@ if (defined(ohos_lite)) { "include/notify", "${common_path}/include", "${common_path}/include/ipc", + "${utils_path}/include/hitrace/standard", "${common_path}/include/ipc/model", ] } @@ -130,6 +135,7 @@ if (defined(ohos_lite)) { "src/ipc/standard/ipc_client_stub.cpp", "src/ipc/standard/ipc_cmd_parser.cpp", "src/notify/device_manager_notify.cpp", + "${utils_path}/src/hitrace/standard/dm_hitrace.cpp", ] public_configs = [ ":devicemanagersdk_config" ] @@ -144,6 +150,7 @@ if (defined(ohos_lite)) { external_deps = [ "hiviewdfx_hilog_native:libhilog", + "hitrace_native:hitrace_meter", "ipc:ipc_core", "samgr_standard:samgr_proxy", "utils_base:utils", diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 19b2bdc80de2dd3c3e111d6d70c6e3f1caad4647..81630c1dac29ea4815ab73291227b82e6007acd2 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -18,6 +18,9 @@ #include "device_manager_notify.h" #include "dm_anonymous.h" #include "dm_constants.h" +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#include "dm_hitrace.h" +#endif #include "dm_log.h" #include "ipc_authenticate_device_req.h" #include "ipc_get_dmfaparam_rsp.h" @@ -47,6 +50,9 @@ DeviceManagerImpl &DeviceManagerImpl::GetInstance() int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::shared_ptr dmInitCallback) { LOGI("DeviceManager::InitDeviceManager start, pkgName: %s", pkgName.c_str()); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceStart(DM_HITRACE_INIT); +#endif if (pkgName.empty() || dmInitCallback == nullptr) { LOGE("InitDeviceManager error: Invalid parameter"); return ERR_DM_INPUT_PARAMETER_EMPTY; @@ -72,6 +78,9 @@ int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::sh } DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceEnd(); +#endif LOGI("InitDeviceManager success"); return DM_OK; } @@ -128,6 +137,9 @@ int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, cons int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info) { LOGI("DeviceManager::GetLocalDeviceInfo start, pkgName: %s", pkgName.c_str()); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceStart(DM_HITRACE_GET_LOCAL_DEVICE_INFO); +#endif std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); @@ -144,6 +156,9 @@ int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDevi } info = rsp->GetLocalDeviceInfo(); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceEnd(); +#endif LOGI("GetLocalDeviceInfo completed,pkgname%s", req->GetPkgName().c_str()); return DM_OK; } @@ -184,6 +199,9 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons const std::string &extra, std::shared_ptr callback) { LOGI("DeviceManager::StartDeviceDiscovery start, pkgName: %s", pkgName.c_str()); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceStart(DM_HITRACE_START_DEVICE); +#endif if (pkgName.empty() || callback == nullptr) { LOGE("StartDeviceDiscovery error: Invalid para"); return ERR_DM_INPUT_PARAMETER_EMPTY; @@ -209,6 +227,9 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons return ret; } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceEnd(); +#endif LOGI("StartDeviceDiscovery completed, pkgName: %s", pkgName.c_str()); return DM_OK; } @@ -248,6 +269,9 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ std::shared_ptr callback) { LOGI("DeviceManager::AuthenticateDevice start , pkgName: %s", pkgName.c_str()); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceStart(DM_HITRACE_AUTH_TO_CONSULT); +#endif if (pkgName.empty()) { LOGE("AuthenticateDevice error: Invalid para"); return ERR_DM_INPUT_PARAMETER_EMPTY; @@ -272,6 +296,9 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ LOGE("AuthenticateDevice error: Failed with ret %d", ret); return ERR_DM_IPC_RESPOND_FAILED; } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceEnd(); +#endif LOGI("DeviceManager::AuthenticateDevice completed, pkgName: %s", pkgName.c_str()); return DM_OK; } diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index 2be7fed6bcbd75be8f5dad93a97ae39d06d06b53..289dabf73adee1b0c3c295129a471b09ff8d59a5 100755 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -334,6 +334,7 @@ if (defined(ohos_lite)) { "startup_l2:syspara", "startup_l2:syspara_watchagent", "utils_base:utils", + "hitrace_native:hitrace_meter", ] subsystem_name = "distributedhardware" diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp index 99605d7df6a9c93ecaca428d0e620c0883f9ed72..44063b716688dbf964a50dd0cc99bb6ccc267396 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp @@ -18,6 +18,9 @@ #include "dm_anonymous.h" #include "dm_constants.h" #include "dm_log.h" +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#include "dm_hitrace.h" +#endif #include "nlohmann/json.hpp" #include "softbus_connector.h" @@ -60,6 +63,9 @@ int32_t SoftbusSession::UnRegisterSessionCallback() int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) { LOGI("SoftbusSession::OpenAuthSession"); +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceStart(DM_HITRACE_AUTH_TO_OPPEN_SESSION); +#endif int32_t sessionId = -1; std::string connectAddr; ConnectionAddr *addrInfo = SoftbusConnector::GetConnectAddr(deviceId, connectAddr); @@ -72,6 +78,9 @@ int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) LOGE("open session error, ret:%d", sessionId); return sessionId; } +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) + DMTraceEnd(); +#endif LOGI("SoftbusSession::OpenAuthSession success. sessionId is:%d", sessionId); return sessionId; } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 8fd97f001b505d72a6a5805f080ef907b6a27434..206782a7bece892daa7d04b3556c1ee67bbf7fac 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -283,6 +283,7 @@ ohos_unittest("UTTest_profile_connector") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", ] } @@ -300,6 +301,7 @@ ohos_unittest("UTTest_device_profile_adapter") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", ] } @@ -641,6 +643,7 @@ ohos_static_library("device_manager_test") { "dsoftbus_standard:softbus_client", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", + "hitrace_native:hitrace_meter", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", diff --git a/test/unittest/UTTest_dm_discovery_manager.cpp b/test/unittest/UTTest_dm_discovery_manager.cpp index c168d029586a20a791342dcecfef1e0e12ef2abf..4abfc5f374fd33b6d5089be6ef498050a94de797 100644 --- a/test/unittest/UTTest_dm_discovery_manager.cpp +++ b/test/unittest/UTTest_dm_discovery_manager.cpp @@ -20,6 +20,7 @@ #include "dm_log.h" #include "dm_constants.h" #include "dm_anonymous.h" +#include "dm_hitrace.h" #include "ipc_server_listener.h" #include "device_manager_service_listener.h" #include "discovery_service.h" diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 760eb0b69d0ece3274bcfdcfdd5c4e58268402dc..38e39331092733d8f8ec538816a14bbc0d0425cb 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -25,6 +25,7 @@ if (defined(ohos_lite)) { include_dirs = [ "${utils_path}/include", "${utils_path}/include/permission/lite", + "${utils_path}/include/hitrace/lite", "${common_path}/include", ] @@ -44,10 +45,12 @@ if (defined(ohos_lite)) { "${utils_path}/src/dm_error_message.cpp", "${utils_path}/src/dm_log.cpp", "${utils_path}/src/dm_random.cpp", + "${utils_path}/src/hitrace/lite/dm_hitrace.cpp", "${utils_path}/src/permission/lite/permission_manager.cpp", ] defines = [ + "__LITEOS_M__", "HI_LOG_ENABLE", "DH_LOG_TAG=\"devicemanagerutils\"", "LOG_DOMAIN=0xD004100", @@ -66,6 +69,7 @@ if (defined(ohos_lite)) { } else { shared_library("devicemanagerutils") { include_dirs = [ + "${utils_path}/include/hitrace/lite", "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", @@ -97,9 +101,11 @@ if (defined(ohos_lite)) { "src/dm_random.cpp", "src/fwkload/lite/dm_distributed_hardware_load.cpp", "src/ipc/lite/ipc_cmd_register.cpp", + "${utils_path}/src/hitrace/lite/dm_hitrace.cpp", "src/permission/lite/permission_manager.cpp", ] defines = [ + "LITE_DEVICE", "hI_LOG_ENABLE", "DH_LOG_TAG=\"devicemanagerutils\"", "lOG_DOMAIN=0xD004100", @@ -113,7 +119,7 @@ if (defined(ohos_lite)) { "//third_party/bounds_checking_function:libsec_shared", "//third_party/mbedtls:mbedtls_shared", "//utils/native/lite:utils", - ] + ]dm_hitrace } } } else { @@ -121,6 +127,7 @@ if (defined(ohos_lite)) { include_dirs = [ "include", "include/fwkload/standard", + "${utils_path}/include/hitrace/standard", "include/ipc/standard", "${common_path}/include", "${common_path}/include/ipc", @@ -138,6 +145,7 @@ if (defined(ohos_lite)) { "src/dm_log.cpp", "src/dm_random.cpp", "src/ipc/standard/ipc_cmd_register.cpp", + "${utils_path}/src/hitrace/standard/dm_hitrace.cpp", ] if (support_jsapi) { sources += [ @@ -159,6 +167,7 @@ if (defined(ohos_lite)) { external_deps = [ "access_token:libaccesstoken_sdk", "hiviewdfx_hilog_native:libhilog", + "hitrace_native:hitrace_meter", "ipc:ipc_core", "safwk:system_ability_fwk", "samgr_standard:samgr_proxy", diff --git a/utils/include/hitrace/lite/dm_hitrace.h b/utils/include/hitrace/lite/dm_hitrace.h new file mode 100644 index 0000000000000000000000000000000000000000..761ce3d3ae4fbaf07564c1ad8cc06c37f39a54fe --- /dev/null +++ b/utils/include/hitrace/lite/dm_hitrace.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_HITRACE_H +#define OHOS_DM_HITRACE_H + +#include + +#include "dm_constants.h" + +namespace OHOS { +namespace DistributedHardware { +void DMTraceStart(void); +void DMTraceEnd(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/utils/include/hitrace/standard/dm_hitrace.h b/utils/include/hitrace/standard/dm_hitrace.h new file mode 100644 index 0000000000000000000000000000000000000000..ce3e2a819f02f4d6cfdf9329b8f02e178d469a4f --- /dev/null +++ b/utils/include/hitrace/standard/dm_hitrace.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_DM_HITRACE_H +#define OHOS_DM_HITRACE_H + +#include + +#include "hitrace_meter.h" + +#include "dm_constants.h" + +namespace OHOS { +namespace DistributedHardware { +constexpr uint64_t DM_HITRACE_LABEL = HITRACE_TAG_DEVICE_MANAGER; + +const std::string DM_HITRACE_START_DEVICE = "DM_HITRACE_START_DEVICE"; +const std::string DM_HITRACE_GET_LOCAL_DEVICE_INFO = "DM_HITRACE_GET_LOCAL_DEVICE_INFO"; +const std::string DM_HITRACE_AUTH_TO_CONSULT = "DM_HITRACE_AUTH_TO_CONSULT"; +const std::string DM_HITRACE_AUTH_TO_OPPEN_SESSION = "DM_HITRACE_AUTH_TO_OPPEN_SESSION"; +const std::string DM_HITRACE_DEVICE_ONLINE = "DM_HITRACE_DEVICE_ONLINE"; +const std::string DM_HITRACE_INIT = "DM_HITRACE_INIT"; + +void DMTraceStart(const std::string &msg); +void DMTraceEnd(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/utils/src/hitrace/lite/dm_hitrace.cpp b/utils/src/hitrace/lite/dm_hitrace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7406d71f4c4746e097df80e155854a3d6e7df1cd --- /dev/null +++ b/utils/src/hitrace/lite/dm_hitrace.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "dm_hitrace.h" + +namespace OHOS { +namespace DistributedHardware { +void DMTraceStart(void) +{ + return; +} + +void DMTraceEnd() +{ + return; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/src/hitrace/standard/dm_hitrace.cpp b/utils/src/hitrace/standard/dm_hitrace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b22ade6937a438c6bbe0778bed262472ddd4ea8 --- /dev/null +++ b/utils/src/hitrace/standard/dm_hitrace.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "dm_hitrace.h" + +namespace OHOS { +namespace DistributedHardware { +void DMTraceStart(const std::string &msg) +{ + StartTrace(DM_HITRACE_LABEL, msg); +} + +void DMTraceEnd() +{ + FinishTrace(DM_HITRACE_LABEL); +} +} // namespace DistributedHardware +} // namespace OHOS