How do I view the information the process of IO to read and write on linux?

Linux Kernel 2.6.20 kernel support for the process of more than IO statistics, can use such tools like iotop each process to monitor the situation on the IO operation, just as with the top real-time view process memory, CPU and so take the case in.  But for Linux kernel version 2.6.20 the following not so lucky, according to Stack Overflow of Replies in this way is given, VPSee Python to write a simple script that is used in linux kernel <2.6.20 the printing process under the IO condition .

Kernel < 2.6.20 Kernel <2.6.20

This idea is very simple script to redirect the results of dmesg to a file and then parse out the process once every 1 second to print the statistics IO read and write, execute this script needs root:

 

#!/usr/bin/python
# Monitoring per-process disk I/O activity
# written by Jason

import sys, os, time, signal, re

class DiskIO:
def __init__(self, pname=None, pid=None, reads=0, writes=0):
self.pname = pname
self.pid = pid
self.reads = 0
self.writes = 0

def main():
argc = len(sys.argv)
if argc != 1:
print “usage: ./iotop”
sys.exit(0)

if os.getuid() != 0:
print “must be run as root”
sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)
os.system(‘echo 1 > /proc/sys/vm/block_dump’)
print “TASK              PID       READ      WRITE”
while True:
os.system(‘dmesg -c > /tmp/diskio.log’)
l = []
f = open(‘/tmp/diskio.log’, ‘r’)
line = f.readline()
while line:
m = re.match(\
‘^(\S+)\((\d+)\): (READ|WRITE) block (\d+) on (\S+)’, line)
if m != None:
if not l:
l.append(DiskIO(m.group(1), m.group(2)))
line = f.readline()
continue
found = False
for item in l:
if item.pid == m.group(2):
found = True
if m.group(3) == “READ”:
item.reads = item.reads + 1
elif m.group(3) == “WRITE”:
item.writes = item.writes + 1
if not found:
l.append(DiskIO(m.group(1), m.group(2)))
line = f.readline()
time.sleep(1)
for item in l:
print “%-10s %10s %10d %10d” % \
(item.pname, item.pid, item.reads, item.writes)

def signal_handler(signal, frame):
os.system(‘echo 0 > /proc/sys/vm/block_dump’)
sys.exit(0)

if __name__==”__main__”:
main()

Kernel> = 2.6.20

If you want to use IO iotop process real-time view the status of activities, then, need to download and upgrade the new kernel (2.6.20 or later).  Compile a new kernel need to open TASK_DELAY_ACCT and TASK_IO_ACCOUNTING options.  Extract the kernel into the configuration interface:

# tar jxvf linux-2.6.30.5.tar.bz2
# mv linux-2.6.30.5 /usr/src/
# cd /usr/src/linux-2.6.30.5

# make menuconfig

Select Kernel hacking -> Collect scheduler debugging info and Collect scheduler statistics, save compile the kernel after kernel:

# Make; make modules; make modules_install; make install

Modify grub, start a new kernel recognized correctly:

# Vi / boot / grub / menu.lst

Out of the new kernel outside, iotop also need to run Python 2.5 or above, so if the current Python 2.4, then you need to download and install the latest Python package.  Compile and install using the source code here:

# Tar jxvf Python-2.6.2.tar.bz2
# cd Python-2.6.2 # Cd Python-2.6.2
# ./configure
#. / Configure # make; make install
# Make; make install

Do not forget to download setuptools:

# Mv setuptools-0.6c9-py2.6.egg.sh setuptools-0.6c9-py2.6.egg # sh setuptools-0.6c9-py2.6.egg # Sh setuptools-0.6c9-py2.6.egg

More

If you want to know more about block_dump information, you can look at this process in real-time Linux IO monitoring the situation .  When using block_dump is best to turn off klogd process.

Leave a Reply