Skip to content

Commit

Permalink
fix #965: disk_io_counters() may miscalculate sector size and report …
Browse files Browse the repository at this point in the history
…the wrong number of bytes read and written
  • Loading branch information
giampaolo committed Feb 2, 2017
1 parent 892a55b commit 8815aac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

- 964_: [Windows] Process.username() and psutil.users() may return badly
decoding character on Python 3.
- 965_: [Linux] disk_io_counters() may miscalculate sector size and report the
wrong number of bytes read and written.

5.1.0
=====
Expand Down
12 changes: 5 additions & 7 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ def file_flags_to_mode(flags):
return mode


def get_sector_size():
def get_sector_size(partition):
try:
with open(b"/sys/block/sda/queue/hw_sector_size") as f:
with open(b"/sys/block/%s/queue/hw_sector_size" % partition) as f:
return int(f.read())
except (IOError, ValueError):
# man iostat states that sectors are equivalent with blocks and
Expand All @@ -254,9 +254,6 @@ def get_sector_size():
return 512


SECTOR_SIZE = get_sector_size()


@memoize
def set_scputimes_ntuple(procfs_path):
"""Return a namedtuple of variable fields depending on the
Expand Down Expand Up @@ -1027,8 +1024,9 @@ def get_partitions():
raise ValueError("not sure how to interpret line %r" % line)

if name in partitions:
rbytes = rbytes * SECTOR_SIZE
wbytes = wbytes * SECTOR_SIZE
sector_size = get_sector_size(name)
rbytes = rbytes * sector_size
wbytes = wbytes * sector_size
retdict[name] = (reads, writes, rbytes, wbytes, rtime, wtime,
reads_merged, writes_merged, busy_time)
return retdict
Expand Down

0 comments on commit 8815aac

Please sign in to comment.