linux printk 时间戳,printk_time 中时间戳的获取

可以在用prink打的log前面加上时间戳,但这个时间戳是怎么得到的呢?

我们知道printk-> vprintk_emit

1608 asmlinkage int vprintk_emit(int facility, int level,

1609 const char *dict, size_t dictlen,

1610 const char *fmt, va_list args)

1611 {

1748 if (cont.len) {

1749 if (cont.owner == current && !(lflags & LOG_PREFIX))

1750 stored = cont_add(facility, level, text,

1751 text_len);

1752 cont_flush(LOG_NEWLINE);

1753 }

1754

1755 if (stored)

1756 printed_len += text_len;

1757 else

1758 printed_len += log_store(facility, level, lflags, 0,

1759 dict, dictlen, text, text_len);

1760 }

1761

这个函数的1748行会判断要打印的log是否为NULL,不为NULL的话,就会走到cont_add 来得到当前log的时间

1546 static bool cont_add(int facility, int level, const char *text, size_t len)

1547 {

1548 if (cont.len && cont.flushed)

1549 return false;

1550

1551 /*

1552 * If ext consoles are present, flush and skip in-kernel

1553 * continuation. See nr_ext_console_drivers definition. Also, if

1554 * the line gets too long, split it up in separate records.

1555 */

1556 if (nr_ext_console_drivers || cont.len + len > sizeof(cont.buf)) {

1557 cont_flush(LOG_CONT);

1558 return false;

1559 }

1560

1561 if (!cont.len) {

1562 cont.facility = facility;

1563 cont.level = level;

1564 cont.owner = current;

1565 cont.ts_nsec = local_clock();

1566 cont.flags = 0;

1567 cont.cons = 0;

1568 cont.flushed = false;

1569 }

1570

1571 memcpy(cont.buf + cont.len, text, len);

1572 cont.len += len;

1573

1574 if (cont.len > (sizeof(cont.buf) * 80) / 100)

1575 cont_flush(LOG_CONT);

1576

1577 return true;

1578 }

这个函数的1665行会得到通过local_clock得到当前时间。在vprintk_emit 也可能是走log_store 这个flow,里面也是调用local_clock 来得到时间。

所以结论就是prink 中的时间戳是通过local_clock得到的.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值