通过一个单一的过程计算总的磁盘I / O [英] Calculate Total disk i/o by a single process

查看:137
本文介绍了通过一个单一的过程计算总的磁盘I / O的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一些工具,它结束后,将由单一的进程转储总的磁盘I / O。
到目前为止,我的结论是: -

I am looking for some tool that will dump total disk I/O by a single process after it ends. So far my finding is :-


  • iotop =这表明I / O每个进程的实时,但不给
    过程结束后总。

  • 的iostat =它显示实时I / O,但
    没有告诉进程

  • iotop= It shows i/o per process in real time but does not give total after process end.
  • iostat= It shows real time I/O but does not tell process

例如的,我有一些过程后台运行具有PID ####。我需要的总字节数的在这个过程之后总该进程ends.Can有人告诉我该怎么给一个进程的PID提取这些信息。

For example, I have some process running in background with PID ####. I need the Total Bytes Written and Read by that process in total after the process ends.Can anybody tell how I can extract this information given a process PID.

推荐答案

随意使用这种潦草(myio.sh)播放:

Feel free to play with this scribble (myio.sh):

#!/bin/bash 

TEMPFILE=$(tempfile)    # create temp file for results

trap "rm $TEMPFILE; exit 1" SIGINT  # cleanup after Ctrl+C

SECONDS=0               # reset timer

$@ &                    # execute command in background

IO=/proc/$!/io          # io data of command
while [ -e $IO ]; do
    cat $IO > "$TEMPFILE"   # "copy" data
    sed 's/.*/& Bytes/' "$TEMPFILE" | column -t
    echo
    sleep 1
done

S=$SECONDS              # save timer

echo -e "\nPerformace after $S seconds:"
while IFS=" " read string value; do
    echo $string $(($value/1024/1024/$S)) MByte/s
done < "$TEMPFILE" | column -t

rm "$TEMPFILE"          # remove temp file

语法: ./ myio.sh&lt;您的命令&GT;

例如:


  • ./ myio.sh DD如果=的/ dev / = /开发/空BS =零1G数= 4096

  • 为根: ./ myio.sh DD如果=的/ dev / null的BS = 1M的=的/ dev / sda1的数= 4096

  • ./myio.sh dd if=/dev/zero of=/dev/null bs=1G count=4096
  • as root: ./myio.sh dd if=/dev/sda1 of=/dev/null bs=1M count=4096

请改变DD的的= 去年示例只,如果你知道自己在做什么。

Please change dd's of= in last example only if you know what you are doing.

从我这个简单的脚本,你可以看一个已经运行的过程和它的IO。

With this simple script from me you can watch an already running process and its IO.

语法: pio.sh PID

#!/bin/bash

[ "$1" == "" ] && echo "Error: Missing PID" && exit 1
IO=/proc/$1/io          # io data of PID
[ ! -e "$IO" ] && echo "Error: PID does not exist" && exit 2
I=3                     # interval in seconds
SECONDS=0               # reset timer

echo "Watching command $(cat /proc/$1/comm) with PID $1"

IFS=" " read rchar wchar syscr syscw rbytes wbytes cwbytes < <(cut -d " " -f2 $IO | tr "\n" " ")

while [ -e $IO ]; do
    IFS=" " read rchart wchart syscrt syscwt rbytest wbytest cwbytest < <(cut -d " " -f2 $IO | tr "\n" " ")

    S=$SECONDS
    [ $S -eq 0 ] && continue

cat << EOF
rchar:                 $((($rchart-$rchar)/1024/1024/$S)) MByte/s
wchar:                 $((($wchart-$wchar)/1024/1024/$S)) MByte/s
syscr:                 $((($syscrt-$syscr)/1024/1024/$S)) MByte/s
syscw:                 $((($syscwt-$syscw)/1024/1024/$S)) MByte/s
read_bytes:            $((($rbytest-$rbytes)/1024/1024/$S)) MByte/s
write_bytes:           $((($wbytest-$wbytest)/1024/1024/$S)) MByte/s
cancelled_write_bytes: $((($cwbytest-$cwbytes)/1024/1024/$S)) MByte/s
EOF
    echo
    sleep $I
done

这篇关于通过一个单一的过程计算总的磁盘I / O的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