blktrace 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

blktrace 命令安装:


-bash/zsh: blktrace command not found

#Debian
apt-get install blktrace

#Ubuntu
apt-get install blktrace

#Kali Linux
apt-get install blktrace

#CentOS
yum install blktrace

#Fedora
dnf install blktrace

#Raspbian
apt-get install blktrace

blktrace 命令补充说明:


blktrace 是块层 IO 跟踪机制,它提供有关直到用户空间的请求队列操作的详细信息。

提供了三个主要组件:

  • blktrace:该实用程序可将事件跟踪从内核转移到长期磁盘存储中,或提供直接格式化的输出(通过 blkparse)。
  • blkparse:一种实用程序,用于格式化存储在文件中的事件,或者在实时模式下运行时直接输出 blktrace 收集的数据。
  • 运行 blktrace 需要 Linux 内核的补丁程序,其中包括内核事件记录接口,还需要对块层区域进行补丁程序以发出事件跟踪。

2.6.17-rc1 起,这些补丁已包含在主要的 Linux 内核中,而自 2.6.23 起已包含在默认的 Debian 内核中。

blktrace 命令语法:


blktrace -d dev [ -r debugfs_path ] [ -o output ] [-k ] [ -w time ] [ -a action ] [ -A action_mask ] [ -v ]

blktrace 命令选项:


-A hex-mask
--set-mask=hex-mask

Set filter mask to hex-mask (see below for masks)
-a mask
--act-mask=mask

Add mask to current filter (see below for masks)
-b size
--buffer-size=size

Specifies buffer size for event extraction (scaled by 1024). The default buffer size is 512KiB.
-d dev
--dev=dev

Adds dev as a device to trace
-I file
--input-devs=file

Adds the devices found in file as devices to trace
-n num-sub
--num-sub-buffers=num-sub

Specifies number of buffers to use. blktrace defaults to 4 sub buffers.
-l
--listen

Run in network listen mode (blktrace server)
-h hostname
--host=hostname

Run in network client mode, connecting to the given host
-p number
--port=number

Network port to use (default 8462)
-s
--no-sendfile

Make the network client NOT use sendfile() to transfer data
-o basename
--output=basename

Specifies base name for input files. Default is device.blktrace.cpu. Specifying -o - runs in live mode with blkparse (writing data to standard out).
-D dir
--output-dir=dir

Prepend file to output file name(s)
-r rel-path
--relay=rel-path

Specifies debugfs mount point
-v
--version

Outputs version
-V
--version

Outputs version
-w seconds
--stopwatch=seconds

Sets run time to the number of seconds specified

blktrace 命令实例:


1. 使用 blktrace 跟踪计算机上的 I/O

blktrace -d /dev/sda -o -|blkparse -i -          

2. 同时,在另一个控制台上,启动以下命令以生成一些 I/O 以进行测试:

dd if=/dev/zero of=/mnt/test1 bs=1M count=1

从 blktrace 控制台,您将获得输出,最终将如下所示:

CPU0 (8,0):
 Reads Queued:           2,       60KiB Writes Queued:       5,132,   20,524KiB
 Read Dispatches:        2,       60KiB Write Dispatches:       61,   20,524KiB
 Reads Requeued:         0 Writes Requeued:         0
 Reads Completed:        2,       60KiB Writes Completed:       63,   20,524KiB
 Read Merges:            0,        0KiB Write Merges:        5,070,   20,280KiB
 Read depth:             1         Write depth:             7
 IO unplugs:            14         Timer unplugs:           9
Throughput (R/W): 8KiB/s / 2,754KiB/s
Events (8,0): 21,234 entries
Skips: 166 forward (1,940,721 -  98.9%)

3. btrace 命令也可以达到相同的结果。命令启动后,请应用与第 2 部分相同的原理。

btrace /dev/sda

4. 在第 1 部分,第 2 部分和第 4 部分中,启动了 blktrace 命令,该命令将永久运行-不退出。在此特定示例中,我将输出文件名进行分析。假设您要运行 blktrace 30 秒钟,命令将如下所示:

blktrace -w 30 -d /dev/sda -o io-debugging

5. 在另一个控制台上,启动以下命令:

dd if=/dev/sda of=/dev/null bs=1M count=10 iflag=direct

6. 等待 30 秒以使步骤4完成。我刚得到以下结果:

[root@localhost mnt]# blktrace -w 30 -d /dev/sda -o io-debugging
=== sda ===
  CPU  0:                  510 events,       24 KiB data
  Total:                   510 events (dropped 0),       24 KiB data

7. 您会在 /mnt 目录中注意到将创建该文件。要读取它,请使用命令 blkparse

blkparse io-debugging.blktrace.0 | less

8. 现在,让我们看一下 blkparse 命令的简单摘录:

8,0    0        1     0.000000000  5686  Q   R 0 + 1024 [dd]
8,0    0        0     0.000028926     0  m   N cfq5686S / alloced
8,0    0        2     0.000029869  5686  G   R 0 + 1024 [dd]
8,0    0        3     0.000034500  5686  P   N [dd]
8,0    0        4     0.000036509  5686  I   R 0 + 1024 [dd]
8,0    0        0     0.000038209     0  m   N cfq5686S / insert_request
8,0    0        0     0.000039472     0  m   N cfq5686S / add_to_rr

  • 第1列显示设备主,次元组
  • 第2列提供有关 CPU 的信息,并继续显示发出 IO 进程的进程的顺序,时间戳和 PID。
  • 第6列显示事件类型,例如,Q 表示由请求队列代码处理的 IO。
  • 第7列是 R(代表读取),W(代表写入),D(代表区块),B(代表屏障操作),
  • 最后一列是区块编号,后跟 + 号是请求的区块编号。[] 括号之间的最后一个字段是发出请求的流程的流程名称。在我们的例子中,我运行 dd 命令。

blktrace 命令扩展阅读:




blktrace 命令评论

共收录到 489Linux 命令