Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
81e80e19
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
接近 2 年 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
81e80e19
编写于
9月 22, 2022
作者:
O
openharmony_ci
提交者:
Gitee
9月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1258 添加init的启动关键事件
Merge pull request !1258 from cheng_jinsong/master_cc_add_init_bootevent
上级
47c4a9c4
c2d059ff
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
77 addition
and
26 deletion
+77
-26
services/init/standard/init.c
services/init/standard/init.c
+13
-1
services/modules/bootevent/bootevent.c
services/modules/bootevent/bootevent.c
+64
-25
未找到文件。
services/init/standard/init.c
浏览文件 @
81e80e19
...
@@ -251,13 +251,22 @@ HOOK_MGR *GetBootStageHookMgr()
...
@@ -251,13 +251,22 @@ HOOK_MGR *GetBootStageHookMgr()
INIT_TIMING_STAT
g_bootJob
=
{
0
};
INIT_TIMING_STAT
g_bootJob
=
{
0
};
static
void
RecordInitBootEvent
(
const
char
*
initBootEvent
)
{
const
char
*
bootEventArgv
[]
=
{
"init"
,
initBootEvent
};
PluginExecCmd
(
"bootevent"
,
ARRAY_LENGTH
(
bootEventArgv
),
bootEventArgv
);
return
;
}
static
void
BootStateChange
(
int
start
,
const
char
*
content
)
static
void
BootStateChange
(
int
start
,
const
char
*
content
)
{
{
if
(
start
==
0
)
{
if
(
start
==
0
)
{
clock_gettime
(
CLOCK_MONOTONIC
,
&
(
g_bootJob
.
startTime
));
clock_gettime
(
CLOCK_MONOTONIC
,
&
(
g_bootJob
.
startTime
));
RecordInitBootEvent
(
content
);
INIT_LOGI
(
"boot job %s start."
,
content
);
INIT_LOGI
(
"boot job %s start."
,
content
);
}
else
{
}
else
{
clock_gettime
(
CLOCK_MONOTONIC
,
&
(
g_bootJob
.
endTime
));
clock_gettime
(
CLOCK_MONOTONIC
,
&
(
g_bootJob
.
endTime
));
RecordInitBootEvent
(
content
);
long
long
diff
=
InitDiffTime
(
&
g_bootJob
);
long
long
diff
=
InitDiffTime
(
&
g_bootJob
);
INIT_LOGI
(
"boot job %s finish diff %lld us."
,
content
,
diff
);
INIT_LOGI
(
"boot job %s finish diff %lld us."
,
content
,
diff
);
}
}
...
@@ -363,9 +372,9 @@ void SystemConfig(void)
...
@@ -363,9 +372,9 @@ void SystemConfig(void)
options
.
flags
=
0
;
options
.
flags
=
0
;
options
.
preHook
=
InitPreHook
;
options
.
preHook
=
InitPreHook
;
options
.
postHook
=
InitPostHook
;
options
.
postHook
=
InitPostHook
;
InitServiceSpace
();
InitServiceSpace
();
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_GLOBAL_INIT
,
(
void
*
)
&
timingStat
,
(
void
*
)
&
options
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_GLOBAL_INIT
,
(
void
*
)
&
timingStat
,
(
void
*
)
&
options
);
RecordInitBootEvent
(
"init.prepare"
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_PRE_PARAM_SERVICE
,
(
void
*
)
&
timingStat
,
(
void
*
)
&
options
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_PRE_PARAM_SERVICE
,
(
void
*
)
&
timingStat
,
(
void
*
)
&
options
);
InitParamService
();
InitParamService
();
...
@@ -376,7 +385,9 @@ void SystemConfig(void)
...
@@ -376,7 +385,9 @@ void SystemConfig(void)
// load SELinux context and policy
// load SELinux context and policy
// Do not move position!
// Do not move position!
PluginExecCmdByName
(
"loadSelinuxPolicy"
,
""
);
PluginExecCmdByName
(
"loadSelinuxPolicy"
,
""
);
RecordInitBootEvent
(
"init.prepare"
);
RecordInitBootEvent
(
"init.ParseCfg"
);
LoadSpecialParam
();
LoadSpecialParam
();
// parse parameters
// parse parameters
...
@@ -385,6 +396,7 @@ void SystemConfig(void)
...
@@ -385,6 +396,7 @@ void SystemConfig(void)
// read config
// read config
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_PRE_CFG_LOAD
,
(
void
*
)
&
timingStat
,
(
void
*
)
&
options
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_PRE_CFG_LOAD
,
(
void
*
)
&
timingStat
,
(
void
*
)
&
options
);
ReadConfig
();
ReadConfig
();
RecordInitBootEvent
(
"init.ParseCfg"
);
INIT_LOGI
(
"boot parse config file done."
);
INIT_LOGI
(
"boot parse config file done."
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_CFG_LOAD
,
(
void
*
)
&
timingStat
,
(
void
*
)
&
options
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_POST_CFG_LOAD
,
(
void
*
)
&
timingStat
,
(
void
*
)
&
options
);
...
...
services/modules/bootevent/bootevent.c
浏览文件 @
81e80e19
...
@@ -102,6 +102,34 @@ static int AddServiceBootEvent(const char *serviceName, const char *paramName)
...
@@ -102,6 +102,34 @@ static int AddServiceBootEvent(const char *serviceName, const char *paramName)
return
0
;
return
0
;
}
}
static
void
AddInitBootEvent
(
const
char
*
bootEventName
)
{
ListNode
*
found
=
NULL
;
found
=
OH_ListFind
(
&
bootEventList
,
(
void
*
)
bootEventName
,
ParseBooteventCompareProc
);
if
(
found
!=
NULL
)
{
INIT_CHECK_ONLY_RETURN
(
clock_gettime
(
CLOCK_MONOTONIC
,
&
(((
BOOT_EVENT_PARAM_ITEM
*
)
found
)
->
timestamp
[
BOOTEVENT_READY
]))
==
0
);
return
;
}
BOOT_EVENT_PARAM_ITEM
*
item
=
malloc
(
sizeof
(
BOOT_EVENT_PARAM_ITEM
));
if
(
item
==
NULL
)
{
return
;
}
OH_ListInit
(
&
item
->
node
);
if
(
clock_gettime
(
CLOCK_MONOTONIC
,
&
(
item
->
timestamp
[
BOOTEVENT_FORK
]))
!=
0
)
{
free
(
item
);
return
;
}
item
->
paramName
=
strdup
(
bootEventName
);
if
(
item
->
paramName
==
NULL
)
{
free
(
item
);
return
;
}
OH_ListAddTail
(
&
bootEventList
,
(
ListNode
*
)
&
item
->
node
);
return
;
}
#define BOOT_EVENT_BOOT_COMPLETED "bootevent.boot.completed"
#define BOOT_EVENT_BOOT_COMPLETED "bootevent.boot.completed"
static
void
BootEventParaFireByName
(
const
char
*
paramName
)
static
void
BootEventParaFireByName
(
const
char
*
paramName
)
...
@@ -128,7 +156,7 @@ static void BootEventParaFireByName(const char *paramName)
...
@@ -128,7 +156,7 @@ static void BootEventParaFireByName(const char *paramName)
return
;
return
;
}
}
// All parameters are fired, set boot completed now ...
// All parameters are fired, set boot completed now ...
INIT_LOGI
(
"All bootevents are fired, boot complete now ..."
);
INIT_LOGI
(
"All boot
events are fired, boot complete now ..."
);
SystemWriteParam
(
BOOT_EVENT_BOOT_COMPLETED
,
"true"
);
SystemWriteParam
(
BOOT_EVENT_BOOT_COMPLETED
,
"true"
);
return
;
return
;
}
}
...
@@ -139,31 +167,31 @@ static void ServiceParseBootEventHook(SERVICE_PARSE_CTX *serviceParseCtx)
...
@@ -139,31 +167,31 @@ static void ServiceParseBootEventHook(SERVICE_PARSE_CTX *serviceParseCtx)
int
cnt
;
int
cnt
;
cJSON
*
bootEvents
=
cJSON_GetObjectItem
(
serviceParseCtx
->
serviceNode
,
BOOT_EVENT_FIELD_NAME
);
cJSON
*
bootEvents
=
cJSON_GetObjectItem
(
serviceParseCtx
->
serviceNode
,
BOOT_EVENT_FIELD_NAME
);
// No bootevents in config file
// No boot
events in config file
if
(
bootEvents
==
NULL
)
{
if
(
bootEvents
==
NULL
)
{
return
;
return
;
}
}
SERVICE_INFO_CTX
ctx
=
{
0
};
SERVICE_INFO_CTX
ctx
=
{
0
};
ctx
.
serviceName
=
serviceParseCtx
->
serviceName
;
ctx
.
serviceName
=
serviceParseCtx
->
serviceName
;
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_CLEAR
,
(
void
*
)
&
ctx
,
NULL
);
HookMgrExecute
(
GetBootStageHookMgr
(),
INIT_SERVICE_CLEAR
,
(
void
*
)
&
ctx
,
NULL
);
// Single bootevent in config file
// Single boot
event in config file
if
(
!
cJSON_IsArray
(
bootEvents
))
{
if
(
!
cJSON_IsArray
(
bootEvents
))
{
if
(
AddServiceBootEvent
(
serviceParseCtx
->
serviceName
,
if
(
AddServiceBootEvent
(
serviceParseCtx
->
serviceName
,
cJSON_GetStringValue
(
bootEvents
))
!=
0
)
{
cJSON_GetStringValue
(
bootEvents
))
!=
0
)
{
INIT_LOGI
(
"Add service boot
e
vent failed %s"
,
serviceParseCtx
->
serviceName
);
INIT_LOGI
(
"Add service boot
E
vent failed %s"
,
serviceParseCtx
->
serviceName
);
return
;
return
;
}
}
g_bootEventNum
++
;
g_bootEventNum
++
;
return
;
return
;
}
}
// Multiple bootevents in config file
// Multiple boot
events in config file
cnt
=
cJSON_GetArraySize
(
bootEvents
);
cnt
=
cJSON_GetArraySize
(
bootEvents
);
for
(
int
i
=
0
;
i
<
cnt
;
i
++
)
{
for
(
int
i
=
0
;
i
<
cnt
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
bootEvents
,
i
);
cJSON
*
item
=
cJSON_GetArrayItem
(
bootEvents
,
i
);
if
(
AddServiceBootEvent
(
serviceParseCtx
->
serviceName
,
if
(
AddServiceBootEvent
(
serviceParseCtx
->
serviceName
,
cJSON_GetStringValue
(
item
))
!=
0
)
{
cJSON_GetStringValue
(
item
))
!=
0
)
{
INIT_LOGI
(
"Add service boot
e
vent failed %s"
,
serviceParseCtx
->
serviceName
);
INIT_LOGI
(
"Add service boot
E
vent failed %s"
,
serviceParseCtx
->
serviceName
);
continue
;
continue
;
}
}
g_bootEventNum
++
;
g_bootEventNum
++
;
...
@@ -173,17 +201,21 @@ static void ServiceParseBootEventHook(SERVICE_PARSE_CTX *serviceParseCtx)
...
@@ -173,17 +201,21 @@ static void ServiceParseBootEventHook(SERVICE_PARSE_CTX *serviceParseCtx)
static
int
DoBootEventCmd
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
static
int
DoBootEventCmd
(
int
id
,
const
char
*
name
,
int
argc
,
const
char
**
argv
)
{
{
PLUGIN_CHECK
(
argc
>=
1
,
return
-
1
,
"Invalid parameter"
);
PLUGIN_CHECK
(
argc
>=
1
,
return
-
1
,
"Invalid parameter"
);
// argv[0] samgr.ready.true
if
(
strcmp
(
argv
[
0
],
"init"
)
==
0
)
{
BootEventParaFireByName
(
argv
[
0
]);
AddInitBootEvent
(
argv
[
1
]);
}
else
{
// argv[0] samgr.ready.true
BootEventParaFireByName
(
argv
[
0
]);
}
return
0
;
return
0
;
}
}
static
int
AddItemToJson
(
cJSON
*
root
,
const
char
*
name
,
double
startime
,
int
tid
,
double
durTime
)
static
int
AddItemToJson
(
cJSON
*
root
,
const
char
*
name
,
double
start
T
ime
,
int
tid
,
double
durTime
)
{
{
cJSON
*
obj
=
cJSON_CreateObject
();
// release obj at traverse done
cJSON
*
obj
=
cJSON_CreateObject
();
// release obj at traverse done
INIT_CHECK_RETURN_VALUE
(
obj
!=
NULL
,
-
1
);
INIT_CHECK_RETURN_VALUE
(
obj
!=
NULL
,
-
1
);
cJSON_AddStringToObject
(
obj
,
"name"
,
name
);
cJSON_AddStringToObject
(
obj
,
"name"
,
name
);
cJSON_AddNumberToObject
(
obj
,
"ts"
,
startime
);
cJSON_AddNumberToObject
(
obj
,
"ts"
,
start
T
ime
);
cJSON_AddStringToObject
(
obj
,
"ph"
,
"X"
);
cJSON_AddStringToObject
(
obj
,
"ph"
,
"X"
);
cJSON_AddNumberToObject
(
obj
,
"pid"
,
0
);
cJSON_AddNumberToObject
(
obj
,
"pid"
,
0
);
cJSON_AddNumberToObject
(
obj
,
"tid"
,
tid
);
cJSON_AddNumberToObject
(
obj
,
"tid"
,
tid
);
...
@@ -192,9 +224,9 @@ static int AddItemToJson(cJSON *root, const char *name, double startime, int tid
...
@@ -192,9 +224,9 @@ static int AddItemToJson(cJSON *root, const char *name, double startime, int tid
return
0
;
return
0
;
}
}
static
int
Boot
e
ventTraversal
(
ListNode
*
node
,
void
*
root
)
static
int
Boot
E
ventTraversal
(
ListNode
*
node
,
void
*
root
)
{
{
static
int
tid
=
1
;
// 1 bootevent start num
static
int
tid
=
1
;
// 1 boot
event start num
BOOT_EVENT_PARAM_ITEM
*
item
=
(
BOOT_EVENT_PARAM_ITEM
*
)
node
;
BOOT_EVENT_PARAM_ITEM
*
item
=
(
BOOT_EVENT_PARAM_ITEM
*
)
node
;
double
forkTime
=
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_sec
*
SECTOMSEC
+
double
forkTime
=
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_sec
*
SECTOMSEC
+
(
double
)
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_nsec
/
MSECTONSEC
;
(
double
)
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_nsec
/
MSECTONSEC
;
...
@@ -217,19 +249,26 @@ static int SaveServiceBootEvent(int id, const char *name, int argc, const char *
...
@@ -217,19 +249,26 @@ static int SaveServiceBootEvent(int id, const char *name, int argc, const char *
INIT_CHECK_RETURN_VALUE
(
nowTime
>
0
,
-
1
);
INIT_CHECK_RETURN_VALUE
(
nowTime
>
0
,
-
1
);
struct
tm
*
p
=
localtime
(
&
nowTime
);
struct
tm
*
p
=
localtime
(
&
nowTime
);
INIT_CHECK_RETURN_VALUE
(
p
!=
NULL
,
-
1
);
INIT_CHECK_RETURN_VALUE
(
p
!=
NULL
,
-
1
);
char
boot
e
ventFileName
[
BOOT_EVENT_FILEPATH_MAX_LEN
]
=
""
;
char
boot
E
ventFileName
[
BOOT_EVENT_FILEPATH_MAX_LEN
]
=
""
;
INIT_CHECK_RETURN_VALUE
(
snprintf
(
boot
e
ventFileName
,
BOOT_EVENT_FILEPATH_MAX_LEN
,
INIT_CHECK_RETURN_VALUE
(
snprintf
(
boot
E
ventFileName
,
BOOT_EVENT_FILEPATH_MAX_LEN
,
BOOTEVENT_OUTPUT_PATH
"%d%d%d-%d%d.bootevent"
,
BOOTEVENT_OUTPUT_PATH
"%d%d%d-%d%d.bootevent"
,
1900
+
p
->
tm_year
,
p
->
tm_mon
,
p
->
tm_mday
,
p
->
tm_hour
,
p
->
tm_min
)
>=
0
,
-
1
);
// 1900 is start year
1900
+
p
->
tm_year
,
p
->
tm_mon
,
p
->
tm_mday
,
p
->
tm_hour
,
p
->
tm_min
)
>=
0
,
-
1
);
// 1900 is start year
CheckAndCreatFile
(
boot
e
ventFileName
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
CheckAndCreatFile
(
boot
E
ventFileName
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
FILE
*
tmpFile
=
fopen
(
boot
e
ventFileName
,
"wr"
);
FILE
*
tmpFile
=
fopen
(
boot
E
ventFileName
,
"wr"
);
INIT_CHECK_RETURN_VALUE
(
tmpFile
!=
NULL
,
-
1
);
INIT_CHECK_RETURN_VALUE
(
tmpFile
!=
NULL
,
-
1
);
cJSON
*
root
=
cJSON_CreateArray
();
cJSON
*
root
=
cJSON_CreateArray
();
INIT_CHECK_RETURN_VALUE
(
root
!=
NULL
,
-
1
);
if
(
root
==
NULL
)
{
OH_ListTraversal
(
&
bootEventList
,
(
void
*
)
root
,
BooteventTraversal
,
0
);
(
void
)
fclose
(
tmpFile
);
return
-
1
;
}
OH_ListTraversal
(
&
bootEventList
,
(
void
*
)
root
,
BootEventTraversal
,
0
);
char
*
buff
=
cJSON_Print
(
root
);
char
*
buff
=
cJSON_Print
(
root
);
INIT_CHECK_RETURN_VALUE
(
buff
!=
NULL
,
-
1
);
if
(
buff
==
NULL
)
{
INIT_CHECK_RETURN_VALUE
(
fprintf
(
tmpFile
,
"%s
\n
"
,
buff
)
>=
0
,
-
1
);
cJSON_Delete
(
root
);
(
void
)
fclose
(
tmpFile
);
return
-
1
;
}
INIT_CHECK_ONLY_ELOG
(
fprintf
(
tmpFile
,
"%s
\n
"
,
buff
)
>=
0
,
"save boot event file failed"
);
free
(
buff
);
free
(
buff
);
cJSON_Delete
(
root
);
cJSON_Delete
(
root
);
(
void
)
fflush
(
tmpFile
);
(
void
)
fflush
(
tmpFile
);
...
@@ -258,16 +297,16 @@ static void DumpServiceBootEvent(SERVICE_INFO_CTX *serviceCtx)
...
@@ -258,16 +297,16 @@ static void DumpServiceBootEvent(SERVICE_INFO_CTX *serviceCtx)
return
;
return
;
}
}
BOOT_EVENT_PARAM_ITEM
*
item
=
(
BOOT_EVENT_PARAM_ITEM
*
)
serviceExtData
->
data
;
BOOT_EVENT_PARAM_ITEM
*
item
=
(
BOOT_EVENT_PARAM_ITEM
*
)
serviceExtData
->
data
;
char
boot
e
ventForkTimeStamp
[
BOOT_EVENT_TIMESTAMP_MAX_LEN
]
=
""
;
char
boot
E
ventForkTimeStamp
[
BOOT_EVENT_TIMESTAMP_MAX_LEN
]
=
""
;
char
boot
e
ventReadyTimeStamp
[
BOOT_EVENT_TIMESTAMP_MAX_LEN
]
=
""
;
char
boot
E
ventReadyTimeStamp
[
BOOT_EVENT_TIMESTAMP_MAX_LEN
]
=
""
;
INIT_CHECK_ONLY_RETURN
(
sprintf_s
(
boot
e
ventForkTimeStamp
,
BOOT_EVENT_TIMESTAMP_MAX_LEN
,
"%f"
,
INIT_CHECK_ONLY_RETURN
(
sprintf_s
(
boot
E
ventForkTimeStamp
,
BOOT_EVENT_TIMESTAMP_MAX_LEN
,
"%f"
,
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_sec
+
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_sec
+
(
double
)
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_nsec
/
SECTONSEC
)
>=
0
);
(
double
)
item
->
timestamp
[
BOOTEVENT_FORK
].
tv_nsec
/
SECTONSEC
)
>=
0
);
INIT_CHECK_ONLY_RETURN
(
sprintf_s
(
boot
e
ventReadyTimeStamp
,
BOOT_EVENT_TIMESTAMP_MAX_LEN
,
"%f"
,
INIT_CHECK_ONLY_RETURN
(
sprintf_s
(
boot
E
ventReadyTimeStamp
,
BOOT_EVENT_TIMESTAMP_MAX_LEN
,
"%f"
,
(
long
)
item
->
timestamp
[
BOOTEVENT_READY
].
tv_sec
+
(
long
)
item
->
timestamp
[
BOOTEVENT_READY
].
tv_sec
+
(
double
)
item
->
timestamp
[
BOOTEVENT_READY
].
tv_nsec
/
SECTONSEC
)
>=
0
);
(
double
)
item
->
timestamp
[
BOOTEVENT_READY
].
tv_nsec
/
SECTONSEC
)
>=
0
);
printf
(
"
\t
%-20.20s
\t
%-50s
\t
%-20.20s
\t
%-20.20s
\n
"
,
serviceCtx
->
serviceName
,
item
->
paramName
,
printf
(
"
\t
%-20.20s
\t
%-50s
\t
%-20.20s
\t
%-20.20s
\n
"
,
serviceCtx
->
serviceName
,
item
->
paramName
,
boot
eventForkTimeStamp
,
boote
ventReadyTimeStamp
);
boot
EventForkTimeStamp
,
bootE
ventReadyTimeStamp
);
}
}
return
;
return
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录