IO性能工具

一、iotop

1. 用法

# iotop --help
Usage: iotop [-h] [-P] [-d <delay>] [-n <cycles>] [-s <column>]
    -a 显示字节数而非速率
    -d 设置刷新间隔(秒)
    -h 显示此帮助信息
    -m 设置要显示的进程或线程数
    -n 设置退出前的刷新次数
    -P 显示进程数而非默认的线程数
    -s 设置排序依据的列: pid、read、write、total、io、swap、faults、sched、mem 或 delay。

 

2. 示例

iotop -d 5 //统计最近5秒的

iotop -m 4 -d 2 //循环显示4个线程, 每2秒刷新一次。

iotop -m 4 -n 3 //只循环显示3次

iotop -P -m 4 //以进程为单位进行展示而不是线程

iotop -s faults -m 4 //按faults进行排序,可选的还有 pid, read, write, total, io, swap, faults, sched, mem or delay

# iotop | head -5
                          --- IO (KiB/s) --- --- faults ---  ----------- delayed on ---------- //单位KB/s
   PID Command            read  write  total  major  minor  IO     swap   sched  mem    total
  1165 logcat                0    212    212      0      0  0.00%  0.00%  0.00%  0.00%  0.00%
 26337 peechservice          0     44     44      0   3451  0.00%  0.00%  0.00%  0.00%  0.00%
  2808 queued-work-loo       0     12     12      0      3  0.00%  0.00%  0.00%  0.00%  0.00%

# iotop -a | head -5
                          ---- IO (KiB) ---- --- faults ---  ----------- delayed on ---------- //单位KB
   PID Command            read  write  total  major  minor  IO     swap   sched  mem    total
  1165 logcat                0    240    240      0      0  0.00%  0.00%  0.00%  0.00%  0.00%
  1167 logcat                0     36     36      0      0  0.00%  0.00%  0.00%  0.00%  0.00%
  2921 Thread-4              0     12     12      0      0  0.00%  0.00%  0.00%  0.00%  0.00%

# iotop -m 10
                          --- IO (KiB/s) --- --- faults ---  ----------- delayed on ----------
   PID Command            read  write  total  major  minor  IO     swap   sched  mem    total
  7976 speech_po             0    532    532      0    412  0.00%  0.00%  0.00%  0.00%  0.00%
  7890 native_fsp            0    216    216      0    135  0.00%  0.00%  0.00%  0.00%  0.00%
  1158 cnss_diag             0    192    192      0      0  0.00%  0.00%  0.00%  0.00%  0.00%
  8250 iot.coreservice       0    152    152      0     38  0.00%  0.00%  0.00%  0.00%  0.00%
  8314 iaopeng.smartas       0    152    152      0     38  0.00%  0.00%  0.00%  0.00%  0.00%
  1014 logcat                0     12     12      0      0  0.00%  0.00%  0.00%  0.00%  0.00%
     1 init                  0      0      0      0      0  0.00%  0.00%  0.00%  0.00%  0.00%
     2 kthreadd              0      0      0      0      0  0.00%  0.00%  0.00%  0.00%  0.00%
     3 rcu_gp                0      0      0      0      0  0.00%  0.00%  0.00%  0.00%  0.00%
     4 rcu_par_gp            0      0      0      0      0  0.00%  0.00%  0.00%  0.00%  0.00%
       TOTAL                 0   1256   1256      0    949

注: major fault 应该是从swap中换回内存,而 minor fault 应该是单纯的 page fault.

 

3. 相关命令

# io
ionice                   iorap.cmd.maintenance    iorap.prefetcherd        iorenice
iorap.cmd.compiler       iorap.inode2filename     iorapd                   iotop

 

4. 实验

下面命令创建大量IO, 看统计结果

# time dd if=/dev/zero of=/sdcard/test.file bs=1G count=5
5+0 records in
5+0 records out
5368709120 bytes (5.0 G) copied, 13.336342 s, 384 M/s
    0m13.35s real     0m00.00s user     0m11.20s system

 

5. 小结

iotop 对 IO 的统计原理和 top 不同,它数据源来自 /proc/<pid>/io, 统计的是实际的量,不是处于IO状态的时间。

iotop 统计,也有一些误读点:
(1) buffered I/O 与回写归属: 应用写文件后,实际落盘可能由内核回写线程完成,iotop 归属不总是直观。
(2) page cache 命中: 命中缓存时,应用虽"读了很多"但不一定有实际磁盘读。
(3) 多队列/blk-mq + cgroup 限速: 设备层和 cgroup 也会改变谁先跑、跑多快,和 ioprio 叠加后更复杂。

 

二、vmstat

1. 打印内容

au8295_xp:/ # vmstat 1
procs ------------memory------------ ----swap--- -----io---- ---system-- ----cpu----
 r  b    swpd    free   buff   cache    si    so    bi    bo    in    cs us sy id wa
10  0  679408 1731736  11160 4748732     8    16    25   112     0  3079  8 10 81  0
 0  0  679408 1796936  11160 4748812     0     0     0   468     0 17706  5  8 87  0
...

 

posted on 2025-01-17 10:38  Hello-World3  阅读(80)  评论(0)    收藏  举报

导航