From 22a7a7efa192f02d52010a6837d6860c9a26b652 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Thu, 16 Jun 2022 22:12:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?dm=E6=B7=BB=E5=8A=A0hitrace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- interfaces/inner_kits/native_cpp/BUILD.gn | 1 + .../native_cpp/src/device_manager_impl.cpp | 27 ++++++++++++ services/devicemanagerservice/BUILD.gn | 1 + .../dependency/softbus/softbus_session.cpp | 9 ++++ test/unittest/BUILD.gn | 3 ++ utils/BUILD.gn | 2 + utils/include/dm_hitrace.h | 43 +++++++++++++++++++ utils/src/dm_hitrace.cpp | 30 +++++++++++++ 8 files changed, 116 insertions(+) create mode 100644 utils/include/dm_hitrace.h create mode 100644 utils/src/dm_hitrace.cpp diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 64eca50a2..670719879 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -144,6 +144,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 19b2bdc80..81630c1da 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 2be7fed6b..289dabf73 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 99605d7df..44063b716 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 8fd97f001..206782a7b 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/utils/BUILD.gn b/utils/BUILD.gn index 760eb0b69..6945118f9 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -135,6 +135,7 @@ if (defined(ohos_lite)) { "src/dm_anonymous.cpp", "src/dm_error_message.cpp", "src/dm_hash.cpp", + "src/dm_hitrace.cpp", "src/dm_log.cpp", "src/dm_random.cpp", "src/ipc/standard/ipc_cmd_register.cpp", @@ -159,6 +160,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/dm_hitrace.h b/utils/include/dm_hitrace.h new file mode 100644 index 000000000..ef43a855f --- /dev/null +++ b/utils/include/dm_hitrace.h @@ -0,0 +1,43 @@ +/* + * 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 + +#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) +#include "hitrace_meter.h" +#endif + +#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/dm_hitrace.cpp b/utils/src/dm_hitrace.cpp new file mode 100644 index 000000000..6cea7e83f --- /dev/null +++ b/utils/src/dm_hitrace.cpp @@ -0,0 +1,30 @@ +/* + * 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 -- Gitee From 25292feafac753915a2aba3ffae4c4b84b5e2d86 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Tue, 21 Jun 2022 10:51:37 +0800 Subject: [PATCH 2/2] 11 Signed-off-by: wangyb0625 --- interfaces/inner_kits/native_cpp/BUILD.gn | 6 ++++ test/unittest/UTTest_dm_discovery_manager.cpp | 1 + utils/BUILD.gn | 11 +++++-- utils/include/hitrace/lite/dm_hitrace.h | 29 +++++++++++++++++++ .../{ => hitrace/standard}/dm_hitrace.h | 3 -- utils/src/hitrace/lite/dm_hitrace.cpp | 29 +++++++++++++++++++ .../src/{ => hitrace/standard}/dm_hitrace.cpp | 1 - 7 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 utils/include/hitrace/lite/dm_hitrace.h rename utils/include/{ => hitrace/standard}/dm_hitrace.h (95%) create mode 100644 utils/src/hitrace/lite/dm_hitrace.cpp rename utils/src/{ => hitrace/standard}/dm_hitrace.cpp (99%) diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 670719879..6985c8347 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" ] diff --git a/test/unittest/UTTest_dm_discovery_manager.cpp b/test/unittest/UTTest_dm_discovery_manager.cpp index c168d0295..4abfc5f37 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 6945118f9..38e393310 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", @@ -135,10 +142,10 @@ if (defined(ohos_lite)) { "src/dm_anonymous.cpp", "src/dm_error_message.cpp", "src/dm_hash.cpp", - "src/dm_hitrace.cpp", "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 += [ diff --git a/utils/include/hitrace/lite/dm_hitrace.h b/utils/include/hitrace/lite/dm_hitrace.h new file mode 100644 index 000000000..761ce3d3a --- /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/dm_hitrace.h b/utils/include/hitrace/standard/dm_hitrace.h similarity index 95% rename from utils/include/dm_hitrace.h rename to utils/include/hitrace/standard/dm_hitrace.h index ef43a855f..ce3e2a819 100644 --- a/utils/include/dm_hitrace.h +++ b/utils/include/hitrace/standard/dm_hitrace.h @@ -18,9 +18,7 @@ #include -#if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) #include "hitrace_meter.h" -#endif #include "dm_constants.h" @@ -35,7 +33,6 @@ const std::string DM_HITRACE_AUTH_TO_OPPEN_SESSION = "DM_HITRACE_AUTH_TO_OPPEN_S 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 diff --git a/utils/src/hitrace/lite/dm_hitrace.cpp b/utils/src/hitrace/lite/dm_hitrace.cpp new file mode 100644 index 000000000..7406d71f4 --- /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/dm_hitrace.cpp b/utils/src/hitrace/standard/dm_hitrace.cpp similarity index 99% rename from utils/src/dm_hitrace.cpp rename to utils/src/hitrace/standard/dm_hitrace.cpp index 6cea7e83f..7b22ade69 100644 --- a/utils/src/dm_hitrace.cpp +++ b/utils/src/hitrace/standard/dm_hitrace.cpp @@ -16,7 +16,6 @@ namespace OHOS { namespace DistributedHardware { - void DMTraceStart(const std::string &msg) { StartTrace(DM_HITRACE_LABEL, msg); -- Gitee