Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add total time field to disk_io_counters() #523

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def isfile_strict(path):
# psutil.disk_io_counters()
sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
'read_bytes', 'write_bytes',
'read_time', 'write_time'])
'read_time', 'write_time',
'tot_time'])
# psutil.disk_partitions()
sdiskpart = namedtuple('sdiskpart', ['device', 'mountpoint', 'fstype', 'opts'])
# psutil.net_io_counters()
Expand Down
8 changes: 5 additions & 3 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,16 +638,18 @@ def disk_io_counters():
f.close()
for line in lines:
# http://www.mjmwired.net/kernel/Documentation/iostats.txt
_, _, name, reads, _, rbytes, rtime, writes, _, wbytes, wtime = \
line.split()[:11]
_, _, name, reads, _, rbytes, rtime, writes, _, wbytes, wtime, _, tot_time = \
line.split()[:13]
if name in partitions:
rbytes = int(rbytes) * SECTOR_SIZE
wbytes = int(wbytes) * SECTOR_SIZE
reads = int(reads)
writes = int(writes)
rtime = int(rtime)
wtime = int(wtime)
retdict[name] = (reads, writes, rbytes, wbytes, rtime, wtime)
tot_time = int(tot_time)
retdict[name] = (reads, writes, rbytes, wbytes, rtime, wtime,
tot_time)
return retdict


Expand Down
2 changes: 2 additions & 0 deletions test/test_psutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1050,12 +1050,14 @@ def check_ntuple(nt):
self.assertEqual(nt[3], nt.write_bytes)
self.assertEqual(nt[4], nt.read_time)
self.assertEqual(nt[5], nt.write_time)
self.assertEqual(nt[6], nt.tot_time)
assert nt.read_count >= 0, nt
assert nt.write_count >= 0, nt
assert nt.read_bytes >= 0, nt
assert nt.write_bytes >= 0, nt
assert nt.read_time >= 0, nt
assert nt.write_time >= 0, nt
assert nt.tot_time >= 0, nt

ret = psutil.disk_io_counters(perdisk=False)
check_ntuple(ret)
Expand Down