From 38ddd0a684dca6a055535190101e7cd52329d536 Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Tue, 22 Oct 2024 20:00:07 +0800 Subject: [PATCH] add exit reason when process exit Signed-off-by: sunjiakun --- hisysevent.yaml | 1 + services/appmgr/src/app_mgr_service_inner.cpp | 1 + services/common/include/event_report.h | 1 + services/common/src/event_report.cpp | 4 +++- .../event_report_test/event_report_test.cpp | 14 ++++++++++++++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/hisysevent.yaml b/hisysevent.yaml index 02865083ea..f9e5652e77 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -325,6 +325,7 @@ PROCESS_EXIT: EXIT_PID: {type: INT32, desc: pid} PROCESS_NAME: {type: STRING, desc: process name} EXTENSION_TYPE: {type: INT32, desc: process exit extension type} + EXIT_REASON: {type: INT32, desc: process exit reason} PROCESS_START_FAILED: __BASE: {type: FAULT, level: CRITICAL, tag: app, desc: process start failed, preserve: true} diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 5c57ddaccf..9edec684ad 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -1524,6 +1524,7 @@ void AppMgrServiceInner::SendProcessExitEventTask( eventInfo.pid = pid; eventInfo.processName = appRecord->GetProcessName(); eventInfo.extensionType = static_cast(appRecord->GetExtensionType()); + eventInfo.exitReason = appRecord->GetExitReason(); if (exitResult) { eventInfo.exitResult = EXIT_SUCESS; diff --git a/services/common/include/event_report.h b/services/common/include/event_report.h index b8b68f7d03..fb6056c8c2 100644 --- a/services/common/include/event_report.h +++ b/services/common/include/event_report.h @@ -55,6 +55,7 @@ struct EventInfo { int64_t duration = 0; int32_t reason = -1; int32_t subReason = -1; + int32_t exitReason = -1; }; enum class EventName { diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index e5ead262d1..31c0abe6f5 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -43,6 +43,7 @@ constexpr const char *EVENT_KEY_CALLER_PROCESS_ID = "CALLER_PROCESS_ID"; constexpr const char *EVENT_KEY_EXIT_TIME = "EXIT_TIME"; constexpr const char *EVENT_KEY_EXIT_RESULT = "EXIT_RESULT"; constexpr const char *EVENT_KEY_EXIT_PID = "EXIT_PID"; +constexpr const char *EVENT_KEY_EXIT_REASON = "EXIT_REASON"; constexpr const char *EVENT_KEY_BUNDLE_TYPE = "BUNDLE_TYPE"; constexpr const char *EVENT_KEY_START_TYPE = "START_TYPE"; constexpr const char *EVENT_KEY_CALLER_STATE = "CALLER_STATE"; @@ -555,7 +556,8 @@ void EventReport::SendProcessExitEvent(const EventName &eventName, const EventIn EVENT_KEY_EXIT_RESULT, eventInfo.exitResult, EVENT_KEY_EXIT_PID, eventInfo.pid, EVENT_KEY_PROCESS_NAME, eventInfo.processName, - EVENT_KEY_EXTENSION_TYPE, eventInfo.extensionType); + EVENT_KEY_EXTENSION_TYPE, eventInfo.extensionType, + EVENT_KEY_EXIT_REASON, eventInfo.exitReason); } void EventReport::SendStartServiceEvent(const EventName &eventName, const EventInfo &eventInfo) diff --git a/test/unittest/event_report_test/event_report_test.cpp b/test/unittest/event_report_test/event_report_test.cpp index 17f310a356..83234660f2 100755 --- a/test/unittest/event_report_test/event_report_test.cpp +++ b/test/unittest/event_report_test/event_report_test.cpp @@ -613,6 +613,20 @@ HWTEST_F(EventReportTest, SendProcessExitEvent_0100, TestSize.Level0) EventReport::SendProcessExitEvent(eventName, eventInfo); } +/** + * @tc.name: SendProcessExitEvent_0200 + * @tc.desc: Check SendProcessExitEvent Test + * @tc.type: FUNC + */ +HWTEST_F(EventReportTest, SendProcessExitEvent_0200, TestSize.Level1) +{ + EventInfo eventInfo; + EventName eventName = EventName::PROCESS_EXIT; + eventInfo.exitReason = 0; + EventReport::SendProcessExitEvent(eventName, eventInfo); + EXPECT_EQ(EventReport::ConvertEventName(eventName), "PROCESS_EXIT"); +} + /** * @tc.name: SendStartServiceEvent_0100 * @tc.desc: Check SendStartServiceEvent Test