From 3a6e0d6e7485839217aec33456c728794bab3c01 Mon Sep 17 00:00:00 2001 From: gongguilin Date: Sun, 13 Apr 2025 13:23:23 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gongguilin --- interfaces/innerkits/common/BUILD.gn | 1 + services/dfx/include/hisysevent_adapter.h | 2 +- services/dfx/source/hisysevent_adapter.cpp | 13 +++++-------- services/samgr/native/BUILD.gn | 1 + .../native/source/collect/ref_count_collect.cpp | 9 ++++++++- services/samgr/native/test/unittest/BUILD.gn | 10 ++++++++++ test/fuzztest/samgr_fuzzer/BUILD.gn | 1 + test/fuzztest/samgrcoverage_fuzzer/BUILD.gn | 1 + test/fuzztest/samgrdumper_fuzzer/BUILD.gn | 1 + test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn | 1 + 10 files changed, 30 insertions(+), 10 deletions(-) diff --git a/interfaces/innerkits/common/BUILD.gn b/interfaces/innerkits/common/BUILD.gn index 639f675d..71e1bae5 100644 --- a/interfaces/innerkits/common/BUILD.gn +++ b/interfaces/innerkits/common/BUILD.gn @@ -72,6 +72,7 @@ ohos_shared_library("samgr_common") { "c_utils:utils", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", ] diff --git a/services/dfx/include/hisysevent_adapter.h b/services/dfx/include/hisysevent_adapter.h index e8a71392..700fa59a 100644 --- a/services/dfx/include/hisysevent_adapter.h +++ b/services/dfx/include/hisysevent_adapter.h @@ -49,6 +49,6 @@ void ReportProcessStartDuration(const std::string& processName, int32_t pid, int void ReportProcessStopDuration(const std::string& processName, int32_t pid, int32_t uid, int64_t duration); -void ReportSAIdle(int32_t said, const std::string& reason); +void ReportSAIdle(const char* reason); } // OHOS #endif // SAMGR_SERVICES_DFX_INCLUDE__HISYSEVENT_ADAPTER_H diff --git a/services/dfx/source/hisysevent_adapter.cpp b/services/dfx/source/hisysevent_adapter.cpp index 6bb315b4..949cbcbc 100644 --- a/services/dfx/source/hisysevent_adapter.cpp +++ b/services/dfx/source/hisysevent_adapter.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ #include "hisysevent_adapter.h" +#include "hisysevent_easy.h" #include @@ -293,15 +294,11 @@ void WatchDogSendEvent(int32_t pid, uint32_t uid, const std::string& sendMsg, } } -void ReportSAIdle(int32_t said, const std::string& reason) +void ReportSAIdle(const char* reason) { - int ret = HiSysEventWrite(HiSysEvent::Domain::SAMGR, + HiSysEventEasyWrite(HiSysEvent::Domain::SAMGR, SA_IDLE, - HiSysEvent::EventType::BEHAVIOR, - SAID, said, - REASON, reason); - if (ret != 0) { - HILOGE("hisysevent report sa idle failed! ret %{public}d.", ret); - } + HiSysEventEasyType::EASY_EVENT_TYPE_BEHAVIOR, + reason); } } // OHOS diff --git a/services/samgr/native/BUILD.gn b/services/samgr/native/BUILD.gn index 34cccf36..9df0fad0 100644 --- a/services/samgr/native/BUILD.gn +++ b/services/samgr/native/BUILD.gn @@ -100,6 +100,7 @@ ohos_executable("samgr") { "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", diff --git a/services/samgr/native/source/collect/ref_count_collect.cpp b/services/samgr/native/source/collect/ref_count_collect.cpp index bafb0e61..2062fbbf 100644 --- a/services/samgr/native/source/collect/ref_count_collect.cpp +++ b/services/samgr/native/source/collect/ref_count_collect.cpp @@ -14,6 +14,7 @@ */ #include "ref_count_collect.h" +#include namespace OHOS { namespace { @@ -116,7 +117,13 @@ void RefCountCollect::IdentifyUnrefResident() uint32_t refCount = saProxy->GetStrongRefCountForStub(); HILOGD("resident SA:%{public}d, ref count:%{public}u", saId, refCount); if (refCount == 1) { - ReportSAIdle(saId, "ref count 1"); + char reason[128] = {0}; + errno_t res = snprintf_s(reason, sizeof(reason), sizeof(reason) - 1, "saId:%d REASON:ref count 1", saId); + if (res < 0) { + HILOGE("SA:%{public}d report SA_IDLE snprintf_s error:%{public}d", saId, res); + continue; + } + ReportSAIdle(reason); HILOGI("resident SA:%{public}d, ref count:1", saId); } } diff --git a/services/samgr/native/test/unittest/BUILD.gn b/services/samgr/native/test/unittest/BUILD.gn index 3b0a2f5c..d011cbeb 100644 --- a/services/samgr/native/test/unittest/BUILD.gn +++ b/services/samgr/native/test/unittest/BUILD.gn @@ -108,6 +108,7 @@ ohos_unittest("SystemAbilityMgrTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", @@ -225,6 +226,7 @@ ohos_unittest("SystemAbilityMgrCollectTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", @@ -352,6 +354,7 @@ ohos_unittest("SystemAbilityMgrDeviceNetworkingTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", @@ -451,6 +454,7 @@ ohos_unittest("SystemAbilityMgrStubTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", @@ -536,6 +540,7 @@ ohos_unittest("SystemAbilityMgrProxyTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "init:libbegetutil", "ipc:ipc_single", "json:nlohmann_json_static", @@ -578,6 +583,7 @@ ohos_unittest("LocalAbilityManagerProxyTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "ipc:ipc_single", "json:nlohmann_json_static", ] @@ -648,6 +654,7 @@ ohos_unittest("SystemAbilityStateSchedulerTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", @@ -724,6 +731,7 @@ ohos_unittest("SystemAbilityMgrDumperTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", @@ -777,6 +785,7 @@ ohos_unittest("MockSystemAbilityManagerTest") { "googletest:gtest_main", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", @@ -982,6 +991,7 @@ ohos_executable("TestTool") { "eventhandler:libeventhandler", "ffrt:libffrt", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", diff --git a/test/fuzztest/samgr_fuzzer/BUILD.gn b/test/fuzztest/samgr_fuzzer/BUILD.gn index 62412f66..4cf56105 100644 --- a/test/fuzztest/samgr_fuzzer/BUILD.gn +++ b/test/fuzztest/samgr_fuzzer/BUILD.gn @@ -176,6 +176,7 @@ foreach(item, samgr_fuzztests) { "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", diff --git a/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn b/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn index 328c79b6..643f88e2 100644 --- a/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn +++ b/test/fuzztest/samgrcoverage_fuzzer/BUILD.gn @@ -79,6 +79,7 @@ ohos_fuzztest("SamgrCoverageFuzzTest") { "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", diff --git a/test/fuzztest/samgrdumper_fuzzer/BUILD.gn b/test/fuzztest/samgrdumper_fuzzer/BUILD.gn index d644470c..ae895240 100644 --- a/test/fuzztest/samgrdumper_fuzzer/BUILD.gn +++ b/test/fuzztest/samgrdumper_fuzzer/BUILD.gn @@ -78,6 +78,7 @@ ohos_fuzztest("SamgrDumperFuzzTest") { "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", diff --git a/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn b/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn index bd0e4c07..1e08f795 100644 --- a/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn +++ b/test/fuzztest/systemabilitymanager_fuzzer/BUILD.gn @@ -78,6 +78,7 @@ ohos_fuzztest("SystemAbilityManagerFuzzTest") { "ffrt:libffrt", "hilog:libhilog", "hisysevent:libhisysevent", + "hisysevent:libhisysevent_easy", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", -- Gitee