Skip to content

Commit

Permalink
#523 / disk_io_counters / OpenBSD: add busy_time field
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jan 13, 2016
1 parent 459f0db commit 4bec7e4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues

**Enhancements**

- #523: [Linux] disk_io_counters() return a new "busy_time" field.
- #523: [Linux, BSD] disk_io_counters() return a new "busy_time" field.
- #660: [Windows] make.bat is smarter in finding alternative VS install
locations. (patch by mpderbec)
- #732: Process.environ(). (patch by Frank Benkstein)
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ clean:
rm -rf dist
rm -rf docs/_build
rm -rf htmlcov
find . -type d -empty -delete # remove empty dirs

build: clean
$(PYTHON) setup.py build
Expand Down
13 changes: 9 additions & 4 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,15 @@
'pmmap_grouped', 'path rss, private, ref_count, shadow_count')
pmmap_ext = namedtuple(
'pmmap_ext', 'addr, perms path rss, private, ref_count, shadow_count')
sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
'read_bytes', 'write_bytes',
'read_time', 'write_time',
'busy_time'])
if FREEBSD:
sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
'read_bytes', 'write_bytes',
'read_time', 'write_time',
'busy_time'])
else:
sdiskio = namedtuple('sdiskio', ['read_count', 'write_count',
'read_bytes', 'write_bytes',
'busy_time'])

# set later from __init__.py
NoSuchProcess = None
Expand Down
15 changes: 6 additions & 9 deletions psutil/arch/bsd/openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,15 +772,12 @@ psutil_disk_io_counters(PyObject *self, PyObject *args) {

for (i = 0; i < dk_ndrive; i++) {
py_disk_info = Py_BuildValue(
"(KKKKLL)",
stats[i].ds_rxfer,
stats[i].ds_wxfer,
stats[i].ds_rbytes,
stats[i].ds_wbytes,
// assume half read - half writes.
// TODO: why?
(long long) PSUTIL_TV2DOUBLE(stats[i].ds_time) / 2,
(long long) PSUTIL_TV2DOUBLE(stats[i].ds_time) / 2);
"(KKKKL)",
stats[i].ds_rxfer, // num reads
stats[i].ds_wxfer, // num writes
stats[i].ds_rbytes, // read bytes
stats[i].ds_wbytes, // written bytes
(long long) PSUTIL_TV2DOUBLE(stats[i].ds_time)); // busy time
if (!py_disk_info)
goto error;
if (PyDict_SetItemString(py_retdict, stats[i].ds_name, py_disk_info))
Expand Down
26 changes: 13 additions & 13 deletions psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

import psutil
from psutil import BSD
from psutil import FREEBSD
from psutil import LINUX
from psutil import OPENBSD
from psutil import OSX
from psutil import POSIX
from psutil import SUNOS
Expand Down Expand Up @@ -610,19 +612,17 @@ def check_ntuple(nt):
self.assertEqual(nt[1], nt.write_count)
self.assertEqual(nt[2], nt.read_bytes)
self.assertEqual(nt[3], nt.write_bytes)
self.assertEqual(nt[4], nt.read_time)
self.assertEqual(nt[5], nt.write_time)
if LINUX:
self.assertEqual(nt[6], nt.read_merged_count)
self.assertEqual(nt[7], nt.write_merged_count)
self.assertEqual(nt[8], nt.busy_time)
assert nt.read_merged_count >= 0, nt
assert nt.write_merged_count >= 0, nt
assert nt.busy_time >= 0, nt
elif BSD:
self.assertEqual(nt[6], nt.busy_time)
assert nt.busy_time >= 0, nt

if (OPENBSD or NETBSD):
self.assertEqual(nt[4], nt.busy_time)
else:
self.assertEqual(nt[4], nt.read_time)
self.assertEqual(nt[5], nt.write_time)
if LINUX:
self.assertEqual(nt[6], nt.read_merged_count)
self.assertEqual(nt[7], nt.write_merged_count)
self.assertEqual(nt[8], nt.busy_time)
elif FREEBSD:
self.assertEqual(nt[6], nt.busy_time)
for name in nt._fields:
assert getattr(nt, name) >= 0, nt

Expand Down

0 comments on commit 4bec7e4

Please sign in to comment.