mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-22 22:50:21 +00:00
add detailed log for debugging app unexpectedly exit issues
Signed-off-by: MapleStory <zengzhi5@huawei.com>
This commit is contained in:
parent
f58152266e
commit
5ee09f23d5
5
BUILD.gn
5
BUILD.gn
@ -103,6 +103,11 @@ ohos_static_library("appspawn_server") {
|
||||
external_deps += [ "selinux:libhap_restorecon" ]
|
||||
}
|
||||
|
||||
if (appspawn_report_event) {
|
||||
cflags = [ "-DREPORT_EVENT" ]
|
||||
deps += [ "adapter/sysevent:event_reporter" ]
|
||||
}
|
||||
|
||||
subsystem_name = "${subsystem_name}"
|
||||
part_name = "${part_name}"
|
||||
}
|
||||
|
23
adapter/sysevent/BUILD.gn
Normal file
23
adapter/sysevent/BUILD.gn
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import("//build/ohos.gni")
|
||||
config("event_reporter_config") {
|
||||
visibility = [ "*:*" ]
|
||||
include_dirs = [ "." ]
|
||||
}
|
||||
|
||||
ohos_source_set("event_reporter") {
|
||||
sources = [ "event_reporter.cpp" ]
|
||||
public_configs = [ ":event_reporter_config" ]
|
||||
external_deps = [ "hisysevent_native:libhisysevent" ]
|
||||
}
|
45
adapter/sysevent/event_reporter.cpp
Normal file
45
adapter/sysevent/event_reporter.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "event_reporter.h"
|
||||
|
||||
#include <hisysevent.h>
|
||||
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace OHOS {
|
||||
namespace system {
|
||||
constexpr char KEY_PROCESS_EXIT[] = "PROCESS_EXIT";
|
||||
constexpr char KEY_NAME[] = "PROCESS_NAME";
|
||||
constexpr char KEY_PID[] = "PID";
|
||||
constexpr char KEY_UID[] = "UID";
|
||||
constexpr char KEY_STATUS[] = "STATUS";
|
||||
constexpr int32_t MAX_NAME_LENGTH = 1024;
|
||||
void ReportProcessExitInfo(const char* processName, int pid, int uid, int status)
|
||||
{
|
||||
std::string pname = "Unknown";
|
||||
if ((processName != NULL) && (strlen(processName) <= MAX_NAME_LENGTH)) {
|
||||
pname = std::string(processName, strlen(processName));
|
||||
}
|
||||
|
||||
HiSysEvent::Write(HiSysEvent::Domain::STARTUP, KEY_PROCESS_EXIT, HiSysEvent::EventType::BEHAVIOR,
|
||||
KEY_NAME, pname, KEY_PID, pid, KEY_UID, uid, KEY_STATUS, status);
|
||||
}
|
||||
} // namespace system
|
||||
} // namespace OHOS
|
||||
|
||||
void ReportProcessExitInfo(const char* processName, int pid, int uid, int status)
|
||||
{
|
||||
OHOS::system::ReportProcessExitInfo(processName, pid, uid, status);
|
||||
}
|
31
adapter/sysevent/event_reporter.h
Normal file
31
adapter/sysevent/event_reporter.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef STARTUP_EVENT_REPORT_H
|
||||
#define STARTUP_EVENT_REPORT_H
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void ReportProcessExitInfo(const char* processName, int pid, int uid, int status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
@ -19,4 +19,5 @@ module_output_path = "${part_name}/appspawn_l2"
|
||||
|
||||
declare_args() {
|
||||
appspawn_support_nweb = true
|
||||
appspawn_report_event = true
|
||||
}
|
||||
|
@ -22,9 +22,13 @@
|
||||
],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"hisysevent_config": [
|
||||
"//base/startup/appspawn_standard/startup_events.yaml"
|
||||
],
|
||||
"deps": {
|
||||
"components": [
|
||||
"ability_base",
|
||||
"hisysevent_native",
|
||||
"hiviewdfx_hilog_native",
|
||||
"ipc",
|
||||
"safwk",
|
||||
|
@ -33,6 +33,10 @@
|
||||
#include "parameter.h"
|
||||
#include "securec.h"
|
||||
|
||||
#ifdef REPORT_EVENT
|
||||
#include "event_reporter.h"
|
||||
#endif
|
||||
|
||||
static AppSpawnContentExt *g_appSpawnContent = NULL;
|
||||
|
||||
static const int TV_SEC = 60;
|
||||
@ -131,6 +135,24 @@ static int SendResponse(AppSpawnClientExt *client, const char *buff, size_t buff
|
||||
return LE_Send(LE_GetDefaultLoop(), client->stream, handle, buffSize);
|
||||
}
|
||||
|
||||
#ifdef REPORT_EVENT
|
||||
static void PrintProcessExitInfo(pid_t pid, uid_t uid, int status)
|
||||
{
|
||||
HashNode *node = HashMapGet(g_appSpawnContent->appMap, (const void *)&pid);
|
||||
APPSPAWN_CHECK(node != NULL, return, "Handle SIGCHLD from pid:%d status:%d", pid, status);
|
||||
AppInfo *appInfo = HASHMAP_ENTRY(node, AppInfo, node);
|
||||
APPSPAWN_CHECK(appInfo != NULL, return, "Handle SIGCHLD from pid:%d status:%d", pid, status);
|
||||
if (WIFSIGNALED(status)) {
|
||||
APPSPAWN_LOGW("%s with pid %d exit with signal:%d", appInfo->name, pid, WTERMSIG(status));
|
||||
}
|
||||
if (WIFEXITED(status)) {
|
||||
APPSPAWN_LOGW("%s with pid %d exit with code:%d", appInfo->name, pid, WEXITSTATUS(status));
|
||||
}
|
||||
|
||||
ReportProcessExitInfo(appInfo->name, pid, uid, status);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void SignalHandler(const struct signalfd_siginfo *siginfo)
|
||||
{
|
||||
APPSPAWN_LOGI("SignalHandler signum %d", siginfo->ssi_signo);
|
||||
@ -142,6 +164,9 @@ static void SignalHandler(const struct signalfd_siginfo *siginfo)
|
||||
int status;
|
||||
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
|
||||
APPSPAWN_LOGI("SignalHandler pid %d status %d", pid, status);
|
||||
#ifdef REPORT_EVENT
|
||||
PrintProcessExitInfo(pid, siginfo->ssi_uid, status);
|
||||
#endif
|
||||
RemoveAppInfo(pid);
|
||||
}
|
||||
#endif
|
||||
|
21
startup_events.yaml
Normal file
21
startup_events.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
domain: STARTUP
|
||||
|
||||
PROCESS_EXIT:
|
||||
__BASE: {type: BEHAVIOR, level: CRITICAL, tag: Stability, desc: process exit reason}
|
||||
PROCESS_NAME: {type: STRING, desc: process name}
|
||||
PID: {type: UINT32, desc: process id}
|
||||
UID: {type: UINT32, desc: user id}
|
||||
STATUS: {type: INT32, desc: exit code or signal number}
|
Loading…
Reference in New Issue
Block a user