我正在寻找一些工具,它将在结束后通过单个进程转储整个磁盘I / O.
到目前为止,我的发现是: –
> iotop =它实时显示每个进程的i / o但不给出
过程结束后的总数.
> iostat =显示实时I / O但是
不告诉过程
例如,我有一些进程在后台运行PID ####.在流程结束后,我需要在整个流程中编写和读取总字节数.任何人都可以告诉我如何在给定流程PID的情况下提取此信息.最佳答案随意玩这个涂鸦(myio.sh):
#!/bin/bash TEMPfile=$(tempfile) # create temp file for resultstrap "rm $TEMPfile; exit 1" SIGINT # cleanup after Ctrl+CSECONDS=0 # reset timer$@ & # execute command in backgroundIO=/proc/$!/io # io data of commandwhile [ -e $IO ]; do cat $IO > "$TEMPfile" # "copy" data sed 's/.*/& Bytes/' "$TEMPfile" | column -t echo sleep 1doneS=$SECONDS # save timerecho -e "\nPerformace after $S seconds:"while IFS=" " read string value; do echo $string $(($value/1024/1024/$S)) MByte/sdone < "$TEMPfile" | column -trm "$TEMPfile" # remove temp file
语法:./ myio.sh< your command>
例子:
> ./myio.sh dd if = / dev / zero of = / dev / null bs = 1G count = 4096
>以root身份:./ myio.sh dd if = / dev / sda1 of = / dev / null bs = 1M count = 4096
只有在您知道自己在做什么的情况下,才能在最后一个示例中更改=的dd.
通过我的这个简单脚本,您可以观看已经运行的进程及其IO.
语法:pio.sh PID
#!/bin/bash[ "" == "" ] && echo "Error: Missing PID" && exit 1IO=/proc//io # io data of PID[ ! -e "$IO" ] && echo "Error: PID does not exist" && exit 2I=3 # interval in secondsSECONDS=0 # reset timerecho "Watching command $(cat /proc//comm) with PID "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 ] && continuecat << EOFrchar: $((($rchart-$rchar)/1024/1024/$S)) MByte/swchar: $((($wchart-$wchar)/1024/1024/$S)) MByte/ssyscr: $((($syscrt-$syscr)/1024/1024/$S)) MByte/ssyscw: $((($syscwt-$syscw)/1024/1024/$S)) MByte/sread_bytes: $((($rbytest-$rbytes)/1024/1024/$S)) MByte/swrite_bytes: $((($wbytest-$wbytest)/1024/1024/$S)) MByte/scancelled_write_bytes: $((($cwbytest-$cwbytes)/1024/1024/$S)) MByte/sEOF echo sleep $Idone
总结 以上是内存溢出为你收集整理的linux – 通过单个进程计算总磁盘i / o全部内容,希望文章能够帮你解决linux – 通过单个进程计算总磁盘i / o所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)