[英]Calculate Total disk i/o by a single process
I am looking for some tool that will dump total disk I/O by a single process after it ends.我正在寻找一些工具,它会在它结束后通过单个进程转储总磁盘 I/O。 So far my finding is:-
到目前为止,我的发现是:-
For example , I have some process running in background with PID ####.例如,我有一些进程在后台运行,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.
在进程结束后,我需要该进程写入和读取的总字节数。任何人都可以告诉我如何在给定进程 PID 的情况下提取这些信息。
Feel free to play with this scribble (myio.sh): 随意玩此涂鸦(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
Syntax: ./myio.sh <your command>
语法:
./myio.sh <your command>
Examples: 例子:
./myio.sh dd if=/dev/zero of=/dev/null bs=1G count=4096
./myio.sh dd if=/dev/sda1 of=/dev/null bs=1M count=4096
./myio.sh dd if=/dev/sda1 of=/dev/null bs=1M count=4096
Please change dd's of=
in last example only if you know what you are doing. 仅当您知道自己在做什么时,才在上一个示例中更改dd的
of=
。
With this simple script from me you can watch an already running process and its IO. 使用我提供的这个简单脚本,您可以观看一个已经在运行的进程及其IO。
Syntax: pio.sh PID
语法:
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
@Cyrus, @赛勒斯,
the unit for syscr and syswr is wrong, as it is not MByte/s but "operations/s" syscr 和 syswr 的单位是错误的,因为它不是 MByte/s 而是“操作/s”
rchar: number of bytes the process read, using any read-like system call (from files, pipes, tty...).
wchar: number of bytes the process wrote using any write-like system call.
syscr: number of read-like system call invocations that the process performed.
syscr: number of write-like system call invocations that the process performed.
read_bytes: number of bytes the process directly read from disk.
write_bytes: number of bytes the process originally dirtied in the page-cache (assuming they will go to disk later).
cancelled_write_bytes: number of bytes the process "un-dirtied" - e.g. using an "ftruncate" call that truncated pages from the page-cache.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.