From c3f2eee09fc4db093f2c618ffa4059d076865321 Mon Sep 17 00:00:00 2001 From: wangyikai Date: Wed, 19 Mar 2025 16:02:17 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90hdf=5Fcore=E3=80=91=E6=B7=BB=E5=8A=A0x?= =?UTF-8?q?collie=E7=BB=B4=E6=B5=8B=EF=BC=8C=20=E9=80=9A=E8=BF=87feature?= =?UTF-8?q?=20hdf=5Fcore=5Fdefault=5Fhicollie=5Fconfig=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyikai --- adapter/uhdf2/hdi.gni | 1 - adapter/uhdf2/ipc/BUILD.gn | 4 +++ adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp | 5 +++ adapter/uhdf2/pub_utils/BUILD.gn | 2 +- adapter/uhdf2/uhdf.gni | 13 ++++--- adapter/uhdf2/utils/include/hdf_xcollie.h | 33 +++++++++-------- adapter/uhdf2/utils/src/hdf_xcollie.cpp | 37 +++++++++++--------- bundle.json | 3 +- 8 files changed, 60 insertions(+), 38 deletions(-) diff --git a/adapter/uhdf2/hdi.gni b/adapter/uhdf2/hdi.gni index 882ba7414..dbfaa404f 100644 --- a/adapter/uhdf2/hdi.gni +++ b/adapter/uhdf2/hdi.gni @@ -12,7 +12,6 @@ # limitations under the License.. import("//build/ohos.gni") -import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") hdf_fwk_path = "//drivers/hdf_core/framework" idl_tool_path = "//foundation/ability/idl_tool/idl_tool_2" diff --git a/adapter/uhdf2/ipc/BUILD.gn b/adapter/uhdf2/ipc/BUILD.gn index 1bef89f42..4481e0a9d 100644 --- a/adapter/uhdf2/ipc/BUILD.gn +++ b/adapter/uhdf2/ipc/BUILD.gn @@ -56,6 +56,10 @@ if (defined(ohos_lite)) { "ipc:ipc_single", "samgr:samgr_proxy", ] + + if (hicollie_enabled) { + external_deps += [ "hicollie:libhicollie" ] + } } else { external_deps = [ "hilog:libhilog", diff --git a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp index f6d3db3cd..9966c1bd0 100644 --- a/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp +++ b/adapter/uhdf2/ipc/src/hdf_remote_adapter.cpp @@ -311,6 +311,9 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) const int32_t sleepInterval = 20000; OHOS::sptr saManager; { + OHOS::HdfXCollie hdfXCollie("HdfRemoteAdapterAddSa_" + OHOS::ToString(saId) + "_get_samgr", + OHOS::DEFAULT_TIMEOUT_SECONDS, nullptr, nullptr, OHOS::HDF_XCOLLIE_FLAG_RECOVERY); + for (uint32_t cnt = 0; cnt < waitTimes; ++cnt) { HDF_LOGI("waiting for samgr... %{public}d", cnt); saManager = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); @@ -329,6 +332,8 @@ int HdfRemoteAdapterAddSa(int32_t saId, struct HdfRemoteService *service) } } { + OHOS::HdfXCollie hdfXCollie("HdfRemoteAdapterAddSa_" + OHOS::ToString(saId) + "_add_sa", + OHOS::DEFAULT_TIMEOUT_SECONDS, nullptr, nullptr, OHOS::HDF_XCOLLIE_FLAG_RECOVERY); struct HdfRemoteServiceHolder *holder = reinterpret_cast(service); #ifdef WITH_SELINUX OHOS::sptr remote = holder->remote_; diff --git a/adapter/uhdf2/pub_utils/BUILD.gn b/adapter/uhdf2/pub_utils/BUILD.gn index 173d86786..a8a2a679d 100644 --- a/adapter/uhdf2/pub_utils/BUILD.gn +++ b/adapter/uhdf2/pub_utils/BUILD.gn @@ -54,7 +54,7 @@ if (defined(ohos_lite)) { ] defines = [] if (hicollie_enabled) { - public_external_deps = [ "hicollie:libhicollie" ] + external_deps += [ "hicollie:libhicollie" ] defines += [ "HDFHICOLLIE_ENABLE" ] } diff --git a/adapter/uhdf2/uhdf.gni b/adapter/uhdf2/uhdf.gni index 3a7b5f64e..9de2161f4 100644 --- a/adapter/uhdf2/uhdf.gni +++ b/adapter/uhdf2/uhdf.gni @@ -14,11 +14,16 @@ hdf_framework_path = "//drivers/hdf_core/framework" hdf_uhdf_path = "//drivers/hdf_core/adapter/uhdf2" declare_args() { - hicollie_enabled = true - if (defined(global_parts_info) && - !defined(global_parts_info.hiviewdfx_hicollie)) { - hicollie_enabled = false + hdf_core_default_hicollie_config = false +} + +declare_args() { + hicollie_enabled = false + + if (hdf_core_default_hicollie_config) { + hicollie_enabled = hdf_core_default_hicollie_config } + with_sample = false hdf_core_default_peripheral_config = true } diff --git a/adapter/uhdf2/utils/include/hdf_xcollie.h b/adapter/uhdf2/utils/include/hdf_xcollie.h index 32511b961..7a0068942 100644 --- a/adapter/uhdf2/utils/include/hdf_xcollie.h +++ b/adapter/uhdf2/utils/include/hdf_xcollie.h @@ -24,24 +24,29 @@ #endif namespace OHOS { +constexpr uint32_t HDF_XCOLLIE_FLAG_LOG = 1; // generate log file +constexpr uint32_t HDF_XCOLLIE_FLAG_RECOVERY = 2; // die when timeout +constexpr uint32_t DEFAULT_TIMEOUT_SECONDS = 10; #ifdef HDFHICOLLIE_ENABLE -using HdfXCollie = ::OHOS::HiviewDFX::XCollie; -#else -class HdfXCollie : public Singleton { - DECLARE_SINGLETON(HdfXCollie); -public: - // NULL impl - int SetTimer(const std::string &name, unsigned int timeout, - std::function func, void *arg, unsigned int flag); +class HdfXCollie { + HdfXCollie(const std::string& tag, uint32_t timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, + std::function func = nullptr, void* arg = nullptr, uint32_t flag = HDF_XCOLLIE_FLAG_LOG); + ~HdfXCollie(); - // NULL impl - void CancelTimer(int id); + void CancelHdfXCollie(); - // NULL impl - int SetTimerCount(const std::string &name, unsigned int timeLimit, int countLimit); +private: + int32_t id_; + std::string tag_; + bool isCanceled_; +}; - // NULL impl - void TriggerTimerCount(const std::string &name, bool bTrigger, const std::string &message); +#else +class HdfXCollie { +public: + HdfXCollie(const std::string& tag, uint32_t timeoutSeconds = DEFAULT_TIMEOUT_SECONDS, + std::function func = nullptr, void* arg = nullptr, uint32_t flag = HDF_XCOLLIE_FLAG_LOG); + ~HdfXCollie(); }; #endif } diff --git a/adapter/uhdf2/utils/src/hdf_xcollie.cpp b/adapter/uhdf2/utils/src/hdf_xcollie.cpp index 0b3f92247..88f5e1ed9 100644 --- a/adapter/uhdf2/utils/src/hdf_xcollie.cpp +++ b/adapter/uhdf2/utils/src/hdf_xcollie.cpp @@ -18,35 +18,38 @@ namespace OHOS { #ifdef HDFHICOLLIE_ENABLE -#else -#define HDFXCOLLIE_SUCCESS 0 -HdfXCollie::HdfXCollie() +HdfXCollie::HdfXCollie(const std::string& tag, uint32_t timeoutSeconds, + std::function func, void* arg, uint32_t flag) { + tag_ = tag; + id_ = HiviewDFX::XCollie::GetInstance().SetTimer(tag_, timeoutSeconds, func, arg, flag); + isCanceled_ = false; + HDF_LOGD("start HdfXCollie, tag:%{public}s,timeout:%{public}u,flag:%{public}u,id:%{public}d", + tag_.c_str(), timeoutSeconds, flag, id_); } + HdfXCollie::~HdfXCollie() { -} -// NULL impl -int HdfXCollie::SetTimer(const std::string &name, unsigned int timeout, - std::function func, void *arg, unsigned int flag) -{ - return HDFXCOLLIE_SUCCESS; + CancelHdfXCollie(); } -// NULL impl -void HdfXCollie::CancelTimer(int id) +void HdfXCollie::CancelHdfXCollie() { + if (!isCanceled_) { + HiviewDFX::XCollie::GetInstance().CancelTimer(id_); + isCanceled_ = true; + HDF_LOGD("cancel HdfXCollie, tag:%{public}s,id:%{public}d", tag_.c_str(), id_); + } } +#else -// NULL impl -int HdfXCollie::SetTimerCount(const std::string &name, unsigned int timeLimit, int countLimit) +HdfXCollie::HdfXCollie(const std::string& tag, uint32_t timeoutSeconds, + std::function func, void* arg, uint32_t flag) { - return HDFXCOLLIE_SUCCESS; } -// NULL impl -void HdfXCollie::TriggerTimerCount(const std::string &name, bool bTrigger, const std::string &message) +HdfXCollie::~HdfXCollie() { } #endif -} \ No newline at end of file +} diff --git a/bundle.json b/bundle.json index 546557309..7b2f6d0ce 100644 --- a/bundle.json +++ b/bundle.json @@ -16,7 +16,8 @@ "hdf_core_khdf_test_support", "hdf_core_platform_test_support", "hdf_core_platform_rtc_test_support", - "hdf_core_default_peripheral_config" + "hdf_core_default_peripheral_config", + "hdf_core_default_hicollie_config" ], "adapted_system_type": ["standard", "small", "mini"], "rom": "735KB", -- Gitee