blktrace 編譯與使用【轉】

轉自:https://www.cnblogs.com/linhaostudy/p/16182795.html

 

正文

在對ssd性能調優過程中,有使用到blktrace,本文對blktrace做一個記錄

文章目錄

  1. blktrace介紹
  2. blktrace aarch64移植
  3. 使用
  4. 實例
  5. 數據分析
  6. blktrace分析ssd性能差的問題實例

1. blktrace介紹

我們首先需要知道提交到 block I/O層的每個I/O執行的具體操作,如下圖所示

image

blktrace功能如下:

  1. 提供關於單個I/O的詳細的block layer信息
  2. 低開銷內核跟蹤機制(在I/O壓力相對較大的情況下,對應用程序性能的影響不到2%)
  3. 可配置:
    1. 可以指定一個或多個物理設備或邏輯設備
    2. 用戶可選擇事件-可以在事件獲取和/或格式化輸出時指定過濾器
  4. 同時支持“實時”和“回放”跟蹤

blktrace總體架構如下:

image

2. blktrace aarch64移植

首先對blktrace,blkparse ,btt做個簡單的介紹,blktrace負責採集,blkparse負責對採集的數據進行解析,而btt能夠協助分析統計

blktrace選項如下,常用的使用有

  • -d dev #添加一個設備追蹤
  • -o file #指定輸出文件的名字
root@a1000:~# blktrace --help
blktrace: unrecognized option '--help'
Usage: blktrace

