From 58e38a7215a4184dcbf2f024da654d79d2ba4b0b Mon Sep 17 00:00:00 2001 From: yanghang Date: Fri, 9 May 2025 15:15:04 +0800 Subject: [PATCH] fix: trace for rectification Signed-off-by: yanghang --- services/native/include/power_hitrace.h | 43 ------------------- services/native/src/power_state_machine.cpp | 9 ++-- .../src/runninglock/running_lock_mgr.cpp | 6 +-- 3 files changed, 9 insertions(+), 49 deletions(-) delete mode 100644 services/native/include/power_hitrace.h diff --git a/services/native/include/power_hitrace.h b/services/native/include/power_hitrace.h deleted file mode 100644 index a43c026b..00000000 --- a/services/native/include/power_hitrace.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021-2023 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 POWERMGR_POWER_HITRACE_H -#define POWERMGR_POWER_HITRACE_H -#ifdef HAS_HIVIEWDFX_HITRACE_PART -#include "hitrace_meter.h" -#endif -namespace OHOS { -namespace PowerMgr { -class PowerHitrace { -public: - explicit PowerHitrace(const std::string& trace) : trace_(trace) - { -#ifdef HAS_HIVIEWDFX_HITRACE_PART - StartTrace(HITRACE_TAG_POWER, trace_.c_str()); -#endif - } - - ~PowerHitrace() - { -#ifdef HAS_HIVIEWDFX_HITRACE_PART - FinishTrace(HITRACE_TAG_POWER); -#endif - } -private: - std::string trace_; -}; -} // namespace PowerMgr -} // namespace OHOS -#endif // POWERMGR_POWER_HITRACE__H \ No newline at end of file diff --git a/services/native/src/power_state_machine.cpp b/services/native/src/power_state_machine.cpp index d7db9d19..bae4873e 100644 --- a/services/native/src/power_state_machine.cpp +++ b/services/native/src/power_state_machine.cpp @@ -26,7 +26,7 @@ #include #include "power_ext_intf_wrapper.h" #ifdef HAS_HIVIEWDFX_HITRACE_PART -#include "power_hitrace.h" +#include "hitrace_meter.h" #endif #include "power_mode_policy.h" #include "power_mgr_factory.h" @@ -481,7 +481,7 @@ void PowerStateMachine::SuspendDeviceInner( pid_t pid, int64_t callTimeMs, SuspendDeviceType type, bool suspendImmed, bool ignoreScreenState) { #ifdef HAS_HIVIEWDFX_HITRACE_PART - PowerHitrace powerHitrace("SuspendDevice"); + HitraceScopedEx powerHitrace(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_POWER, "SuspendDevice"); #endif if (type > SuspendDeviceType::SUSPEND_DEVICE_REASON_MAX) { POWER_HILOGW(FEATURE_SUSPEND, "Invalid type: %{public}d", type); @@ -637,7 +637,7 @@ void PowerStateMachine::WakeupDeviceInner( pid_t pid, int64_t callTimeMs, WakeupDeviceType type, const std::string& details, const std::string& pkgName) { #ifdef HAS_HIVIEWDFX_HITRACE_PART - PowerHitrace powerHitrace("WakeupDevice"); + HitraceScopedEx powerHitrace(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_POWER, "WakeupDevice"); #endif if (type > WakeupDeviceType::WAKEUP_DEVICE_MAX) { POWER_HILOGW(FEATURE_WAKEUP, "Invalid type: %{public}d", type); @@ -1136,6 +1136,9 @@ void PowerStateMachine::NotifyPowerStateChanged(PowerState state, StateChangeRea for (auto& listener : asyncPowerStateListeners_) { listener->OnAsyncPowerStateChanged(state); } +#ifdef HAS_HIVIEWDFX_HITRACE_PART + HitraceScopedEx powerHitrace(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_POWER, "StateListener"); +#endif for (auto& listener : syncPowerStateListeners_) { listener->OnPowerStateChanged(state); } diff --git a/services/native/src/runninglock/running_lock_mgr.cpp b/services/native/src/runninglock/running_lock_mgr.cpp index 1c4abac3..dc148151 100644 --- a/services/native/src/runninglock/running_lock_mgr.cpp +++ b/services/native/src/runninglock/running_lock_mgr.cpp @@ -23,7 +23,7 @@ #include #include #ifdef HAS_HIVIEWDFX_HITRACE_PART -#include "power_hitrace.h" +#include "hitrace_meter.h" #endif #include "ffrt_utils.h" #include "power_log.h" @@ -447,7 +447,7 @@ bool RunningLockMgr::UpdateWorkSource(const sptr& remoteObj, bool RunningLockMgr::Lock(const sptr& remoteObj) { #ifdef HAS_HIVIEWDFX_HITRACE_PART - PowerHitrace powerHitrace("RunningLock_Lock"); + HitraceScopedEx powerHitrace(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_POWER, "RunningLock_Lock"); #endif auto lockInner = GetRunningLockInner(remoteObj); if (lockInner == nullptr) { @@ -495,7 +495,7 @@ bool RunningLockMgr::Lock(const sptr& remoteObj) bool RunningLockMgr::UnLock(const sptr remoteObj, const std::string& name) { #ifdef HAS_HIVIEWDFX_HITRACE_PART - PowerHitrace powerHitrace("RunningLock_Unlock"); + HitraceScopedEx powerHitrace(HITRACE_LEVEL_COMMERCIAL, HITRACE_TAG_POWER, "RunningLock_Unlock"); #endif auto lockInner = GetRunningLockInner(remoteObj); if (lockInner == nullptr) { -- Gitee