From eba6488929fd873d6c9c9f742a222ba51ae5fba8 Mon Sep 17 00:00:00 2001 From: li_junsong Date: Mon, 28 Oct 2024 20:34:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Ehicollie=E7=BB=B4=E6=B5=8B?= =?UTF-8?q?=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li_junsong --- bundle.json | 1 + services/ipc/stub/time_service_stub.cpp | 15 +++++++ services/timer/src/timer_manager.cpp | 4 -- time.gni | 1 + utils/BUILD.gn | 8 ++++ utils/native/include/time_xcollie.h | 43 +++++++++++++++++++ utils/native/src/time_xcollie.cpp | 56 +++++++++++++++++++++++++ 7 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 utils/native/include/time_xcollie.h create mode 100644 utils/native/src/time_xcollie.cpp diff --git a/bundle.json b/bundle.json index b9416c27..ac178053 100644 --- a/bundle.json +++ b/bundle.json @@ -37,6 +37,7 @@ "ability_runtime", "relational_store", "hilog", + "hicollie", "safwk", "c_utils", "access_token", diff --git a/services/ipc/stub/time_service_stub.cpp b/services/ipc/stub/time_service_stub.cpp index 0c90e43d..d13de3aa 100644 --- a/services/ipc/stub/time_service_stub.cpp +++ b/services/ipc/stub/time_service_stub.cpp @@ -15,6 +15,7 @@ #include "simple_timer_info.h" #include "time_common.h" +#include "time_xcollie.h" #include "time_service_stub.h" #include "ntp_update_time.h" #include "ntp_trusted_time.h" @@ -104,6 +105,7 @@ int32_t TimeServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mes int32_t TimeServiceStub::OnSetTime(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, " start."); + TimeXCollie timeXCollie("TimeService::SetTime"); int64_t time = data.ReadInt64(); auto apiVersion = data.ReadInt8(); if (apiVersion == APIVersion::API_VERSION_9) { @@ -124,6 +126,7 @@ int32_t TimeServiceStub::OnSetTime(MessageParcel &data, MessageParcel &reply) int32_t TimeServiceStub::OnSetTimeZone(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, " start."); + TimeXCollie timeXCollie("TimeService::SetTimeZone"); std::string timeZoneId = data.ReadString(); auto apiVersion = data.ReadInt8(); if (apiVersion == APIVersion::API_VERSION_9) { @@ -144,6 +147,7 @@ int32_t TimeServiceStub::OnSetTimeZone(MessageParcel &data, MessageParcel &reply int32_t TimeServiceStub::OnGetTimeZone(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, " start."); + TimeXCollie timeXCollie("TimeService::GetTimeZone"); std::string timeZoneId; int32_t ret = GetTimeZone(timeZoneId); if (ret != ERR_OK) { @@ -158,6 +162,7 @@ int32_t TimeServiceStub::OnGetTimeZone(MessageParcel &data, MessageParcel &reply int32_t TimeServiceStub::OnGetThreadTimeMs(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, " start."); + TimeXCollie timeXCollie("TimeService::GetThreadTimeMs"); int64_t time; int32_t ret = GetThreadTimeMs(time); if (ret != ERR_OK) { @@ -172,6 +177,7 @@ int32_t TimeServiceStub::OnGetThreadTimeMs(MessageParcel &data, MessageParcel &r int32_t TimeServiceStub::OnGetThreadTimeNs(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, " start."); + TimeXCollie timeXCollie("TimeService::GetThreadTimeNs"); int64_t time; int32_t ret = GetThreadTimeNs(time); if (ret != ERR_OK) { @@ -186,6 +192,7 @@ int32_t TimeServiceStub::OnGetThreadTimeNs(MessageParcel &data, MessageParcel &r int32_t TimeServiceStub::OnCreateTimer(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, "start."); + TimeXCollie timeXCollie("TimeService::CreateTimer"); if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); return E_TIME_NOT_SYSTEM_APP; @@ -231,6 +238,7 @@ int32_t TimeServiceStub::OnCreateTimer(MessageParcel &data, MessageParcel &reply int32_t TimeServiceStub::OnStartTimer(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, "start."); + TimeXCollie timeXCollie("TimeService::StartTimer"); if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); return E_TIME_NOT_SYSTEM_APP; @@ -248,6 +256,7 @@ int32_t TimeServiceStub::OnStartTimer(MessageParcel &data, MessageParcel &reply) int32_t TimeServiceStub::OnStopTimer(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, "start."); + TimeXCollie timeXCollie("TimeService::StopTimer"); if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); return E_TIME_NOT_SYSTEM_APP; @@ -264,6 +273,7 @@ int32_t TimeServiceStub::OnStopTimer(MessageParcel &data, MessageParcel &reply) int32_t TimeServiceStub::OnDestroyTimer(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, "start."); + TimeXCollie timeXCollie("TimeService::DestroyTimer"); if (!TimePermission::CheckSystemUidCallingPermission(IPCSkeleton::GetCallingFullTokenID())) { TIME_HILOGE(TIME_MODULE_SERVICE, "not system applications"); return E_TIME_NOT_SYSTEM_APP; @@ -280,6 +290,7 @@ int32_t TimeServiceStub::OnDestroyTimer(MessageParcel &data, MessageParcel &repl int32_t TimeServiceStub::OnTimerProxy(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, "start."); + TimeXCollie timeXCollie("TimeService::TimerProxy"); auto uid = data.ReadInt32(); if (uid == 0) { TIME_HILOGE(TIME_MODULE_SERVICE, "Error param uid."); @@ -296,6 +307,7 @@ int32_t TimeServiceStub::OnTimerProxy(MessageParcel &data, MessageParcel &reply) int32_t TimeServiceStub::OnPidTimerProxy(MessageParcel &data, MessageParcel &reply) { + TimeXCollie timeXCollie("TimeService::PidTimerProxy"); auto pidListSize = data.ReadInt32(); std::set pidList; if (pidListSize == 0 || pidListSize > MAX_PID_LIST_SIZE) { @@ -323,6 +335,7 @@ int32_t TimeServiceStub::OnPidTimerProxy(MessageParcel &data, MessageParcel &rep int32_t TimeServiceStub::OnAdjustTimer(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, "on timer adjust start."); + TimeXCollie timeXCollie("TimeService::AdjustTimer"); if (!TimePermission::CheckProxyCallingPermission()) { TIME_HILOGE(TIME_MODULE_SERVICE, "Adjust Timer permission check failed"); return E_TIME_NO_PERMISSION; @@ -350,6 +363,7 @@ int32_t TimeServiceStub::OnAdjustTimer(MessageParcel &data, MessageParcel &reply int32_t TimeServiceStub::OnSetTimerExemption(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, "set timer exemption start."); + TimeXCollie timeXCollie("TimeService::SetTimerExemption"); if (!TimePermission::CheckProxyCallingPermission()) { TIME_HILOGE(TIME_MODULE_SERVICE, "Set Timer Exemption permission check failed"); return E_TIME_NO_PERMISSION; @@ -382,6 +396,7 @@ int32_t TimeServiceStub::OnSetTimerExemption(MessageParcel &data, MessageParcel int32_t TimeServiceStub::OnAllProxyReset(MessageParcel &data, MessageParcel &reply) { TIME_HILOGD(TIME_MODULE_SERVICE, "start."); + TimeXCollie timeXCollie("TimeService::AllProxyReset"); if (!ResetAllProxy()) { return E_TIME_DEAL_FAILED; } diff --git a/services/timer/src/timer_manager.cpp b/services/timer/src/timer_manager.cpp index 1be82cd2..ccbf1e2b 100644 --- a/services/timer/src/timer_manager.cpp +++ b/services/timer/src/timer_manager.cpp @@ -270,7 +270,6 @@ int32_t TimerManager::StopTimerInner(uint64_t timerNumber, bool needDestroy) needRecoverOnReboot = CheckNeedRecoverOnReboot(it->second->bundleName, it->second->type); if (needDestroy) { timerEntryMap_.erase(it); } } - TIME_HILOGI(TIME_MODULE_SERVICE, "db bgn"); if (needRecoverOnReboot) { OHOS::NativeRdb::ValuesBucket values; values.PutInt("state", 0); @@ -280,7 +279,6 @@ int32_t TimerManager::StopTimerInner(uint64_t timerNumber, bool needDestroy) if (needDestroy) { OHOS::NativeRdb::RdbPredicates rdbPredicatesDelete(HOLD_ON_REBOOT); rdbPredicatesDelete.EqualTo("timerId", static_cast(timerNumber)); - TIME_HILOGI(TIME_MODULE_SERVICE, "db del"); TimeDatabase::GetInstance().Delete(rdbPredicatesDelete); } } else { @@ -292,11 +290,9 @@ int32_t TimerManager::StopTimerInner(uint64_t timerNumber, bool needDestroy) if (needDestroy) { OHOS::NativeRdb::RdbPredicates rdbPredicatesDelete(DROP_ON_REBOOT); rdbPredicatesDelete.EqualTo("timerId", static_cast(timerNumber)); - TIME_HILOGI(TIME_MODULE_SERVICE, "db del"); TimeDatabase::GetInstance().Delete(rdbPredicatesDelete); } } - TIME_HILOGI(TIME_MODULE_SERVICE, "db end"); return E_TIME_OK; } diff --git a/time.gni b/time.gni index dbb8a953..509f66c9 100755 --- a/time.gni +++ b/time.gni @@ -26,6 +26,7 @@ time_sanitize_debug = false declare_args() { device_standby = true + time_hicollie_able = true if (defined(global_parts_info) && !defined(global_parts_info.resourceschedule_device_standby)) { device_standby = false diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 98df5e79..f262a277 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -28,6 +28,7 @@ ohos_source_set("time_utils") { sources = [ "${time_service_path}/time_permission.cpp", "${time_utils_path}/native/src/time_file_utils.cpp", + "${time_utils_path}/native/src/time_xcollie.cpp", ] deps = [] @@ -40,6 +41,13 @@ ohos_source_set("time_utils") { "init:libbegetutil", "ipc:ipc_single", ] + defines = [] + + if (time_hicollie_able) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + branch_protector_ret = "pac_ret" sanitize = { integer_overflow = true diff --git a/utils/native/include/time_xcollie.h b/utils/native/include/time_xcollie.h new file mode 100644 index 00000000..0a781ec0 --- /dev/null +++ b/utils/native/include/time_xcollie.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021 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 TIME_XCOLLIE_H +#define TIME_XCOLLIE_H + +#include + +namespace OHOS { +namespace MiscServices { + +constexpr int TIME_OUT_SECONDS = 5; +constexpr int XCOLLIE_FLAG_LOG = 3; + +class TimeXCollie { +public: + TimeXCollie(const std::string &name, uint32_t timeoutSeconds = TIME_OUT_SECONDS, + std::function func = nullptr, void *arg = nullptr, uint32_t flag = XCOLLIE_FLAG_LOG); + + ~TimeXCollie(); + + void CancelTimeXCollie(); + +private: + int32_t id_; + std::string name_; + bool isCanceled_; +}; +} +} +#endif // TIME_XCOLLIE_H diff --git a/utils/native/src/time_xcollie.cpp b/utils/native/src/time_xcollie.cpp new file mode 100644 index 00000000..2f6536b6 --- /dev/null +++ b/utils/native/src/time_xcollie.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2021 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 "time_xcollie.h" + +#include "time_hilog.h" + +#ifdef HICOLLIE_ENABLE +#include "xcollie/xcollie.h" +#endif + +namespace OHOS { +namespace MiscServices { +TimeXCollie::TimeXCollie(const std::string &name, uint32_t timeoutSeconds, + std::function func, void *arg, uint32_t flag) +{ + name_ = name; +#ifdef HICOLLIE_ENABLE + id_ = HiviewDFX::XCollie::GetInstance().SetTimer(name_, timeoutSeconds, func, arg, flag); +#else + id_ = -1; +#endif + isCanceled_ = false; + TIME_HILOGD(TIME_MODULE_SERVICE, "start TimeXCollie, name:%{public}s,timeout:%{public}u,flag:%{public}u," + "id:%{public}d", name_.c_str(), timeoutSeconds, flag, id_); +} + +TimeXCollie::~TimeXCollie() +{ + CancelTimeXCollie(); +} + +void TimeXCollie::CancelTimeXCollie() +{ + if (!isCanceled_) { +#ifdef HICOLLIE_ENABLE + HiviewDFX::XCollie::GetInstance().CancelTimer(id_); +#endif + isCanceled_ = true; + TIME_HILOGD(TIME_MODULE_SERVICE, "cancel TimeXCollie, tag:%{public}s,id:%{public}d", name_.c_str(), id_); + } +} +} +} \ No newline at end of file -- Gitee