From 92d6cf7434b8ceff3feeb632de02de426c2bc100 Mon Sep 17 00:00:00 2001 From: m30030488 Date: Sat, 25 Jun 2022 14:11:15 +0800 Subject: [PATCH] dfx Signed-off-by: m30030488 --- bundle.json | 3 ++ hisysevent.yaml | 21 +++++++++ services/core/BUILD.gn | 5 +++ .../core/include/dfx/dp_hisysevent_report.h | 44 +++++++++++++++++++ services/core/include/dfx/dp_hitrace_report.h | 34 ++++++++++++++ .../contentsensor/content_sensor_manager.cpp | 6 ++- .../src/dbstorage/device_profile_storage.cpp | 3 +- .../device_profile_storage_manager.cpp | 21 +++++++++ .../core/src/dfx/dp_hisysevent_report.cpp | 37 ++++++++++++++++ .../distributed_device_profile_service.cpp | 5 +++ services/core/test/BUILD.gn | 6 ++- .../test/unittest/dp_hisysevent_report.cpp | 31 +++++++++++++ .../core/test/unittest/dp_hisysevent_report.h | 40 +++++++++++++++++ .../core/test/unittest/profile_crud_test.cpp | 12 +++++ 14 files changed, 265 insertions(+), 3 deletions(-) create mode 100644 hisysevent.yaml create mode 100644 services/core/include/dfx/dp_hisysevent_report.h create mode 100644 services/core/include/dfx/dp_hitrace_report.h create mode 100644 services/core/src/dfx/dp_hisysevent_report.cpp create mode 100644 services/core/test/unittest/dp_hisysevent_report.cpp create mode 100644 services/core/test/unittest/dp_hisysevent_report.h diff --git a/bundle.json b/bundle.json index e889dfb..db4cbc9 100644 --- a/bundle.json +++ b/bundle.json @@ -13,6 +13,9 @@ "name": "device_profile_core", "subsystem": "deviceprofile", "adapted_system_type": [ "standard" ], + "hisysevent_config":[ + "//foundation/deviceprofile/device_profile_core/hisysevent.yaml" + ], "rom": "", "ram": "", "deps": { diff --git a/hisysevent.yaml b/hisysevent.yaml new file mode 100644 index 0000000..4199d39 --- /dev/null +++ b/hisysevent.yaml @@ -0,0 +1,21 @@ +# 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. + +domain: DEVICE_PROFILE + +DEVICE_PROFILE_SYNC_EVENT: + __BASE: {type: BEHAVIOR, level: MINOR, tag: deviceProfileSyn, desc: device profile sync} + +DEVICE_PROFILE_SYNC_FAILED: + __BASE: {type: FAULT, level: CRITICAL, desc: device profile sync failed} + FAULT_CODE: {type: INT32, desc: fault code} \ No newline at end of file diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index 8916656..259c048 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -16,6 +16,7 @@ import("//build/ohos_var.gni") device_profile_path = "//foundation/deviceprofile/device_profile_core" device_profile_innerkits = "${device_profile_path}/interfaces/innerkits" +services = "${device_profile_path}/services" device_profile_common_sources = [ "${device_profile_path}/common/src/device_profile_utils.cpp" ] @@ -30,6 +31,7 @@ config("device_profile_core_config") { "include/subscribemanager", "${device_profile_path}/common/include", "${device_profile_innerkits}/core/include", + "${services}/core/include", "//third_party/json/include", ] } @@ -51,6 +53,7 @@ ohos_shared_library("distributed_device_profile") { "src/dbstorage/sync_coordinator.cpp", "src/devicemanager/device_info.cpp", "src/devicemanager/device_manager.cpp", + "src/dfx/hisysevent_report.cpp", "src/distributed_device_profile_service.cpp", "src/distributed_device_profile_stub.cpp", "src/profile_change_notification.cpp", @@ -76,6 +79,8 @@ ohos_shared_library("distributed_device_profile") { "distributeddatamgr:distributeddata_inner", "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/core/include/dfx/dp_hisysevent_report.h b/services/core/include/dfx/dp_hisysevent_report.h new file mode 100644 index 0000000..0e8f950 --- /dev/null +++ b/services/core/include/dfx/dp_hisysevent_report.h @@ -0,0 +1,44 @@ +/* + * 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_DEVICEPROFILE_HISTSEVENT_REPORT_H +#define OHOS_DEVICEPROFILE_HISTSEVENT_REPORT_H + +#include "hisysevent.h" + +namespace OHOS { +namespace DeviceProfile { +namespace BehaviorEvent{ + const std::string DEVICE_PROFILE_SYNC_EVENT = "DEVICE_PROFILE_SYNC_EVENT"; +} + +namespace FaultEvent{ + const std::string DEVICE_PROFILE_SYNC_FAILED = "DEVICE_PROFILE_SYNC_FAILED"; +} + +namespace ErrorType{ + const std::string FAULT_CODE_KEY = "FAULT_CODE"; +} + const std::string DOMAIN_NAME = std::string(OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE); + +class DpHiSysEventReport { +public: + static int ReportSyncBehavior(const std::string& eventName); + static int ReportSyncFault(const std::string& faultName, const int32_t code); +}; +} // namespace DeviceProfile +} // namespace OHOS + +#endif /* OHOS_DEVICEPROFILE_HISTSEVENT_REPORT_H */ \ No newline at end of file diff --git a/services/core/include/dfx/dp_hitrace_report.h b/services/core/include/dfx/dp_hitrace_report.h new file mode 100644 index 0000000..bfc8a65 --- /dev/null +++ b/services/core/include/dfx/dp_hitrace_report.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_DEVICEPROFILE_HITRACE_REPORT_H +#define OHOS_DEVICEPROFILE_HITRACE_REPORT_H + +#include "hisysevent.h" + +namespace OHOS { +namespace DeviceProfile { +namespace { + const std::string DP_DEVICE_PUT_TRACE = "DP_DEVICE_PUT"; + const std::string DP_DEVICE_GET_TRACE = "DP_DEVICE_GET"; + const std::string DP_DEVICE_DELETE_TRACE = "DP_DEVICE_DELETE"; + const std::string DP_DEVICE_SYNC_TRACE = "DP_DEVICE_SYNC"; + const std::string DP_DEVICE_SUB_TRACE = "DP_DEVICE_SUB"; + const std::string DP_CONTENT_SENSOR_TRACE = "DP_CONTENT_SENSOR"; +} +} // namespace DeviceProfile +} // namespace OHOS + +#endif /* OHOS_DEVICEPROFILE_HITRACE_REPORT_H */ \ No newline at end of file diff --git a/services/core/src/contentsensor/content_sensor_manager.cpp b/services/core/src/contentsensor/content_sensor_manager.cpp index 73ea7a6..c26ebe7 100755 --- a/services/core/src/contentsensor/content_sensor_manager.cpp +++ b/services/core/src/contentsensor/content_sensor_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -17,9 +17,12 @@ #include "device_info_collector.h" #include "device_profile_log.h" +#include "dfx/dp_hitrace_report.h" #include "syscap_info_collector.h" #include "system_info_collector.h" +#include "hitrace_meter.h" + namespace OHOS { namespace DeviceProfile { namespace { @@ -46,6 +49,7 @@ bool ContentSensorManager::Collect() taskList.push_back(std::make_shared()); taskList.push_back(std::make_shared()); taskList.push_back(std::make_shared()); + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_CONTENT_SENSOR_TRACE); for (auto& task : taskList) { ServiceCharacteristicProfile profileData; if (!task->ConvertToProfileData(profileData)) { diff --git a/services/core/src/dbstorage/device_profile_storage.cpp b/services/core/src/dbstorage/device_profile_storage.cpp index 214b38a..52b6a08 100755 --- a/services/core/src/dbstorage/device_profile_storage.cpp +++ b/services/core/src/dbstorage/device_profile_storage.cpp @@ -23,6 +23,8 @@ #include "device_profile_log.h" #include "device_profile_storage_manager.h" #include "device_profile_utils.h" +#include "dfx/dp_hisysevent_report.h" +#include "dfx/dp_hitrace_report.h" #include "service_characteristic_profile.h" #include "trust_group_manager.h" @@ -270,7 +272,6 @@ int32_t DeviceProfileStorage::SyncDeviceProfile(const std::vector& int32_t DeviceProfileStorage::RemoveDeviceData(const std::string networkId) { HILOGI("called"); - std::unique_lock writeLock(storageLock_); if (kvStorePtr_ == nullptr) { HILOGE("null kvstore"); diff --git a/services/core/src/dbstorage/device_profile_storage_manager.cpp b/services/core/src/dbstorage/device_profile_storage_manager.cpp index c0bc6b0..9cdfa91 100644 --- a/services/core/src/dbstorage/device_profile_storage_manager.cpp +++ b/services/core/src/dbstorage/device_profile_storage_manager.cpp @@ -18,12 +18,17 @@ #include #include +#include + #include "device_manager.h" #include "device_profile_errors.h" #include "device_profile_log.h" #include "device_profile_utils.h" +#include "dfx/dp_hisysevent_report.h" +#include "dfx/dp_hitrace_report.h" #include "sync_coordinator.h" +#include "hitrace_meter.h" #include "ipc_object_proxy.h" #include "ipc_skeleton.h" #include "iservice_registry.h" @@ -127,6 +132,7 @@ std::string DeviceProfileStorageManager::GenerateKey(const std::string& udid, int32_t DeviceProfileStorageManager::PutDeviceProfile(const ServiceCharacteristicProfile& profile) { + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_PUT_TRACE); if (kvDataServiceFailed_ || onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { HILOGE("kvstore init failed"); return ERR_DP_INIT_DB_FAILED; @@ -165,6 +171,7 @@ int32_t DeviceProfileStorageManager::PutDeviceProfile(const ServiceCharacteristi int32_t DeviceProfileStorageManager::GetDeviceProfile(const std::string& udid, const std::string& serviceId, ServiceCharacteristicProfile& profile) { + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_GET_TRACE); if (onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { HILOGE("kvstore init failed"); return ERR_DP_INIT_DB_FAILED; @@ -231,6 +238,7 @@ void DeviceProfileStorageManager::SetServiceType(const std::string& udid, int32_t DeviceProfileStorageManager::DeleteDeviceProfile(const std::string& serviceId) { + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_DELETE_TRACE); if (onlineSyncTbl_->GetInitStatus() == StorageInitStatus::INIT_FAILED) { HILOGE("kvstore init failed"); return ERR_DP_INIT_DB_FAILED; @@ -309,14 +317,24 @@ int32_t DeviceProfileStorageManager::SyncDeviceProfile(const SyncOptions& syncOp auto syncTask = [syncOptions, this]() { HILOGI("start sync"); + int ret = DpHiSysEventReport::ReportSyncBehavior(BehaviorEvent::DEVICE_PROFILE_SYNC_EVENT); + if (ret != 0) { + HILOGE("hisysevent write failed! ret %{public}d.", ret); + } + auto devicesList = syncOptions.GetDeviceList(); if (devicesList.empty()) { DeviceManager::GetInstance().GetDeviceIdList(devicesList); } + SyncCoordinator::GetInstance().SetSyncTrigger(false); std::vector devicesVector(std::vector { devicesList.begin(), devicesList.end() }); int32_t result = onlineSyncTbl_->SyncDeviceProfile(devicesVector, syncOptions.GetSyncMode()); if (result != ERR_OK) { + int ret = DpHiSysEventReport::ReportSyncFault(FaultEvent::DEVICE_PROFILE_SYNC_FAILED, result); + if (ret != 0) { + HILOGE("hisysevent write failed! ret %{public}d.", ret); + } HILOGE("sync failed result : %{public}d", result); NotifySyncCompleted(); return; @@ -337,6 +355,8 @@ int32_t DeviceProfileStorageManager::NotifySyncStart(const sptr& return ERR_DP_DEVICE_SYNC_BUSY; } + StartAsyncTrace(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SYNC_TRACE, getpid()); + { std::lock_guard autoLock(profileSyncLock_); syncEventNotifier_ = profileEventNotifier; @@ -362,6 +382,7 @@ void DeviceProfileStorageManager::NotifySyncCompleted() { HILOGI("called"); SyncCoordinator::GetInstance().ReleaseSync(); + FinishAsyncTrace(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SYNC_TRACE, getpid()); std::lock_guard autoLock(profileSyncLock_); std::list profileEvents; profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); diff --git a/services/core/src/dfx/dp_hisysevent_report.cpp b/services/core/src/dfx/dp_hisysevent_report.cpp new file mode 100644 index 0000000..bf3e82a --- /dev/null +++ b/services/core/src/dfx/dp_hisysevent_report.cpp @@ -0,0 +1,37 @@ +/* + * 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 "dfx/dp_hisysevent_report.h" + +namespace OHOS { +namespace DeviceProfile { +using namespace OHOS::HiviewDFX; +namespace { + const std::string TAG = "DpHiSysEventReport"; +} + +int DpHiSysEventReport::ReportSyncBehavior(const std::string& eventName) +{ + int ret = HiSysEvent::Write(DOMAIN_NAME, eventName, HiSysEvent::EventType::BEHAVIOR); + return ret; +} + +int DpHiSysEventReport::ReportSyncFault(const std::string& faultName, const int32_t code) +{ + int ret = HiSysEvent::Write(DOMAIN_NAME, faultName, HiSysEvent::EventType::FAULT, FAULT_CODE_KEY, code); + return ret; +} +} +} \ No newline at end of file diff --git a/services/core/src/distributed_device_profile_service.cpp b/services/core/src/distributed_device_profile_service.cpp index 5be11dc..ab75f42 100644 --- a/services/core/src/distributed_device_profile_service.cpp +++ b/services/core/src/distributed_device_profile_service.cpp @@ -21,11 +21,15 @@ #include "device_profile_errors.h" #include "device_profile_log.h" #include "device_profile_storage_manager.h" +#include "dfx/dp_hitrace_report.h" #include "service_characteristic_profile.h" #include "subscribe_manager.h" #include "system_ability_definition.h" #include "trust_group_manager.h" +#include "hitrace_meter.h" + + namespace OHOS { namespace DeviceProfile { namespace { @@ -95,6 +99,7 @@ int32_t DistributedDeviceProfileService::SubscribeProfileEvents(const std::list< const sptr& profileEventNotifier, std::list& failedEvents) { + HITRACE_METER_NAME(HITRACE_TAG_DEVICE_PROFILE, DP_DEVICE_SYNC_TRACE); return SubscribeManager::GetInstance().SubscribeProfileEvents(subscribeInfos, profileEventNotifier, failedEvents); } diff --git a/services/core/test/BUILD.gn b/services/core/test/BUILD.gn index f23ccb7..658c3cf 100755 --- a/services/core/test/BUILD.gn +++ b/services/core/test/BUILD.gn @@ -32,6 +32,7 @@ device_profile_deps = [ device_profile_external_deps = [ "access_token:libaccesstoken_sdk", "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "syscap_codec:syscap_interface_shared", @@ -41,7 +42,10 @@ device_profile_external_deps = [ ohos_unittest("profile_crud_test") { module_out_path = module_output_path - sources = [ "unittest/profile_crud_test.cpp" ] + sources = [ + "unittest/dp_hisysevent_report.cpp", + "unittest/profile_crud_test.cpp", + ] configs = device_profile_configs deps = device_profile_deps external_deps = device_profile_external_deps diff --git a/services/core/test/unittest/dp_hisysevent_report.cpp b/services/core/test/unittest/dp_hisysevent_report.cpp new file mode 100644 index 0000000..00599c1 --- /dev/null +++ b/services/core/test/unittest/dp_hisysevent_report.cpp @@ -0,0 +1,31 @@ +/* + * 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 "dfx/dp_hisysevent_report.h" + +namespace OHOS { +namespace DeviceProfile { +using namespace OHOS::HiviewDFX; +namespace { + const std::string TAG = "DpHiSysEventReport"; +} + +int DpHiSysEventReport::ReportSyncFault(const std::string& faultName, const int32_t code) +{ + int ret = HiSysEvent::Write(DOMAIN_NAME, faultName, HiSysEvent::EventType::FAULT, FAULT_CODE_KEY, code); + return ret; +} +} +} \ No newline at end of file diff --git a/services/core/test/unittest/dp_hisysevent_report.h b/services/core/test/unittest/dp_hisysevent_report.h new file mode 100644 index 0000000..78a5c13 --- /dev/null +++ b/services/core/test/unittest/dp_hisysevent_report.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_DEVICEPROFILE_HISTSEVENT_REPORT_H +#define OHOS_DEVICEPROFILE_HISTSEVENT_REPORT_H + +#include "hisysevent.h" + +namespace OHOS { +namespace DeviceProfile { +namespace FaultEvent{ + const std::string DEVICE_PROFILE_SYNC_FAILED = "DEVICE_PROFILE_SYNC_FAILED"; +} + +namespace ErrorType{ + const std::string FAULT_CODE_KEY = "FAULT_CODE"; +} + const std::string DOMAIN_NAME = std::string(OHOS::HiviewDFX::HiSysEvent::Domain::DEVICE_PROFILE); + +class DpHiSysEventReport { +public: + static int ReportSyncBehavior(const std::string& eventName); + static int ReportSyncFault(const std::string& faultName, const int32_t code); +}; +} // namespace DeviceProfile +} // namespace OHOS + +#endif /* OHOS_DEVICEPROFILE_HISTSEVENT_REPORT_H */ \ No newline at end of file diff --git a/services/core/test/unittest/profile_crud_test.cpp b/services/core/test/unittest/profile_crud_test.cpp index 0fcddd9..89161b1 100755 --- a/services/core/test/unittest/profile_crud_test.cpp +++ b/services/core/test/unittest/profile_crud_test.cpp @@ -15,6 +15,7 @@ #include "gtest/gtest.h" +#include "dp_hisysevent_report.h" #include "utils.h" #define private public @@ -228,5 +229,16 @@ HWTEST_F(ProfileCrudTest, GetDeviceProfile_001, TestSize.Level2) DTEST_LOG << "PrivateSyscap: " << *(priOutput + i) << std::endl; } } + +/** + * @tc.name: DfxErrorPrint_001 + * @tc.desc: print hisysevent error event + * @tc.type: FUNC + */ +HWTEST_F(ProfileCrudTest, DfxErrorPrint_001, TestSize.Level0) +{ + int ret = DpHiSysEventReport::ReportSyncFault(DEVICE_PROFILE_SYNC_FAILED, -1); + EXPECT_TRUE(ret == 0); +} } } \ No newline at end of file