linux命令:调试必备工具dmesg

在服务器上进行芯片调试时,我们会遇到各种各样的问题,很多问题与操作系统相关。此时就需要了解操作系统发生了哪些事件。

dmesg 是linux系统中用来打印或控制内核缓冲区内容的命令。这个环形缓冲区记录了系统启动以来发生的各种事件消息,包括系统日志、驱动程序消息、硬件错误、内核警告等。

例如,在系统reboot后,通过dmesg可以看到PCI设备枚举过程、可以检查是否发生了异常。

1、常用命令

运行 dmesg命令而不带任何参数,将打印出环形缓冲区的所有消息。

dmesg -T 显示事件发生的时间

dmesg -C 清除内核环形缓存消息

dmesg -c 读取并清除内核环形缓存消息

dmesg -H 以容易阅读的形式显示消息

dmesg -L  dmesg 会根据消息的类型(如错误、警告、信息等)给输出的消息加上不同的颜色。这样做可以提高可读性,使得用户能够更快地区分和识别消息的严重性和类型。

具体来说,使用 -L 或 --color 选项可能会对以下方面产生影响:

错误消息:通常会以红色显示,以突出显示错误,便于用户立即注意到。

警告消息:可能会以黄色显示,用于提醒用户存在潜在问题。

信息性消息:可能以默认终端颜色显示,用于普通信息的输出。

调试消息:可能会以特定的颜色显示,以便于在调试过程中区分调试信息。

其他类型的消息:根据系统配置和 dmesg 实现,其他类型的消息也可能有特定的颜色。

dmesg -T | grep PCI   

通过grep命令筛选出想查看的信息,例如grep PCI可以筛选出PCI设备枚举过程信息。

2、命令参考

Usage:

 dmesg [options]

Options:

 -C, --clear                 clear the kernel ring buffer

 -c, --read-clear            read and clear all messages

 -D, --console-off           disable printing messages to console

 -d, --show-delta            show time delta between printed messages

 -e, --reltime               show local time and time delta in readable format

 -E, --console-on            enable printing messages to console

 -F, --file <file>           use the file instead of the kernel log buffer

 -f, --facility <list>       restrict output to defined facilities

 -H, --human                 human readable output

 -k, --kernel                display kernel messages

 -L, --color                 colorize messages

 -l, --level <list>          restrict output to defined levels

 -n, --console-level <level> set level of messages printed to console

 -P, --nopager               do not pipe output into a pager

 -r, --raw                   print the raw message buffer

 -S, --syslog                force to use syslog(2) rather than /dev/kmsg

 -s, --buffer-size <size>    buffer size to query the kernel ring buffer

 -T, --ctime                 show human readable timestamp (could be

                               inaccurate if you have used SUSPEND/RESUME)

 -t, --notime                don't print messages timestamp

 -u, --userspace             display userspace messages

 -w, --follow                wait for new messages

 -x, --decode                decode facility and level to readable string

 -h, --help     display this help and exit

 -V, --version  output version information and exit

Supported log facilities:

    kern - kernel messages

    user - random user-level messages

    mail - mail system

  daemon - system daemons

    auth - security/authorization messages

  syslog - messages generated internally by syslogd

     lpr - line printer subsystem

    news - network news subsystem

Supported log levels (priorities):

   emerg - system is unusable

   alert - action must be taken immediately

    crit - critical conditions

     err - error conditions

    warn - warning conditions

  notice - normal but significant condition

    info - informational

   debug - debug-level messages

  • 22
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值