-d <dev>             | --dev=<dev>
[ -r <debugfs path>  | --relay=<debugfs path> ]
[ -o <file>          | --output=<file>]
[ -D <dir>           | --output-dir=<dir>
[ -w <time>          | --stopwatch=<time>]
[ -a <action field>  | --act-mask=<action field>]
[ -A <action mask>   | --set-mask=<action mask>]
[ -b <size>          | --buffer-size]
[ -n <number>        | --num-sub-buffers=<number>]
[ -l                 | --listen]
[ -h <hostname>      | --host=<hostname>]
[ -p <port number>   | --port=<port number>]
[ -s                 | --no-sendfile]
[ -I <devs file>     | --input-devs=<devs file>]
[ -v <version>       | --version]
[ -V <version>       | --version]
        -d Use specified device. May also be given last after options
        -r Path to mounted debugfs, defaults to /sys/kernel/debug
        -o File(s) to send output to
        -D Directory to prepend to output file names
        -w Stop after defined time, in seconds
        -a Only trace specified actions. See documentation
        -A Give trace mask as a single value. See documentation
        -b Sub buffer size in KiB (default 512)
        -n Number of sub buffers (default 4)
        -l Run in network listen mode (blktrace server)
        -h Run in network client mode, connecting to the given host
        -p Network port to use (default 8462)
        -s Make the network client NOT use sendfile() to transfer data
        -I Add devices found in <devs file>
        -v Print program version info
        -V Print program version info

blkparse選項如下,常用的使用有

  • -i input #輸入包含跟蹤數據的文件
  • -o output #輸出文件。如果未給出,則輸出爲標準輸出
root@a1000:~# blkparse -h
Usage: blkparse

-i <file>           | --input=<file>
[ -a <action field> | --act-mask=<action field> ]
[ -A <action mask>  | --set-mask=<action mask> ]
[ -b <traces>       | --batch=<traces> ]
[ -d <file>         | --dump-binary=<file> ]
[ -D <dir>          | --input-directory=<dir> ]
[ -f <format>       | --format=<format> ]
[ -F <spec>         | --format-spec=<spec> ]
[ -h                | --hash-by-name ]
[ -o <file>         | --output=<file> ]
[ -O                | --no-text-output ]
[ -q                | --quiet ]
[ -s                | --per-program-stats ]
[ -t                | --track-ios ]
[ -w <time>         | --stopwatch=<time> ]
[ -M                | --no-msgs
[ -v                | --verbose ]
[ -V                | --version ]

        -a Only trace specified actions. See documentation
        -A Give trace mask as a single value. See documentation
        -b stdin read batching
        -d Output file. If specified, binary data is written to file
        -D Directory to prepend to input file names
        -f Output format. Customize the output format. The format field
           identifies can be found in the documentation
        -F Format specification. Can be found in the documentation
        -h Hash processes by name, not pid
        -i Input file containing trace data, or '-' for stdin
        -o Output file. If not given, output is stdout
        -O Do NOT output text data
        -q Quiet. Don't display any stats at the end of the trace
        -s Show per-program io statistics
        -t Track individual ios. Will tell you the time a request took
           to get queued, to get dispatched, and to get completed
        -w Only parse data between the given time interval in seconds.
           If 'start' isn't given, blkparse defaults the start time to 0
        -M Do not output messages to binary file
        -v More verbose for marginal errors
        -V Print program version info

摺疊

btt選項如下,常用的使用有

  • -i input #輸入文件
root@a1000:~# btt -h
Usage: btt
[ -a               | --seek-absolute ]
[ -A               | --all-data ]
[ -B <output name> | --dump-blocknos=<output name> ]
[ -d <seconds>     | --range-delta=<seconds> ]
[ -D <dev;...>     | --devices=<dev;...> ]
[ -e <exe,...>     | --exes=<exe,...>  ]
[ -h               | --help ]
[ -i <input name>  | --input-file=<input name> ]
[ -I <output name> | --iostat=<output name> ]
[ -l <output name> | --d2c-latencies=<output name> ]
[ -L <freq>        | --periodic-latencies=<freq> ]
[ -m <output name> | --seeks-per-second=<output name> ]
[ -M <dev map>     | --dev-maps=<dev map>
[ -o <output name> | --output-file=<output name> ]
[ -p <output name> | --per-io-dump=<output name> ]
[ -P <output name> | --per-io-trees=<output name> ]
[ -q <output name> | --q2c-latencies=<output name> ]
[ -Q <output name> | --active-queue-depth=<output name> ]
[ -r               | --no-remaps ]
[ -s <output name> | --seeks=<output name> ]
[ -S <interval>    | --iostat-interval=<interval> ]
[ -t <sec>         | --time-start=<sec> ]
[ -T <sec>         | --time-end=<sec> ]
[ -u <output name> | --unplug-hist=<output name> ]
[ -V               | --version ]
[ -v               | --verbose ]
[ -X               | --easy-parse-avgs ]
[ -z <output name> | --q2d-latencies=<output name> ]
[ -Z               | --do-active

4. 實例

  1. 對/dev/nvme0n1p1進行採集,隨後執行dd命令。
root@a1000:~# blktrace -d /dev/nvme0n1p1&
[1] 418
root@a1000:~# dd of=/dev/null if=/dev/nvme0n1p1 bs=1M count=512
512+0 records in
512+0 records out
536870912 bytes (537 MB, 512 MiB) copied, 0.74305 s, 723 MB/s
root@a1000:~# kill -9 418
[1]+  Killed                  blktrace -d /dev/nvme0n1p1

  1. 利用blkparse對blktrace採集的文件進行解析,其中-d 是輸出二進制文件,方便btt分析,-o 是將blkparse解析的數據放入nvme_data中,可自行分析。
root@a1000:~# ls -lh nvme0n1p1.blktrace.0
-rw-r--r-- 1 root root 8.0M Jan 18 17:10 nvme0n1p1.blktrace.0
root@a1000:~# blkparse -i nvme0n1p1 -d nvme.blktrace.bin -o nvme_data
Input file nvme0n1p1.blktrace.0 added
Bad magic 0

nvme_data原始數據內容如下:
image

  1. btt解析nvme.blktrace.bin
root@a1000:~# btt -i nvme.blktrace.bin
==================== All Devices ====================

            ALL           MIN           AVG           MAX           N
--------------- ------------- ------------- ------------- -----------

Q2Q               0.000151718   0.000393516   0.009215535        2912
Q2G               0.000002172   0.000002721   0.000030020        2912
D2C               0.000366797   0.000482912   0.000821314        2911
Q2C               0.000381274   0.000497561   0.000835603        2911

==================== Device Overhead ====================

       DEV |       Q2G       G2I       Q2M       I2D       D2C
---------- | --------- --------- --------- --------- ---------
 (259,  3) |   0.5470%   0.0000%   0.0000%   0.0000%  97.0557%
---------- | --------- --------- --------- --------- ---------
   Overall |   0.5470%   0.0000%   0.0000%   0.0000%  97.0557%

==================== Device Merge Information ====================

       DEV |       #Q       #D   Ratio |   BLKmin   BLKavg   BLKmax    Total
---------- | -------- -------- ------- | -------- -------- -------- --------
 (259,  3) |     2913     2912     1.0 |      256      255      256   745216

==================== Device Q2Q Seek Information ====================

       DEV |          NSEEKS            MEAN          MEDIAN | MODE
---------- | --------------- --------------- --------------- | ---------------
 (259,  3) |            2913             0.7               0 | 0(2912)
---------- | --------------- --------------- --------------- | ---------------
   Overall |          NSEEKS            MEAN          MEDIAN | MODE
   Average |            2913             0.7               0 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章