From 46721b41bec4407334d40dc1338a7997423f5d9f Mon Sep 17 00:00:00 2001 From: chenbingbing Date: Thu, 2 Jan 2025 20:13:16 +0800 Subject: [PATCH] samgr hisysevent tunning Signed-off-by: chenbingbing --- services/common/src/parse_util.cpp | 3 +- services/dfx/source/hisysevent_adapter.cpp | 36 +++++++++++++++++++ .../system_ability_state_scheduler.cpp | 5 +-- .../native/source/system_ability_manager.cpp | 8 ++--- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/services/common/src/parse_util.cpp b/services/common/src/parse_util.cpp index 7e14c499..2f27ea39 100644 --- a/services/common/src/parse_util.cpp +++ b/services/common/src/parse_util.cpp @@ -157,7 +157,6 @@ void ParseUtil::OpenSo(SaProfile& saProfile) handle = dlopen(saProfile.libPath.c_str(), RTLD_NOW); } int64_t duration = GetTickCount() - begin; - ReportSaLoadDuration(saProfile.saId, SA_LOAD_OPENSO, duration); KHILOGI("SA:%{public}d OpenSo %{public}" PRId64 "ms", saProfile.saId, duration); if (handle == nullptr) { @@ -171,6 +170,8 @@ void ParseUtil::OpenSo(SaProfile& saProfile) HILOGE("SA:%{public}d dlopen %{public}s failed with errno:%{public}s!", saProfile.saId, fileName.c_str(), dlerror()); return; + } else { + ReportSaLoadDuration(saProfile.saId, SA_LOAD_OPENSO, duration); } saProfile.handle = handle; } else { diff --git a/services/dfx/source/hisysevent_adapter.cpp b/services/dfx/source/hisysevent_adapter.cpp index d79b180b..d237711f 100644 --- a/services/dfx/source/hisysevent_adapter.cpp +++ b/services/dfx/source/hisysevent_adapter.cpp @@ -56,8 +56,23 @@ constexpr const char* DURATION = "DURATION"; constexpr const char* KEY_STAGE = "KEY_STAGE"; } +static bool IsInCrashWhiteList(int32_t saId) +{ + std::vector whiteList = { 1205 }; + for (auto sa : whiteList) { + if (saId == sa) { + return true; + } + } + return false; +} + void ReportSaCrash(int32_t saId) { + if (IsInCrashWhiteList(saId)) { + HILOGD("report SA:%{public}d is in crash whitelist.", saId); + return; + } int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR, SA_CRASH, HiSysEvent::EventType::FAULT, @@ -83,6 +98,9 @@ void ReportSaUnLoadFail(int32_t saId, int32_t pid, int32_t uid, const std::strin static void ReportSaDuration(const std::string& eventName, int32_t saId, int32_t keyStage, int64_t duration) { + if (duration <= 0) { + return; + } int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR, eventName, HiSysEvent::EventType::BEHAVIOR, @@ -119,6 +137,9 @@ void ReportSaUnLoadDuration(int32_t saId, int32_t keyStage, int64_t duration) static void ReportProcessDuration(const std::string& eventName, const std::string& processName, int32_t pid, int32_t uid, int64_t duration) { + if (duration <= 0) { + return; + } int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR, eventName, HiSysEvent::EventType::BEHAVIOR, @@ -210,8 +231,23 @@ void ReportSamgrSaUnload(int32_t said, int32_t pid, int32_t uid, int32_t eventId } } +static bool IsOpenSoWhiteList(int32_t saId) +{ + std::vector whiteList = { 4606 }; + for (auto sa : whiteList) { + if (saId == sa) { + return true; + } + } + return false; +} + void ReportAddSystemAbilityFailed(int32_t said, int32_t pid, int32_t uid, const std::string& filaName) { + if (IsOpenSoWhiteList(said)) { + HILOGD("report SA:%{public}d is open so whitelist.", said); + return; + } int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR, ADD_SYSTEMABILITY_FAIL, HiSysEvent::EventType::FAULT, diff --git a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp index 8600e9c1..2815ec4c 100644 --- a/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp +++ b/services/samgr/native/source/schedule/system_ability_state_scheduler.cpp @@ -832,9 +832,10 @@ int32_t SystemAbilityStateScheduler::KillSystemProcessLocked( if (result != 0) { ReportProcessStopFail(Str16ToStr8(processContext->processName), processContext->pid, processContext->uid, "err:" + ToString(result)); + } else { + ReportProcessStopDuration(Str16ToStr8(processContext->processName), processContext->pid, + processContext->uid, duration); } - ReportProcessStopDuration(Str16ToStr8(processContext->processName), processContext->pid, - processContext->uid, duration); KHILOGI("Scheduler proc:%{public}s kill pid:%{public}d,%{public}d_%{public}d_" "%{public}" PRId64 "ms", Str16ToStr8(processContext->processName).c_str(), processContext->pid, processContext->uid, result, duration); diff --git a/services/samgr/native/source/system_ability_manager.cpp b/services/samgr/native/source/system_ability_manager.cpp index 6f00bb54..52d4ea28 100644 --- a/services/samgr/native/source/system_ability_manager.cpp +++ b/services/samgr/native/source/system_ability_manager.cpp @@ -317,7 +317,7 @@ void SystemAbilityManager::InitSaProfile() onDemandSaIdsSet_.insert(saInfo.saId); } } - HILOGI("InitProfile spend %{public}" PRId64 "ms", GetTickCount() - begin); + KHILOGI("InitProfile spend %{public}" PRId64 "ms", GetTickCount() - begin); } void SystemAbilityManager::OndemandLoadForPerf() @@ -1098,12 +1098,13 @@ int32_t SystemAbilityManager::AddSystemProcess(const u16string& procName, } HILOGI("AddProc:%{public}s,%{public}zu_%{public}" PRId64 "ms%{public}s", Str16ToStr8(procName).c_str(), systemProcessMap_.size(), duration, ret ? "" : ",AddDeath fail"); + auto callingPid = IPCSkeleton::GetCallingPid(); + auto callingUid = IPCSkeleton::GetCallingUid(); + ReportProcessStartDuration(Str16ToStr8(procName), callingPid, callingUid, duration); if (abilityStateScheduler_ == nullptr) { HILOGE("abilityStateScheduler is nullptr"); return ERR_INVALID_VALUE; } - auto callingPid = IPCSkeleton::GetCallingPid(); - auto callingUid = IPCSkeleton::GetCallingUid(); ProcessInfo processInfo = {procName, callingPid, callingUid}; abilityStateScheduler_->SendProcessStateEvent(processInfo, ProcessStateEvent::PROCESS_STARTED_EVENT); return ERR_OK; @@ -1448,7 +1449,6 @@ int32_t SystemAbilityManager::StartDynamicSystemProcess(const std::u16string& na if (result != 0) { ReportProcessStartFail(Str16ToStr8(name), callingPid, callingUid, "err:" + ToString(result)); } - ReportProcessStartDuration(Str16ToStr8(name), callingPid, callingUid, duration); KHILOGI("Start dynamic proc:%{public}s,%{public}d,%{public}d_%{public}" PRId64 "ms", Str16ToStr8(name).c_str(), systemAbilityId, result, duration); return result; -- Gitee