未验证 提交 4b8fde96 编写于 作者: O openharmony_ci 提交者: Gitee

!732 增加 dump service 命令

Merge pull request !732 from Mupceet/init530_1
......@@ -61,6 +61,7 @@ if (defined(ohos_lite)) {
ohos_executable("begetctl") {
sources = [
"bootchart_cmd.c",
"dump_service.c",
"init_cmd_reboot.c",
"main.c",
"misc_daemon.cpp",
......@@ -129,6 +130,7 @@ if (defined(ohos_lite)) {
"stop_service",
"service",
"sandbox",
"dump_service",
]
install_images = [ "system" ]
......
/*
* 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 <errno.h>
#include <stdio.h>
#include <string.h>
#include "begetctl.h"
#include "control_fd.h"
#include "init_utils.h"
#define DUMP_SERVICE_INFO_CMD_ARGS 2
static int main_cmd(BShellHandle shell, int argc, char **argv)
{
if (argc != DUMP_SERVICE_INFO_CMD_ARGS) {
BShellCmdHelp(shell, argc, argv);
return 0;
}
if (strcmp(argv[0], "dump_service") == 0) {
printf("dump service info \n");
CmdClientInit(INIT_CONTROL_FD_SOCKET_PATH, ACTION_DUMP, argv[1], "FIFO");
} else {
BShellCmdHelp(shell, argc, argv);
}
return 0;
}
MODULE_CONSTRUCTOR(void)
{
CmdInfo infos[] = {
{"dump_service", main_cmd, "dump one service info by serviceName", "dump_service serviceName", NULL},
{"dump_service", main_cmd, "dump all services info", "dump_service all", NULL},
};
for (size_t i = 0; i < sizeof(infos) / sizeof(infos[0]); i++) {
BShellEnvRegitsterCmd(GetShellHandle(), &infos[i]);
}
}
......@@ -63,11 +63,8 @@ void ReleaseService(Service *service);
void StartAllServices(int startMode);
void LoadAccessTokenId(void);
Service *AddService(const char *name);
#ifdef OHOS_SERVICE_DUMP
void DumpAllServices();
void DumpAllServices(void);
void DumpOneService(const Service *service);
#endif
#ifdef __cplusplus
#if __cplusplus
}
......
......@@ -43,43 +43,42 @@ static const int CRITICAL_DEFAULT_CRASH_TIME = 20;
static const int CRITICAL_DEFAULT_CRASH_COUNT = 4;
static const int CRITICAL_CONFIG_ARRAY_LEN = 3;
#ifdef OHOS_SERVICE_DUMP
static void DumpServiceArgs(const char *info, const ServiceArgs *args)
{
printf("\tservice %s count %d", info, args->count);
printf("\tservice %s count %d \n", info, args->count);
for (int j = 0; j < args->count; j++) {
if (args->argv[j] != NULL) {
printf("\t\tinfo [%d] %s", j, args->argv[j]);
printf("\t\tinfo [%d] %s \n", j, args->argv[j]);
}
}
}
static void DumpServiceJobs(const Service *service)
{
printf("\tservice job info");
printf("\tservice job info \n");
if (service->serviceJobs.jobsName[JOB_ON_BOOT] != NULL) {
printf("\t\tservice boot job %s", service->serviceJobs.jobsName[JOB_ON_BOOT]);
printf("\t\tservice boot job %s \n", service->serviceJobs.jobsName[JOB_ON_BOOT]);
}
if (service->serviceJobs.jobsName[JOB_ON_START] != NULL) {
printf("\t\tservice start job %s", service->serviceJobs.jobsName[JOB_ON_START]);
printf("\t\tservice start job %s \n", service->serviceJobs.jobsName[JOB_ON_START]);
}
if (service->serviceJobs.jobsName[JOB_ON_STOP] != NULL) {
printf("\t\tservice stop job %s", service->serviceJobs.jobsName[JOB_ON_STOP]);
printf("\t\tservice stop job %s \n", service->serviceJobs.jobsName[JOB_ON_STOP]);
}
if (service->serviceJobs.jobsName[JOB_ON_RESTART] != NULL) {
printf("\t\tservice restart job %s", service->serviceJobs.jobsName[JOB_ON_RESTART]);
printf("\t\tservice restart job %s \n", service->serviceJobs.jobsName[JOB_ON_RESTART]);
}
}
static void DumpServiceSocket(const Service *service)
{
printf("\tservice socket info");
printf("\tservice socket info \n");
ServiceSocket *sockopt = service->socketCfg;
while (sockopt != NULL) {
printf("\t\tsocket name: %s", sockopt->name);
printf("\t\tsocket type: %d", sockopt->type);
printf("\t\tsocket uid: %d", sockopt->uid);
printf("\t\tsocket gid: %d", sockopt->gid);
printf("\t\tsocket name: %s \n", sockopt->name);
printf("\t\tsocket type: %d \n", sockopt->type);
printf("\t\tsocket uid: %d \n", sockopt->uid);
printf("\t\tsocket gid: %d \n", sockopt->gid);
sockopt = sockopt->next;
}
}
......@@ -93,33 +92,33 @@ void DumpOneService(const Service *service)
};
int size = 0;
const InitArgInfo *statusMap = GetServieStatusMap(&size);
printf("\tservice name: [%s]", service->name);
printf("\tservice pid: [%d]", service->pid);
printf("\tservice crashCnt: [%d]", service->crashCnt);
printf("\tservice attribute: [%d]", service->attribute);
printf("\tservice importance: [%d]", service->importance);
printf("\tservice startMode: [%s]", startModeMap[service->status].name);
printf("\tservice status: [%s]", statusMap[service->status].name);
printf("\tservice perms uID [%d]", service->servPerm.uID);
printf("\tservice name: [%s] \n", service->name);
printf("\tservice pid: [%d] \n", service->pid);
printf("\tservice crashCnt: [%d] \n", service->crashCnt);
printf("\tservice attribute: [%d] \n", service->attribute);
printf("\tservice importance: [%d] \n", service->importance);
printf("\tservice startMode: [%s] \n", startModeMap[service->status].name);
printf("\tservice status: [%s] \n", statusMap[service->status].name);
printf("\tservice perms uID [%d] \n", service->servPerm.uID);
DumpServiceArgs("path arg", &service->pathArgs);
DumpServiceArgs("writepid file", &service->writePidArgs);
DumpServiceJobs(service);
DumpServiceSocket(service);
printf("\tservice perms groupId %d", service->servPerm.gIDCnt);
printf("\tservice perms groupId %d \n", service->servPerm.gIDCnt);
for (int i = 0; i < service->servPerm.gIDCnt; i++) {
printf("\t\tservice perms groupId %d", service->servPerm.gIDArray[i]);
printf("\t\tservice perms groupId %d \n", service->servPerm.gIDArray[i]);
}
printf("\tservice perms capability %d", service->servPerm.capsCnt);
printf("\tservice perms capability %d \n", service->servPerm.capsCnt);
for (int i = 0; i < (int)service->servPerm.capsCnt; i++) {
printf("\t\tservice perms capability %d", service->servPerm.caps[i]);
printf("\t\tservice perms capability %d \n", service->servPerm.caps[i]);
}
}
void DumpAllServices()
void DumpAllServices(void)
{
printf("Ready to dump all services:");
printf("total service number: %d", g_serviceSpace.serviceCount);
printf("Ready to dump all services: \n");
printf("total service number: %d \n", g_serviceSpace.serviceCount);
InitGroupNode *node = GetNextGroupNode(NODE_TYPE_SERVICES, NULL);
while (node != NULL) {
if (node->data.service == NULL) {
......@@ -130,9 +129,8 @@ void DumpAllServices()
DumpOneService(service);
node = GetNextGroupNode(NODE_TYPE_SERVICES, node);
}
printf("Dump all services finished");
printf("Dump all services finished \n");
}
#endif
static void FreeServiceArg(ServiceArgs *arg)
{
......
......@@ -65,11 +65,6 @@ void SystemConfig(void)
// read config
ReadConfig();
// dump config
#ifdef OHOS_SERVICE_DUMP
DumpAllServices();
#endif
// execute init
DoJob("pre-init");
#ifndef __LINUX__
......
......@@ -266,7 +266,6 @@ static int SystemDump(int id, const char *name, int argc, const char **argv)
{
INIT_ERROR_CHECK(argv != NULL && argc >= 1, return 0, "Invalid install parameter");
INIT_LOGI("Dump system info %s", argv[0]);
DumpAllServices();
SystemDumpParameters(1);
SystemDumpTriggers(1);
return 0;
......@@ -324,18 +323,19 @@ static void InitPreHook(const HOOK_INFO *hookInfo)
static void InitPostHook(const HOOK_INFO *hookInfo)
{
long long diff;
const long long baseTime = 1000;
HOOK_TIMING_STAT *stat = (HOOK_TIMING_STAT *)hookInfo->cookie;
clock_gettime(CLOCK_MONOTONIC, &(stat->endTime));
diff = (long long)((stat->endTime.tv_sec - stat->startTime.tv_sec) / 1000);
diff = (long long)((stat->endTime.tv_sec - stat->startTime.tv_sec) / baseTime);
if (stat->endTime.tv_nsec > stat->startTime.tv_nsec) {
diff += (stat->endTime.tv_nsec - stat->startTime.tv_nsec) * 1000;
diff += (stat->endTime.tv_nsec - stat->startTime.tv_nsec) * baseTime;
} else {
diff -= (stat->endTime.tv_nsec - stat->startTime.tv_nsec) * 1000;
diff -= (stat->endTime.tv_nsec - stat->startTime.tv_nsec) * baseTime;
}
INIT_LOGV("Executing hook [%d:%d:%p] cost [%lld]ms, return %d.",
hookInfo->stage, hookInfo->prio, hookInfo->hook, diff, hookInfo->retVal);
hookInfo->stage, hookInfo->prio, hookInfo->hook, diff, hookInfo->retVal);
}
void SystemConfig(void)
......
......@@ -47,11 +47,9 @@ static void ProcessDumpServiceControlFd(uint16_t type, const char *serviceCmd)
Service *service = GetServiceByName(serviceCmd);
if (service == NULL) {
#ifdef OHOS_SERVICE_DUMP
DumpAllServices();
} else {
DumpOneService(service);
#endif
}
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册