!961 订阅流程增加耗时打印

Merge pull request !961 from Mark_Yao/yzy_dev_0525
This commit is contained in:
openharmony_ci 2024-05-25 10:31:53 +00:00 committed by Gitee
commit c7a803d475
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 15 additions and 6 deletions

View File

@ -72,7 +72,7 @@ public:
EXPORT bool SubscribeCommonEvent(const CommonEventSubscribeInfo &subscribeInfo,
const sptr<IRemoteObject> &commonEventListener, const struct tm &recordTime, const pid_t &pid, const uid_t &uid,
const Security::AccessToken::AccessTokenID &callerToken, const std::string &bundleName,
const int32_t instanceKey = 0);
const int32_t instanceKey = 0, const int64_t startTime = 0);
/**
* Unsubscribes from common events.

View File

@ -30,6 +30,7 @@
#include "system_ability_definition.h"
#include "xcollie/watchdog.h"
#include "ces_inner_error_code.h"
#include "system_time.h"
#include <mutex>
#include <new>
@ -235,6 +236,7 @@ int32_t CommonEventManagerService::SubscribeCommonEvent(const CommonEventSubscri
std::string bundleName = DelayedSingleton<BundleManagerHelper>::GetInstance()->GetBundleName(callingUid);
Security::AccessToken::AccessTokenID callerToken = IPCSkeleton::GetCallingTokenID();
std::weak_ptr<InnerCommonEventManager> wp = innerCommonEventManager_;
int64_t startTime = SystemTime::GetNowSysTime();
std::function<void()> subscribeCommonEventFunc = [wp,
subscribeInfo,
commonEventListener,
@ -243,7 +245,8 @@ int32_t CommonEventManagerService::SubscribeCommonEvent(const CommonEventSubscri
callingUid,
callerToken,
bundleName,
instanceKey] () {
instanceKey,
startTime] () {
std::shared_ptr<InnerCommonEventManager> innerCommonEventManager = wp.lock();
if (innerCommonEventManager == nullptr) {
EVENT_LOGE("innerCommonEventManager not exist");
@ -256,7 +259,8 @@ int32_t CommonEventManagerService::SubscribeCommonEvent(const CommonEventSubscri
callingUid,
callerToken,
bundleName,
instanceKey);
instanceKey,
startTime);
if (!ret) {
EVENT_LOGE("failed to subscribe event");
}

View File

@ -161,9 +161,10 @@ bool InnerCommonEventManager::PublishCommonEvent(const CommonEventData &data, co
bool InnerCommonEventManager::SubscribeCommonEvent(const CommonEventSubscribeInfo &subscribeInfo,
const sptr<IRemoteObject> &commonEventListener, const struct tm &recordTime,
const pid_t &pid, const uid_t &uid, const Security::AccessToken::AccessTokenID &callerToken,
const std::string &bundleName, const int32_t instanceKey)
const std::string &bundleName, const int32_t instanceKey, const int64_t startTime)
{
HITRACE_METER_NAME(HITRACE_TAG_NOTIFICATION, __PRETTY_FUNCTION__);
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());
@ -203,8 +204,10 @@ bool InnerCommonEventManager::SubscribeCommonEvent(const CommonEventSubscribeInf
subCount.fetch_add(1);
eventRecordInfo.subId = subId;
EVENT_LOGI("SubscribeCommonEvent %{public}s(pid = %{public}d, uid = %{public}d, "
"userId = %{public}d, instanceKey = %{public}d, subId = %{public}s)",
bundleName.c_str(), pid, uid, subscribeInfo.GetUserId(), instanceKey, subId.c_str());
"userId = %{public}d, instanceKey = %{public}d, subId = %{public}s, "
"ffrtCost = %{public}s, taskCost = %{public}s",
bundleName.c_str(), pid, uid, subscribeInfo.GetUserId(), instanceKey, subId.c_str(),
std::to_string(taskStartTime - startTime).c_str(), std::to_string(now - taskStartTime).c_str());
auto record = DelayedSingleton<CommonEventSubscriberManager>::GetInstance()->InsertSubscriber(
sp, commonEventListener, recordTime, eventRecordInfo);

View File

@ -349,6 +349,7 @@ bool CommonEventDumpTest::SubscribeCommonEvent(const std::shared_ptr<CommonEvent
callingUid,
tokenID,
bundleName,
0,
0);
return handler_->PostTask(SubscribeCommonEventFunc);
}

View File

@ -300,6 +300,7 @@ bool CommonEventFreezeTest::SubscribeCommonEvent(const std::shared_ptr<CommonEve
callingUid,
tokenID,
bundleName,
0,
0);
return handler_->PostTask(SubscribeCommonEventFunc);
}