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
-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 是块层 IO 跟踪机制,它提供有关直到用户空间的请求队列操作的详细信息。
提供了三个主要组件:
blkparse
)。自 2.6.17-rc1
起,这些补丁已包含在主要的 Linux 内核中,而自 2.6.23
起已包含在默认的 Debian 内核中。
blktrace -d dev [ -r debugfs_path ] [ -o output ] [-k ] [ -w time ] [ -a action ] [ -A action_mask ] [ -v ]
-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
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
dd
命令。