diff --git a/bundle.json b/bundle.json index 9c7eb7bc..a7456984 100644 --- a/bundle.json +++ b/bundle.json @@ -18,6 +18,9 @@ "adapted_system_type": [ "standard", "small" ], "rom": "2M", "ram": "16M", + "hisysevent_config": [ + "//foundation/distributedhardware/device_manager/hisysevent.yaml" + ], "deps": { "components": [ "appexecfwk_standard", diff --git a/hisysevent.yaml b/hisysevent.yaml new file mode 100644 index 00000000..a846a26b --- /dev/null +++ b/hisysevent.yaml @@ -0,0 +1,124 @@ +# 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. + +##################################################### +# below is the format of defining event # +##################################################### +#domain: domain name. [Only one domain name can be defined at the top] +# +#author: the author name who defined this event. +#date: the date when this event was defined, format is YYYY-MM-DD. +#logged: source file which refer to this event. +#usage: the usage of this event. +#//Define event name and event properties. +#@EVENT_NAME: the event definition part begin. +# // __BASE is used for defining the basic info of the event. +# // "type" optional values are: FAULT, STATISTICS, SECURITY, BEHAVIOR. +# // "level" optional values are: CRITICAL, MINOR. +# // "tag" set tags with may used by subscriber of this event, multiple tags devided by space. +# // "desc" full description of this event. +# @PARAMETER: {type: parameter type, arrsize: array length(optional), desc: parameter description}. +# // follow the __BASE block, each line defines a parameter of this event. +# // "type" optional values are: INT8, UINT8, INT16, UINT16, INT32, UINT32, INT64, UINT64, FLOAT, DOUBLE, STRING. +# // "arrsize" of the parameter is an array, set a non-zero value. +# // "desc" full description of this parameter. + +##################################################### +# Example of some hiviewdfx events definition # +##################################################### + +domain: DISTDM + +DM_INIT_DEVICE_MANAGER_SUCCESS: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm init devicemanager success} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm init devicemanager success} + +DM_INIT_DEVICE_MANAGER_FAILED: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm init devicemanager failed} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm init devicemanager failed} + +START_DEVICE_DISCOVERY_SUCCESS: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: device manager discovery success} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: device manager discovery success} + +START_DEVICE_DISCOVERY_FAILED: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: device manager discovery failed} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: device manager discovery failed} + +GET_LOCAL_DEVICE_INFO_SUCCESS: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm get local device info success} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm get local device info success} + +GET_LOCAL_DEVICE_INFO_FAILED: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm get local device info failed} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm get local device info failed} + +DM_SEND_REQUEST_SUCCESS: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm send request success} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm send request success} + +DM_SEND_REQUEST_FAILED: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm send request failed} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm send request failed} + +ADD_HICHAIN_GROUP_SUCCESS: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm add member to group success} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm add member to group success} + +ADD_HICHAIN_GROUP_FAILED: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm add member to group failed} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm add member to group failed} + +DM_CREATE_GROUP_SUCCESS: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm create group success} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm create group success} + +DM_CREATE_GROUP_FAILED: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: dm create group failed} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: dm create group failed} + +UNAUTHENTICATE_DEVICE_SUCCESS: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: unauthenticate device success} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: unauthenticate device success} + +UNAUTHENTICATE_DEVICE_FAILED: + __BASE: {type: BEHAVIOR, level: CRITICAL, desc: unauthenticate device failed} + PID: {type: INT32, desc: devevicemanager pid} + UID: {type: INT32, desc: devevicemanager uid} + MSG: {type: STRING, desc: unauthenticate device failed} diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 64eca50a..b9b12866 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -25,6 +25,8 @@ if (defined(ohos_lite)) { "${innerkits_path}/native_cpp/include", "${innerkits_path}/native_cpp/include/notify", "${utils_path}/include", + "${utils_path}/include/dfx", + "${utils_path}/include/dfx/lite", "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", @@ -45,7 +47,7 @@ if (defined(ohos_lite)) { ] defines = [ - "LITE_DEVICE", + "__LITEOS_M__", "HI_LOG_ENABLE", "DH_LOG_TAG=\"devicemanagerkit\"", "LOG_DOMAIN=0xD004100", @@ -70,6 +72,8 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "${utils_path}/include", + "${utils_path}/include/dfx", + "${utils_path}/include/dfx/lite", "${utils_path}/include/ipc/lite", ] include_dirs += [ @@ -117,6 +121,8 @@ if (defined(ohos_lite)) { "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", + "${utils_path}/include/dfx", + "${utils_path}/include/dfx/standard", ] } @@ -143,6 +149,8 @@ if (defined(ohos_lite)) { deps = [ "${utils_path}:devicemanagerutils" ] external_deps = [ + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "samgr_standard:samgr_proxy", 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 19b2bdc8..f2eb0278 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" +#include "dm_dfx_constants.h" +#include "dm_hisysevent.h" +#include "dm_hitrace.h" #include "dm_log.h" #include "ipc_authenticate_device_req.h" #include "ipc_get_dmfaparam_rsp.h" @@ -47,6 +50,7 @@ DeviceManagerImpl &DeviceManagerImpl::GetInstance() int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::shared_ptr dmInitCallback) { LOGI("DeviceManager::InitDeviceManager start, pkgName: %s", pkgName.c_str()); + DmTraceStart(DM_HITRACE_INIT); if (pkgName.empty() || dmInitCallback == nullptr) { LOGE("InitDeviceManager error: Invalid parameter"); return ERR_DM_INPUT_PARAMETER_EMPTY; @@ -68,11 +72,14 @@ int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::sh } if (ret != DM_OK) { LOGE("InitDeviceManager error: proxy init failed ret: %d", ret); + SysEventWrite(DM_INIT_DEVICE_MANAGER_FAILED, DM_HISYEVENT_FAULT, DM_INIT_DEVICE_MANAGER_FAILED_MSG); return ERR_DM_INIT_FAILED; } DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); + DmTraceEnd(); LOGI("InitDeviceManager success"); + SysEventWrite(DM_INIT_DEVICE_MANAGER_SUCCESS, DM_HISYEVENT_BEHAVIOR, DM_INIT_DEVICE_MANAGER_SUCCESS_MSG); return DM_OK; } @@ -128,6 +135,7 @@ 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()); + DmTraceStart(DM_HITRACE_GET_LOCAL_DEVICE_INFO); std::shared_ptr req = std::make_shared(); std::shared_ptr rsp = std::make_shared(); req->SetPkgName(pkgName); @@ -140,11 +148,14 @@ int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDevi ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGI("GetLocalDeviceInfo error: failed ret: %d", ret); + SysEventWrite(GET_LOCAL_DEVICE_INFO_FAILED, DM_HISYEVENT_BEHAVIOR, GET_LOCAL_DEVICE_INFO_FAILED_MSG); return ERR_DM_IPC_RESPOND_FAILED; } info = rsp->GetLocalDeviceInfo(); + DmTraceEnd(); LOGI("GetLocalDeviceInfo completed,pkgname%s", req->GetPkgName().c_str()); + SysEventWrite(GET_LOCAL_DEVICE_INFO_SUCCESS, DM_HISYEVENT_BEHAVIOR, GET_LOCAL_DEVICE_INFO_SUCCESS_MSG); return DM_OK; } @@ -184,6 +195,7 @@ 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()); + DmTraceStart(DM_HITRACE_START_DEVICE); if (pkgName.empty() || callback == nullptr) { LOGE("StartDeviceDiscovery error: Invalid para"); return ERR_DM_INPUT_PARAMETER_EMPTY; @@ -206,10 +218,13 @@ int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, cons ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("StartDeviceDiscovery error: Failed with ret %d", ret); + SysEventWrite(START_DEVICE_DISCOVERY_FAILED, DM_HISYEVENT_BEHAVIOR, START_DEVICE_DISCOVERY_FAILED_MSG); return ret; } + DmTraceEnd(); LOGI("StartDeviceDiscovery completed, pkgName: %s", pkgName.c_str()); + SysEventWrite(START_DEVICE_DISCOVERY_SUCCESS, DM_HISYEVENT_BEHAVIOR, START_DEVICE_DISCOVERY_SUCCESS_MSG); return DM_OK; } @@ -248,6 +263,7 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ std::shared_ptr callback) { LOGI("DeviceManager::AuthenticateDevice start , pkgName: %s", pkgName.c_str()); + DmTraceStart(DM_HITRACE_AUTH_TO_CONSULT); if (pkgName.empty()) { LOGE("AuthenticateDevice error: Invalid para"); return ERR_DM_INPUT_PARAMETER_EMPTY; @@ -264,14 +280,17 @@ int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_ int32_t ret = ipcClientProxy_->SendRequest(AUTHENTICATE_DEVICE, req, rsp); if (ret != DM_OK) { LOGE("AuthenticateDevice error: Send Request failed ret: %d", ret); + SysEventWrite(DM_SEND_REQUEST_FAILED, DM_HISYEVENT_BEHAVIOR, DM_SEND_REQUEST_FAILED_MSG); return ERR_DM_IPC_SEND_REQUEST_FAILED; } + SysEventWrite(DM_SEND_REQUEST_SUCCESS, DM_HISYEVENT_BEHAVIOR, DM_SEND_REQUEST_SUCCESS_MSG); ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("AuthenticateDevice error: Failed with ret %d", ret); return ERR_DM_IPC_RESPOND_FAILED; } + DmTraceEnd(); LOGI("DeviceManager::AuthenticateDevice completed, pkgName: %s", pkgName.c_str()); return DM_OK; } @@ -297,8 +316,10 @@ int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, cons ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("UnAuthenticateDevice error: Failed with ret %d", ret); + SysEventWrite(UNAUTHENTICATE_DEVICE_FAILED, DM_HISYEVENT_BEHAVIOR, UNAUTHENTICATE_DEVICE_FAILED_MSG); return ERR_DM_IPC_RESPOND_FAILED; } + SysEventWrite(UNAUTHENTICATE_DEVICE_SUCCESS, DM_HISYEVENT_BEHAVIOR, UNAUTHENTICATE_DEVICE_SUCCESS_MSG); LOGI("UnAuthenticateDevice completed, pkgName: %s", pkgName.c_str()); return DM_OK; diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index d8df3a03..87535c8d 100755 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -47,6 +47,8 @@ if (defined(ohos_lite)) { "//base/security/device_auth/interfaces/innerkits", "//third_party/json/include", "${utils_path}/include", + "${utils_path}/include/dfx", + "${utils_path}/include/dfx/lite", "${utils_path}/include/permission/lite", "foundation/multimedia/image_standard/mock/native/include", "${services_path}/include/dispatch", @@ -100,7 +102,7 @@ if (defined(ohos_lite)) { ] defines = [ - "LITE_DEVICE", + "__LITEOS_M__", "HI_LOG_ENABLE", "DH_LOG_TAG=\"devicemanagerservice\"", "LOG_DOMAIN=0xD004100", @@ -125,6 +127,11 @@ if (defined(ohos_lite)) { "//third_party/mbedtls", "//utils/native/lite:utils", ] + + external_deps = [ + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + ] } } else { executable("devicemanagerservice") { @@ -150,6 +157,8 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc/model", "${utils_path}/include", "${utils_path}/include/fwkload/lite", + "${utils_path}/include/dfx", + "${utils_path}/include/dfx/lite", "${utils_path}/include/ipc/lite", "${utils_path}/include/permission/lite", "${innerkits_path}/native_cpp/include", @@ -253,6 +262,8 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc/model", "${utils_path}/include", "${utils_path}/include/fwkload/standard", + "${utils_path}/include/dfx", + "${utils_path}/include/dfx/standard", "${utils_path}/include/permission/standard", "//base/security/device_auth/interfaces/innerkits", "//third_party/json/include", @@ -327,6 +338,8 @@ if (defined(ohos_lite)) { "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp index 2b47c4c9..7e5b908d 100644 --- a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp +++ b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp @@ -23,6 +23,7 @@ #include "dm_anonymous.h" #include "dm_constants.h" +#include "dm_hisysevent.h" #include "dm_log.h" #include "dm_random.h" #include "hichain_connector_callback.h" @@ -261,12 +262,14 @@ void HiChainConnector::onFinish(int64_t requestId, int operationCode, const char LOGI("HiChainConnector::onFinish reqId:%lld, operation:%d", requestId, operationCode); if (operationCode == GroupOperationCode::MEMBER_JOIN) { LOGI("Add Member To Group success"); + SysEventWrite(ADD_HICHAIN_GROUP_SUCCESS, DM_HISYEVENT_BEHAVIOR, ADD_HICHAIN_GROUP_SUCCESS_MSG); if (hiChainConnectorCallback_ != nullptr) { hiChainConnectorCallback_->OnMemberJoin(requestId, DM_OK); } } if (operationCode == GroupOperationCode::GROUP_CREATE) { LOGI("Create group success"); + SysEventWrite(DM_CREATE_GROUP_SUCCESS, DM_HISYEVENT_BEHAVIOR, DM_CREATE_GROUP_SUCCESS_MSG); if (hiChainConnectorCallback_ != nullptr) { hiChainConnectorCallback_->OnMemberJoin(requestId, DM_OK); hiChainConnectorCallback_->OnGroupCreated(requestId, data); @@ -286,12 +289,14 @@ void HiChainConnector::onError(int64_t requestId, int operationCode, int errorCo LOGI("HichainAuthenCallBack::onError reqId:%lld, operation:%d, errorCode:%d.", requestId, operationCode, errorCode); if (operationCode == GroupOperationCode::MEMBER_JOIN) { LOGE("Add Member To Group failed"); + SysEventWrite(ADD_HICHAIN_GROUP_FAILED, DM_HISYEVENT_BEHAVIOR, ADD_HICHAIN_GROUP_FAILED_MSG); if (hiChainConnectorCallback_ != nullptr) { hiChainConnectorCallback_->OnMemberJoin(requestId, ERR_DM_FAILED); } } if (operationCode == GroupOperationCode::GROUP_CREATE) { LOGE("Create group failed"); + SysEventWrite(DM_CREATE_GROUP_FAILED, DM_HISYEVENT_BEHAVIOR, DM_CREATE_GROUP_FAILED_MSG); if (hiChainConnectorCallback_ != nullptr) { hiChainConnectorCallback_->OnGroupCreated(requestId, "{}"); } diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp index 99605d7d..c13dc691 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_session.cpp @@ -17,6 +17,7 @@ #include "dm_anonymous.h" #include "dm_constants.h" +#include "dm_hitrace.h" #include "dm_log.h" #include "nlohmann/json.hpp" #include "softbus_connector.h" @@ -60,6 +61,7 @@ int32_t SoftbusSession::UnRegisterSessionCallback() int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) { LOGI("SoftbusSession::OpenAuthSession"); + DmTraceStart(DM_HITRACE_AUTH_TO_OPPEN_SESSION); int32_t sessionId = -1; std::string connectAddr; ConnectionAddr *addrInfo = SoftbusConnector::GetConnectAddr(deviceId, connectAddr); @@ -72,6 +74,7 @@ int32_t SoftbusSession::OpenAuthSession(const std::string &deviceId) LOGE("open session error, ret:%d", sessionId); return sessionId; } + DmTraceEnd(); LOGI("SoftbusSession::OpenAuthSession success. sessionId is:%d", sessionId); return sessionId; } diff --git a/services/devicemanagerservice/src/device_manager_service.cpp b/services/devicemanagerservice/src/device_manager_service.cpp index ebafb5d0..0c97d234 100644 --- a/services/devicemanagerservice/src/device_manager_service.cpp +++ b/services/devicemanagerservice/src/device_manager_service.cpp @@ -17,7 +17,6 @@ #include - #include "device_manager_service_listener.h" #include "dm_constants.h" #include "dm_device_info_manager.h" diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 01c4fdfe..1cd8bdf1 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -158,6 +158,11 @@ ohos_unittest("UTTest_softbus_connector") { ] deps = [ ":device_manager_test" ] + + external_deps = [ + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + ] } ## UnitTest UTTest_softbus_connector }}} @@ -169,6 +174,11 @@ ohos_unittest("UTTest_softbus_session") { sources = [ "UTTest_softbus_session.cpp" ] deps = [ ":device_manager_test_common" ] + + external_deps = [ + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + ] } ## UnitTest UTTest_softbus_session }}} @@ -283,6 +293,8 @@ ohos_unittest("UTTest_profile_connector") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", ] } @@ -300,6 +312,8 @@ ohos_unittest("UTTest_device_profile_adapter") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", ] } @@ -359,6 +373,11 @@ ohos_unittest("UTTest_dm_device_state_manager") { ] deps = [ ":device_manager_test" ] + + external_deps = [ + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", + ] } ## UnitTest UTTest_dm_device_state_manager }}} @@ -448,6 +467,8 @@ ohos_unittest("UTTest_dm_discovery_manager") { ] deps = [ ":device_manager_test" ] + + external_deps = [ "hitrace_native:hitrace_meter" ] } ## UnitTest UTTest_dm_discovery_manager }}} @@ -640,6 +661,8 @@ ohos_static_library("device_manager_test") { "common_event_service:cesfwk_innerkits", "dsoftbus:softbus_client", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 135f419a..c411fc3b 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -24,6 +24,8 @@ if (defined(ohos_lite)) { static_library("devicemanagerutils_mini") { include_dirs = [ "${utils_path}/include", + "${utils_path}/include/dfx", + "${utils_path}/include/dfx/lite", "${utils_path}/include/permission/lite", "${common_path}/include", ] @@ -40,6 +42,8 @@ if (defined(ohos_lite)) { ] sources = [ + "${utils_path}/src/dfx/lite/dm_hisysevent.cpp", + "${utils_path}/src/dfx/lite/dm_hitrace.cpp", "${utils_path}/src/dm_anonymous.cpp", "${utils_path}/src/dm_error_message.cpp", "${utils_path}/src/dm_log.cpp", @@ -48,6 +52,7 @@ if (defined(ohos_lite)) { ] defines = [ + "__LITEOS_M__", "HI_LOG_ENABLE", "DH_LOG_TAG=\"devicemanagerutils\"", "LOG_DOMAIN=0xD004100", @@ -70,6 +75,8 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc", "${common_path}/include/ipc/model", "include", + "include/dfx", + "include/dfx/lite", "include/fwkload/lite", "include/ipc/lite", "include/permission/lite", @@ -91,6 +98,8 @@ if (defined(ohos_lite)) { "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", ] sources = [ + "src/dfx/lite/dm_hisysevent.cpp", + "src/dfx/lite/dm_hitrace.cpp", "src/dm_anonymous.cpp", "src/dm_error_message.cpp", "src/dm_log.cpp", @@ -100,6 +109,7 @@ if (defined(ohos_lite)) { "src/permission/lite/permission_manager.cpp", ] defines = [ + "LITE_DEVICE", "hI_LOG_ENABLE", "DH_LOG_TAG=\"devicemanagerutils\"", "lOG_DOMAIN=0xD004100", @@ -121,6 +131,8 @@ if (defined(ohos_lite)) { include_dirs = [ "include", "include/fwkload/standard", + "include/dfx", + "include/dfx/standard", "include/ipc/standard", "${common_path}/include", "${common_path}/include/ipc", @@ -132,6 +144,8 @@ if (defined(ohos_lite)) { ohos_shared_library("devicemanagerutils") { sources = [ + "src/dfx/standard/dm_hisysevent.cpp", + "src/dfx/standard/dm_hitrace.cpp", "src/dm_anonymous.cpp", "src/dm_error_message.cpp", "src/dm_hash.cpp", @@ -158,6 +172,8 @@ if (defined(ohos_lite)) { external_deps = [ "access_token:libaccesstoken_sdk", + "hisysevent_native:libhisysevent", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/utils/include/dfx/dm_dfx_constants.h b/utils/include/dfx/dm_dfx_constants.h new file mode 100644 index 00000000..3d4f1768 --- /dev/null +++ b/utils/include/dfx/dm_dfx_constants.h @@ -0,0 +1,69 @@ +/* + * 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_DFX_CONSTANTS_H +#define OHOS_DM_DFX_CONSTANTS_H + +#include + +namespace OHOS { +namespace DistributedHardware { +// HisysEvent Type +const int DM_HISYEVENT_FAULT = 1; +const int DM_HISYEVENT_STATISTIC = 2; +const int DM_HISYEVENT_SECURITY = 3; +const int DM_HISYEVENT_BEHAVIOR = 4; + +// state +const std::string DM_INIT_DEVICE_MANAGER_SUCCESS = "DM_INIT_DEVICE_MANAGER_SUCCESS"; +const std::string DM_INIT_DEVICE_MANAGER_FAILED = "DM_INIT_DEVICE_MANAGER_FAILED"; +const std::string START_DEVICE_DISCOVERY_SUCCESS = "START_DEVICE_DISCOVERY_SUCCESS"; +const std::string START_DEVICE_DISCOVERY_FAILED = "START_DEVICE_DISCOVERY_FAILED"; +const std::string GET_LOCAL_DEVICE_INFO_SUCCESS = "GET_LOCAL_DEVICE_INFO_SUCCESS"; +const std::string GET_LOCAL_DEVICE_INFO_FAILED = "GET_LOCAL_DEVICE_INFO_FAILED"; +const std::string DM_SEND_REQUEST_SUCCESS = "DM_SEND_REQUEST_SUCCESS"; +const std::string DM_SEND_REQUEST_FAILED = "DM_SEND_REQUEST_FAILED"; +const std::string ADD_HICHAIN_GROUP_SUCCESS = "ADD_HICHAIN_GROUP_SUCCESS"; +const std::string ADD_HICHAIN_GROUP_FAILED = "ADD_HICHAIN_GROUP_FAILED"; +const std::string DM_CREATE_GROUP_SUCCESS = "DM_CREATE_GROUP_SUCCESS"; +const std::string DM_CREATE_GROUP_FAILED = "DM_CREATE_GROUP_FAILED"; +const std::string UNAUTHENTICATE_DEVICE_SUCCESS = "UNAUTHENTICATE_DEVICE_SUCCESS"; +const std::string UNAUTHENTICATE_DEVICE_FAILED = "UNAUTHENTICATE_DEVICE_FAILED"; + +// msg +const std::string DM_INIT_DEVICE_MANAGER_SUCCESS_MSG = "init devicemanager success."; +const std::string DM_INIT_DEVICE_MANAGER_FAILED_MSG = "init devicemanager failed."; +const std::string START_DEVICE_DISCOVERY_SUCCESS_MSG = "device manager discovery success."; +const std::string START_DEVICE_DISCOVERY_FAILED_MSG = "device manager discovery failed."; +const std::string GET_LOCAL_DEVICE_INFO_SUCCESS_MSG = "get local device info success."; +const std::string GET_LOCAL_DEVICE_INFO_FAILED_MSG = "get local device info failed."; +const std::string DM_SEND_REQUEST_SUCCESS_MSG = "send request success."; +const std::string DM_SEND_REQUEST_FAILED_MSG = "send request failed."; +const std::string ADD_HICHAIN_GROUP_SUCCESS_MSG = "dm add member to group success."; +const std::string ADD_HICHAIN_GROUP_FAILED_MSG = "dm add member to group failed."; +const std::string DM_CREATE_GROUP_SUCCESS_MSG = "dm create group success."; +const std::string DM_CREATE_GROUP_FAILED_MSG = "dm create group failed."; +const std::string UNAUTHENTICATE_DEVICE_SUCCESS_MSG = "unauthenticate device success."; +const std::string UNAUTHENTICATE_DEVICE_FAILED_MSG = "unauthenticate device failed."; + +// dfx hitrace +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"; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_DFX_CONSTANTS_H diff --git a/utils/include/dfx/lite/dm_hisysevent.h b/utils/include/dfx/lite/dm_hisysevent.h new file mode 100644 index 00000000..c543bb64 --- /dev/null +++ b/utils/include/dfx/lite/dm_hisysevent.h @@ -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. + */ + +#ifndef OHOS_DISTRIBUTED_DM_HISYSEVENT_H +#define OHOS_DISTRIBUTED_DM_HISYSEVENT_H + +#include "dm_constants.h" +#include "dm_dfx_constants.h" + +#include +#include + +namespace OHOS { +namespace DistributedHardware { +void SysEventWrite(const std::string &status, int32_t eventType, const std::string &msg); +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_DM_HISYSEVENT_H diff --git a/utils/include/dfx/lite/dm_hitrace.h b/utils/include/dfx/lite/dm_hitrace.h new file mode 100644 index 00000000..ae1e2e31 --- /dev/null +++ b/utils/include/dfx/lite/dm_hitrace.h @@ -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. + */ + +#ifndef OHOS_DM_HITRACE_H +#define OHOS_DM_HITRACE_H + +#include + +#include "dm_constants.h" +#include "dm_dfx_constants.h" + +namespace OHOS { +namespace DistributedHardware { +void DmTraceStart(const std::string &msg); +void DmTraceEnd(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/utils/include/dfx/standard/dm_hisysevent.h b/utils/include/dfx/standard/dm_hisysevent.h new file mode 100644 index 00000000..a7296ad4 --- /dev/null +++ b/utils/include/dfx/standard/dm_hisysevent.h @@ -0,0 +1,34 @@ +/* + * 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_DISTRIBUTED_DM_HISYSEVENT_H +#define OHOS_DISTRIBUTED_DM_HISYSEVENT_H + +#include "dm_anonymous.h" +#include "dm_log.h" +#include "dm_constants.h" +#include "dm_dfx_constants.h" +#include "hisysevent.h" +#include "single_instance.h" + +#include +#include + +namespace OHOS { +namespace DistributedHardware { +void SysEventWrite(const std::string &status, int32_t eventType, const std::string &msg); +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_DM_HISYSEVENT_H diff --git a/utils/include/dfx/standard/dm_hitrace.h b/utils/include/dfx/standard/dm_hitrace.h new file mode 100644 index 00000000..a8374deb --- /dev/null +++ b/utils/include/dfx/standard/dm_hitrace.h @@ -0,0 +1,32 @@ +/* + * 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" +#include "dm_dfx_constants.h" + +namespace OHOS { +namespace DistributedHardware { +void DmTraceStart(const std::string &msg); +void DmTraceEnd(); +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/utils/src/dfx/lite/dm_hisysevent.cpp b/utils/src/dfx/lite/dm_hisysevent.cpp new file mode 100644 index 00000000..e3bc5cee --- /dev/null +++ b/utils/src/dfx/lite/dm_hisysevent.cpp @@ -0,0 +1,25 @@ +/* + * 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_hisysevent.h" + +namespace OHOS { +namespace DistributedHardware { +void SysEventWrite(const std::string &status, int32_t eventType, const std::string &msg) +{ + return; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/src/dfx/lite/dm_hitrace.cpp b/utils/src/dfx/lite/dm_hitrace.cpp new file mode 100644 index 00000000..6030b857 --- /dev/null +++ b/utils/src/dfx/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(const std::string &msg) +{ + return; +} + +void DmTraceEnd() +{ + return; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/src/dfx/standard/dm_hisysevent.cpp b/utils/src/dfx/standard/dm_hisysevent.cpp new file mode 100644 index 00000000..599cf5ad --- /dev/null +++ b/utils/src/dfx/standard/dm_hisysevent.cpp @@ -0,0 +1,34 @@ +/* + * 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_hisysevent.h" + +namespace OHOS { +namespace DistributedHardware { +void SysEventWrite(const std::string &status, int32_t eventType, const std::string &msg) +{ + int32_t res = OHOS::HiviewDFX::HiSysEvent::Write( + OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_DEVICE_MANAGER, + status.c_str(), + (OHOS::HiviewDFX::HiSysEvent::EventType)eventType, + "PID", getpid(), + "UID", getuid(), + "MSG", msg.c_str()); + if (res != DM_OK) { + LOGE("%s Write HiSysEvent error, res:%d", status.c_str(), res); + } +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/utils/src/dfx/standard/dm_hitrace.cpp b/utils/src/dfx/standard/dm_hitrace.cpp new file mode 100644 index 00000000..1bbe65fa --- /dev/null +++ b/utils/src/dfx/standard/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" +#include "hitrace_meter.h" + +namespace OHOS { +namespace DistributedHardware { +void DmTraceStart(const std::string &msg) +{ + StartTrace(HITRACE_TAG_DEVICE_MANAGER, msg); +} + +void DmTraceEnd() +{ + FinishTrace(HITRACE_TAG_DEVICE_MANAGER); +} +} // namespace DistributedHardware +} // namespace OHOS