From f0a98f5437b63753d922ad569a9164a4df459d3e Mon Sep 17 00:00:00 2001 From: zhengzhuolan Date: Wed, 11 Jun 2025 15:59:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E9=80=9A=E7=9F=A5Trace?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhengzhuolan --- frameworks/core/include/event_log_wrapper.h | 3 +++ frameworks/core/src/common_event.cpp | 15 ++++++------- frameworks/core/src/common_event_listener.cpp | 5 +++-- services/src/ability_manager_helper.cpp | 3 ++- services/src/common_event_control_manager.cpp | 21 ++++++++++--------- services/src/common_event_manager_service.cpp | 9 ++++---- .../src/common_event_subscriber_manager.cpp | 5 +++-- services/src/inner_common_event_manager.cpp | 11 +++++----- services/src/static_subscriber_manager.cpp | 6 +++--- 9 files changed, 44 insertions(+), 34 deletions(-) diff --git a/frameworks/core/include/event_log_wrapper.h b/frameworks/core/include/event_log_wrapper.h index 38c43f67..bffd938e 100644 --- a/frameworks/core/include/event_log_wrapper.h +++ b/frameworks/core/include/event_log_wrapper.h @@ -27,6 +27,9 @@ #define EVENT_LOG_LIMIT_INTERVALS 10000 //ms +#define NOTIFICATION_HITRACE(tag) \ + HITRACE_METER_NAME_EX(HiTraceOutputLevel::HITRACE_LEVEL_INFO, tag, __PRETTY_FUNCTION__, "") + #define CUR_FILE_NAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) #define EVENT_LOGF(fmt, ...) \ diff --git a/frameworks/core/src/common_event.cpp b/frameworks/core/src/common_event.cpp index 444f50a4..b7a75602 100644 --- a/frameworks/core/src/common_event.cpp +++ b/frameworks/core/src/common_event.cpp @@ -18,6 +18,7 @@ #include "common_event_death_recipient.h" #include "event_log_wrapper.h" #include "hitrace_meter_adapter.h" +#include "hitrace_meter.h" #include "icommon_event.h" #include "iservice_registry.h" #include "refbase.h" @@ -52,7 +53,7 @@ std::shared_ptr CommonEvent::GetInstance() bool CommonEvent::PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo, const std::shared_ptr &subscriber) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); sptr commonEventListener = nullptr; if (!PublishParameterCheck(data, publishInfo, subscriber, commonEventListener)) { @@ -79,7 +80,7 @@ bool CommonEvent::PublishCommonEvent(const CommonEventData &data, const CommonEv int32_t CommonEvent::PublishCommonEventAsUser(const CommonEventData &data, const CommonEventPublishInfo &publishInfo, const std::shared_ptr &subscriber, const int32_t &userId) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); sptr commonEventListener = nullptr; if (!PublishParameterCheck(data, publishInfo, subscriber, commonEventListener)) { @@ -106,7 +107,7 @@ int32_t CommonEvent::PublishCommonEventAsUser(const CommonEventData &data, const bool CommonEvent::PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo, const std::shared_ptr &subscriber, const uid_t &uid, const int32_t &callerToken) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); sptr commonEventListener = nullptr; if (!PublishParameterCheck(data, publishInfo, subscriber, commonEventListener)) { @@ -135,7 +136,7 @@ bool CommonEvent::PublishCommonEventAsUser(const CommonEventData &data, const Co const std::shared_ptr &subscriber, const uid_t &uid, const int32_t &callerToken, const int32_t &userId) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); sptr commonEventListener = nullptr; if (!PublishParameterCheck(data, publishInfo, subscriber, commonEventListener)) { @@ -188,7 +189,7 @@ __attribute__((no_sanitize("cfi"))) bool CommonEvent::PublishParameterCheck(cons __attribute__((no_sanitize("cfi"))) int32_t CommonEvent::SubscribeCommonEvent( const std::shared_ptr &subscriber) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (subscriber == nullptr) { @@ -235,7 +236,7 @@ __attribute__((no_sanitize("cfi"))) int32_t CommonEvent::SubscribeCommonEvent( __attribute__((no_sanitize("cfi"))) int32_t CommonEvent::UnSubscribeCommonEvent( const std::shared_ptr &subscriber) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (subscriber == nullptr) { @@ -274,7 +275,7 @@ __attribute__((no_sanitize("cfi"))) int32_t CommonEvent::UnSubscribeCommonEvent( __attribute__((no_sanitize("cfi"))) int32_t CommonEvent::UnSubscribeCommonEventSync( const std::shared_ptr &subscriber) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (subscriber == nullptr) { diff --git a/frameworks/core/src/common_event_listener.cpp b/frameworks/core/src/common_event_listener.cpp index 10d52fd5..1999dab2 100644 --- a/frameworks/core/src/common_event_listener.cpp +++ b/frameworks/core/src/common_event_listener.cpp @@ -16,6 +16,7 @@ #include "common_event_listener.h" #include "event_log_wrapper.h" #include "hitrace_meter_adapter.h" +#include "hitrace_meter.h" #include "ffrt.h" namespace OHOS { @@ -35,7 +36,7 @@ CommonEventListener::~CommonEventListener() ErrCode CommonEventListener::NotifyEvent(const CommonEventData &commonEventData, bool ordered, bool sticky) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); std::lock_guard lock(mutex_); @@ -130,7 +131,7 @@ bool CommonEventListener::IsReady() __attribute__((no_sanitize("cfi"))) void CommonEventListener::OnReceiveEvent( const CommonEventData &commonEventData, const bool &ordered, const bool &sticky) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter %{public}s", commonEventData.GetWant().GetAction().c_str()); int32_t code = commonEventData.GetCode(); diff --git a/services/src/ability_manager_helper.cpp b/services/src/ability_manager_helper.cpp index 3c9bc88a..58319c1d 100644 --- a/services/src/ability_manager_helper.cpp +++ b/services/src/ability_manager_helper.cpp @@ -17,6 +17,7 @@ #include "event_log_wrapper.h" #include "hitrace_meter_adapter.h" +#include "hitrace_meter.h" #include "in_process_call_wrapper.h" #include "iservice_registry.h" #include "static_subscriber_connection.h" @@ -37,7 +38,7 @@ AbilityManagerHelper::AbilityManagerHelper() int AbilityManagerHelper::ConnectAbility( const Want &want, const CommonEventData &event, const sptr &callerToken, const int32_t &userId) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGI("enter, target bundle = %{public}s", want.GetBundle().c_str()); int result = -1; diff --git a/services/src/common_event_control_manager.cpp b/services/src/common_event_control_manager.cpp index c39522dc..af413432 100644 --- a/services/src/common_event_control_manager.cpp +++ b/services/src/common_event_control_manager.cpp @@ -23,6 +23,7 @@ #include "event_log_wrapper.h" #include "event_report.h" #include "hitrace_meter_adapter.h" +#include "hitrace_meter.h" #include "ievent_receive.h" #include "system_time.h" #include "xcollie/watchdog.h" @@ -48,7 +49,7 @@ CommonEventControlManager::~CommonEventControlManager() bool CommonEventControlManager::PublishCommonEvent( const CommonEventRecord &eventRecord, const sptr &commonEventListener) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); bool ret = false; @@ -65,7 +66,7 @@ bool CommonEventControlManager::PublishCommonEvent( bool CommonEventControlManager::PublishStickyCommonEvent( const CommonEventRecord &eventRecord, const std::shared_ptr &subscriberRecord) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (!subscriberRecord) { @@ -77,7 +78,7 @@ bool CommonEventControlManager::PublishStickyCommonEvent( bool CommonEventControlManager::PublishFreezeCommonEvent(const uid_t &uid) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (!GetUnorderedEventHandler()) { @@ -90,7 +91,7 @@ bool CommonEventControlManager::PublishFreezeCommonEvent(const uid_t &uid) bool CommonEventControlManager::PublishFreezeCommonEvent(std::set pidList) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (!GetUnorderedEventHandler()) { @@ -106,7 +107,7 @@ bool CommonEventControlManager::PublishFreezeCommonEvent(std::set pidList) bool CommonEventControlManager::PublishAllFreezeCommonEvents() { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (!GetUnorderedEventHandler()) { @@ -259,7 +260,7 @@ void CommonEventControlManager::NotifyUnorderedEventLocked(std::shared_ptr &eventRecord) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); if (!eventRecord) { EVENT_LOGD("Invalid event record."); return false; @@ -278,7 +279,7 @@ bool CommonEventControlManager::NotifyUnorderedEvent(std::shared_ptr &subscriberRecord) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); bool ret = false; @@ -358,7 +359,7 @@ bool CommonEventControlManager::GetOrderedEventHandler() bool CommonEventControlManager::ProcessOrderedEvent( const CommonEventRecord &eventRecord, const sptr &commonEventListener) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); bool ret = false; @@ -451,7 +452,7 @@ bool CommonEventControlManager::ScheduleOrderedCommonEvent() bool CommonEventControlManager::NotifyOrderedEvent(std::shared_ptr &eventRecordPtr, size_t index) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter with index %{public}zu", index); if (eventRecordPtr == nullptr) { EVENT_LOGE("eventRecordPtr = nullptr"); @@ -501,7 +502,7 @@ bool CommonEventControlManager::NotifyOrderedEvent(std::shared_ptr &commonEventListener, const pid_t &pid, const uid_t &uid, const int32_t &clientToken, const int32_t &userId) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); if (AccessTokenHelper::IsDlpHap(clientToken)) { EVENT_LOGE("DLP hap not allowed to send common event"); return ERR_NOTIFICATION_CES_NOT_SA_SYSTEM_APP; @@ -237,7 +238,7 @@ int32_t CommonEventManagerService::PublishCommonEventDetailed(const CommonEventD ErrCode CommonEventManagerService::SubscribeCommonEvent(const CommonEventSubscribeInfo& subscribeInfo, const sptr& commonEventListener, int32_t instanceKey, int32_t& funcResult) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (!IsReady()) { @@ -306,7 +307,7 @@ ErrCode CommonEventManagerService::SubscribeCommonEvent(const CommonEventSubscri ErrCode CommonEventManagerService::UnsubscribeCommonEvent(const sptr& commonEventListener, int32_t& funcResult) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (!IsReady()) { @@ -336,7 +337,7 @@ ErrCode CommonEventManagerService::UnsubscribeCommonEvent(const sptr& commonEventListener, int32_t& funcResult) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (!IsReady()) { diff --git a/services/src/common_event_subscriber_manager.cpp b/services/src/common_event_subscriber_manager.cpp index c854c129..a2975201 100644 --- a/services/src/common_event_subscriber_manager.cpp +++ b/services/src/common_event_subscriber_manager.cpp @@ -25,6 +25,7 @@ #include "event_report.h" #include "hisysevent.h" #include "hitrace_meter_adapter.h" +#include "hitrace_meter.h" #include "subscriber_death_recipient.h" #ifdef WATCH_CUSTOMIZED_SCREEN_EVENT_TO_OTHER_APP #include @@ -55,7 +56,7 @@ std::shared_ptr CommonEventSubscriberManager::InsertSubsc const SubscribeInfoPtr &eventSubscribeInfo, const sptr &commonEventListener, const struct tm &recordTime, const EventRecordInfo &eventRecordInfo) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (eventSubscribeInfo == nullptr) { @@ -109,7 +110,7 @@ std::shared_ptr CommonEventSubscriberManager::InsertSubsc int CommonEventSubscriberManager::RemoveSubscriber(const sptr &commonEventListener) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (commonEventListener == nullptr) { diff --git a/services/src/inner_common_event_manager.cpp b/services/src/inner_common_event_manager.cpp index 0ccc0761..fe60a8f6 100644 --- a/services/src/inner_common_event_manager.cpp +++ b/services/src/inner_common_event_manager.cpp @@ -25,6 +25,7 @@ #include "event_log_wrapper.h" #include "event_report.h" #include "hitrace_meter_adapter.h" +#include "hitrace_meter.h" #include "ipc_skeleton.h" #include "nlohmann/json.hpp" #include "os_account_manager_helper.h" @@ -215,7 +216,7 @@ bool InnerCommonEventManager::PublishCommonEvent(const CommonEventData &data, co const Security::AccessToken::AccessTokenID &callerToken, const int32_t &userId, const std::string &bundleName, const sptr &service) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); if (data.GetWant().GetAction().empty()) { EVENT_LOGE("the commonEventdata action is null"); return false; @@ -303,7 +304,7 @@ bool InnerCommonEventManager::SubscribeCommonEvent(const CommonEventSubscribeInf const pid_t &pid, const uid_t &uid, const Security::AccessToken::AccessTokenID &callerToken, const std::string &bundleName, const int32_t instanceKey, const int64_t startTime) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); int64_t taskStartTime = SystemTime::GetNowSysTime(); EVENT_LOGD("enter %{public}s(pid = %{public}d, uid = %{public}d, userId = %{public}d)", bundleName.c_str(), pid, uid, subscribeInfo.GetUserId()); @@ -356,7 +357,7 @@ bool InnerCommonEventManager::SubscribeCommonEvent(const CommonEventSubscribeInf bool InnerCommonEventManager::UnsubscribeCommonEvent(const sptr &commonEventListener) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (commonEventListener == nullptr) { @@ -523,7 +524,7 @@ void InnerCommonEventManager::SetSystemUserId(const uid_t &uid, EventComeFrom &c bool InnerCommonEventManager::CheckUserId(const pid_t &pid, const uid_t &uid, const Security::AccessToken::AccessTokenID &callerToken, EventComeFrom &comeFrom, int32_t &userId) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (userId < UNDEFINED_USER) { @@ -558,7 +559,7 @@ bool InnerCommonEventManager::CheckUserId(const pid_t &pid, const uid_t &uid, bool InnerCommonEventManager::PublishStickyEvent( const std::shared_ptr &sp, const std::shared_ptr &subscriberRecord) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if (!sp) { diff --git a/services/src/static_subscriber_manager.cpp b/services/src/static_subscriber_manager.cpp index 1899a20f..6f8c27f7 100644 --- a/services/src/static_subscriber_manager.cpp +++ b/services/src/static_subscriber_manager.cpp @@ -29,7 +29,7 @@ #include "double_wrapper.h" #include "event_log_wrapper.h" #include "event_report.h" -#include "hitrace_meter_adapter.h" +#include "hitrace_meter.h" #include "int_wrapper.h" #include "ipc_skeleton.h" #include "os_account_manager_helper.h" @@ -262,7 +262,7 @@ void StaticSubscriberManager::PublishCommonEvent(const CommonEventData &data, const CommonEventPublishInfo &publishInfo, const Security::AccessToken::AccessTokenID &callerToken, const int32_t &userId, const sptr &service, const std::string &bundleName) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter, event = %{public}s, userId = %{public}d", data.GetWant().GetAction().c_str(), userId); std::lock_guard lock(subscriberMutex_); @@ -468,7 +468,7 @@ void StaticSubscriberManager::RemoveSubscriberWithBundleName(const std::string & void StaticSubscriberManager::UpdateSubscriber(const CommonEventData &data) { - HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__); + NOTIFICATION_HITRACE(HITRACE_TAG_NOTIFICATION); EVENT_LOGD("enter"); if ((data.GetWant().GetAction() != CommonEventSupport::COMMON_EVENT_PACKAGE_ADDED) && -- Gitee