当前位置: 技术问答>linux和unix
测试内核启动时间,便于优化
来源: 互联网 发布时间:2016-02-07
本文导语: 怎样测出内核的整个启动时间, 要想用Printk打出内核中各个模块的启动时间该怎么做。 linux内核中得到当前time的函数接口是什么? 想要优化一下启动时间,一般该怎么做?? 盼复!!! | ...
怎样测出内核的整个启动时间, 要想用Printk打出内核中各个模块的启动时间该怎么做。
linux内核中得到当前time的函数接口是什么?
想要优化一下启动时间,一般该怎么做??
盼复!!!
|
1.直接在grub启动参数加time参数后启动,再看/var/log/messages里面,如Aug 24 17:12:55 He kernel: [ 40.323214] eth1: link up, 100Mbps, full-duplex, lpa 0x45E1,日志的[]内的内容应该是时间,据下列代码得
linux/kernel/printk.c
以下是处理time参数的代码
static int __init printk_time_setup(char *str)
{
if (*str)
return 0;
printk_time = 1;
return 1;
}
__setup("time", printk_time_setup);
以下是处理打印时间的代码,我不明白时间的单位,郁闷
asmlinkage int vprintk(const char *fmt, va_list args)函数中
/* log_level_unknown signals the start of a new line */
if (printk_time) {
int loglev_char;
char tbuf[50], *tp;
unsigned tlen;
unsigned long long t;
unsigned long nanosec_rem;
/*
* force the log level token to be
* before the time output.
*/
if (p[0] == '') {
loglev_char = p[1];
p += 3;
printed_len -= 3;
} else {
loglev_char = default_message_loglevel
+ '0';
}
t = printk_clock();
nanosec_rem = do_div(t, 1000000000);
tlen = sprintf(tbuf,
"[%5lu.%06lu] ",
loglev_char,
(unsigned long)t,
nanosec_rem/1000);
for (tp = tbuf; tp
linux/kernel/printk.c
以下是处理time参数的代码
static int __init printk_time_setup(char *str)
{
if (*str)
return 0;
printk_time = 1;
return 1;
}
__setup("time", printk_time_setup);
以下是处理打印时间的代码,我不明白时间的单位,郁闷
asmlinkage int vprintk(const char *fmt, va_list args)函数中
/* log_level_unknown signals the start of a new line */
if (printk_time) {
int loglev_char;
char tbuf[50], *tp;
unsigned tlen;
unsigned long long t;
unsigned long nanosec_rem;
/*
* force the log level token to be
* before the time output.
*/
if (p[0] == '') {
loglev_char = p[1];
p += 3;
printed_len -= 3;
} else {
loglev_char = default_message_loglevel
+ '0';
}
t = printk_clock();
nanosec_rem = do_div(t, 1000000000);
tlen = sprintf(tbuf,
"[%5lu.%06lu] ",
loglev_char,
(unsigned long)t,
nanosec_rem/1000);
for (tp = tbuf; tp