zoukankan      html  css  js  c++  java
  • How to find per-process I/O statistics on Linux

    以下转自http://www.xaprb.com/blog/2009/08/23/how-to-find-per-process-io-statistics-on-linux/

    Newer Linux kernels have per-process I/O accounting and you can use the iotop tool to find out what’s performing I/O, but in many cases I’m trying to find the source of an I/O problem in an older kernel. I found sort of a hack-ish way to do that today, while trying to figure out why a system was basically unresponsive.

    I found a post on Stack Overflow that showed a way you can get per process I/O statistics from the kernel even in older kernels. I adapted this to my needs, and wrote a little script.

    Here’s how you use it. First, get it:

    wget http://aspersa.googlecode.com/svn/trunk/iodump
    

    Then turn on kernel messages about I/O:

    echo 1 > /proc/sys/vm/block_dump
    

    This makes the kernel start writing messages about every I/O operation that takes place. Now all you have to do is get those messages and feed them into my script:

    while true; do sleep 1; dmesg -c; done | perl iodump
    

    Wait a little while, then cancel the script. The results should look something like the following:

    root@kanga:~# while true; do sleep 1; dmesg -c; done | perl iodump
    ^C# Caught SIGINT.
    TASK                   PID      TOTAL       READ      WRITE      DIRTY DEVICES
    firefox               4450       4538        251       4287          0 sda4, sda3
    kjournald             2100        551          0        551          0 sda4
    firefox              28452        185        185          0          0 sda4
    kjournald              782         59          0         59          0 sda3
    pdflush                 31         30          0         30          0 sda4, sda3
    syslogd               2485          2          0          2          0 sda3
    firefox              28414          2          2          0          0 sda4, sda3
    firefox              28413          1          1          0          0 sda4
    firefox              28410          1          1          0          0 sda4
    firefox              28307          1          1          0          0 sda4
    firefox              28451          1          1          0          0 sda4
    

    I deliberately generated a bunch of I/O by deleting my Firefox history and cache.

    Add by huangbt:)

    #!/bin/sh
     
    while :
    do
    #echo "1" > /proc/sys/vm/block_dump
    exec 6>&1 1>/tmp/iomon.log
    dmesg | egrep "READ|WRITE|dirtied" | awk '{print $1,$2,$3,$4,$NF}' | sort
    exec 1>&6 6>&-
    dmesg | egrep "READ|WRITE|dirtied" | awk '{print $1,$2,$NF}' | sort | uniq -c | sort -rn | head|awk 'BEGIN{print "COUNTS COMMAND(PID) I/O DEVICE"}{print}'|column -t
    #echo "0" > /proc/sys/vm/block_dump
    sleep 1
    clear
    done
  • 相关阅读:
    第四章例4-5
    第四章例4-4
    修改oracle 客户端PL/SQL 的路径问题
    解决div float后,父div高度无法自适应的问题
    include与jsp:include与s:action与s:include与iframe用法汇总
    解决js中onMouseOut事件冒泡的问题
    strut2配置action class 问题
    html块级元素与行内元素
    Tomcat 启动不了的问题
    oracle远程导入导出
  • 原文地址:https://www.cnblogs.com/hbt19860104/p/3469268.html
Copyright © 2011-2022 走看看