增加编译参数关闭hilog和内核日志
1. 新增关闭log日志的编译命令参数: --extra-log nolog 例如:./build.sh --product-name rk3568 --extra-log nolog --ccache 2. 实现该功能的修改点: 2.1 build子系统 2.1.1 build/ohos_var.gni 添加extra_log变量声明 declare_args() { build_
·
1. 新增关闭log日志的编译命令参数:
--extra-log nolog
例如:./build.sh --product-name rk3568 --extra-log nolog --ccache
2. 实现该功能的修改点:
2.1 build子系统
2.1.1 build/ohos_var.gni
添加extra_log变量声明
declare_args() {
build_variant = "root"
device_type = "default"
+ extra_log = "default"
}
2.1.2 build/script/entry.py
新增编译属性
def do_build(args):
...
if args.build_variant:
cmd.append('--build-variant=' + args.build_variant)
+ if args.extra_log:
+ cmd.append('--extra-log=' + args.extra_log)
...
def main():
...
parse.add_option('--share-ccache')
+ parse.add_option('--extra-log', default='default')
...
2.1.3 build/tools/component_tools/kconfig
添加属性识别
config property$$target_cpu
string "target_cpu"
default ""
+ config property$$extra_log
+ string "extra_log"
+ default ""
2.1.4 build/lite/hb_internal/build/下的build.py和build_process.py
编译命令执行解析参数处理
//build.py
def add_options(parser):
...
parser.add_argument('--build-variant',
help='specifies device operating mode'
default='root')
+ parser.add_argument('--extra-log',
+ help='specifies hilog switch'
+ default='default')
...
def exec_command(args):
...
if hasattr(args, 'build_variant') and args.build_variant:
cmd_args['build_variant'] = args.build_variant
+ if hasattr(args, 'extra_log') and args.extra_log:
+ build.register_args('extra_log') and args.extra_log
...
//build_process.py
class Build():
if cmd_args.get('device_type'):
self.register_args('device_type', cmd_args.get('device_type'))
+ if cmd_args.get('extra_log'):
+ self.register_args('extra_log', cmd_args.get('extra_log'))
...
2.2 修改base/hivewdfx/hilog子系统
2.2.1 frameworks/libhilog/BUILD.gn
gn对添加的编译变量识别并添加编译宏
template("libhilog_source") {
defines += [ "HILOG_USE_MUSL" ]
}
+ if (extra_log == "nolog") {
+ defines += [ "HILOG_CLOSE" ]
+ }
...
2.2.2 frameworks/libhilog/base/hilog_base.cpp
通过编译宏屏蔽hilog打印
bool HilogBaseIsLoggable(unsigned int domain, const char *tag, LogLevel level)
{
+ #ifdef HILOG_CLOSE
+ return false;
+ #endif
...
return true;
}
2.2.3 frameworks/libhilog/hilog_printf.cpp
通过编译宏屏蔽hilog打印
bool HilogIsLoggable(unsigned int domain, const char *tag, LogLevel level)
{
+ #ifdef HILOG_CLOSE
+ return false;
+ #endif
...
return true;
}
2.3 修改base/startup/init子系统
2.3.1 services/init/standard/BUILD.gn
同上,子系统gn对添加的编译变量识别并添加编译宏
ohos_executable("init") {
...
]
}
+ if (extra_log == "nolog")
+ defines += [ "HILOG_CLOSE" ]
+ }
if (target_cpu == "arm64") {
defines += [ "SUPPORT_64BIT" ]
}
2.3.2 services/init/standard/init.c
关闭内核日志落盘,新增修改内核日志等级函数并通过编译宏调用
static void EnableDevKmsg(void)
{
...
char *kmsgStatus = "on";
+ #ifdef HILOG_CLOSE
+ kmsgStatus = "off";
+ #endif
...
}
+ static void DisableKmsg(void)
+ {
+ int fd = open("/proc/sys/kernel/printk", O_WRONLY | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
+ if (fd < 0) {
+ return;
+ }
+ char *kmsgLevel = "0 ";
+ write(fd, kmsgLevel, strlen(kmsgLevel) + 1);
+ clse(fd);
+ fd = -1;
+ return;
+ }
void LogInit(void)
{
...
EnableDevKmsg();
INIT_LOGI("Start init first stage.");
+ #ifdef HILOG_CLOSE
+ DisableKmsg();
+ #endif
...
}
2.3.3 services/log/BUILD.gn
init子系统添加编译宏
if (defined(ohos_lite)) {
ohos_static_library("init_log") {
sources = base_sources
defines = [ "INIT_DMESG" ]
+ if (extra_log == "nolog")
+ defines += [ "HILOG_CLOSE" ]
+ }
...
ohos_static_library("agent_log") {
sources = base_sources
defines = [ "INIT_AGENT" ]
+ if (extra_log == "nolog")
+ defines += [ "HILOG_CLOSE" ]
+ }
...
2.3.4 services/log/init_log.c
static void PrintLog(InitLogLevel logLevel, unsigned int domain, const char *tag, const char *log)
{
+ #ifdef HILOG_CLOSE
+ return;
+ #endif
...
}
更多推荐
已为社区贡献10条内容
所有评论(0)