Skip to content

Commit

Permalink
#792 / cpu_stats() / linux: add soft_interrupts
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Mar 5, 2016
1 parent 31808c0 commit d4817f2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
40 changes: 20 additions & 20 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,33 +155,33 @@ CPU
Return various CPU statistics as a namedtuple whose fields change depending
on the platform.

+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| Linux | OSX | Windows | SunOS | FreeBSD | OpenBSD | NetBSD |
+===============+==============+==============+==============+============+=============+==============+
| ctx_switches | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| interrupts | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| procs_running | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| procs_blocked | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
+-----------------+--------------+--------------+--------------+------------+-------------+--------------+
| Linux | OSX | Windows | SunOS | FreeBSD | OpenBSD | NetBSD |
+=================+==============+==============+==============+============+=============+==============+
| ctx_switches | | | | | | |
+-----------------+--------------+--------------+--------------+------------+-------------+--------------+
| interrupts | | | | | | |
+-----------------+--------------+--------------+--------------+------------+-------------+--------------+
| soft_interrupts | | | | | | |
+-----------------+--------------+--------------+--------------+------------+-------------+--------------+
| procs_running | | | | | | |
+-----------------+--------------+--------------+--------------+------------+-------------+--------------+
| procs_blocked | | | | | | |
+-----------------+--------------+--------------+--------------+------------+-------------+--------------+
| | | | | | | |
+-----------------+--------------+--------------+--------------+------------+-------------+--------------+
| | | | | | | |
+-----------------+--------------+--------------+--------------+------------+-------------+--------------+
| | | | | | | |
+-----------------+--------------+--------------+--------------+------------+-------------+--------------+

Example (Linux):

.. code-block:: python
>>> import psutil
>>> psutil.cpu_stats()
scpustats(ctx_switches=20455687, interrupts=6598984, procs_running=1, procs_blocked=0)
scpustats(ctx_switches=20455687, interrupts=6598984, soft_interrupts=2134212, procs_running=1, procs_blocked=0)
.. versionadded:: 4.1.0

Expand Down
14 changes: 10 additions & 4 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ def set_scputimes_ntuple(procfs_path):
'read_time', 'write_time',
'read_merged_count', 'write_merged_count',
'busy_time'])
scpustats = namedtuple('scpustats', ['ctx_switches', 'interrupts',
'procs_running', 'procs_blocked'])
scpustats = namedtuple('scpustats',
['ctx_switches', 'interrupts', 'soft_interrupts',
'procs_running', 'procs_blocked'])
popenfile = namedtuple('popenfile',
['path', 'fd', 'position', 'mode', 'flags'])
pmem = namedtuple('pmem', 'rss vms shared text lib data dirty')
Expand Down Expand Up @@ -436,6 +437,7 @@ def cpu_stats():
procs_running = None
procs_blocked = None
interrupts = None
soft_interrupts = None
for line in f:
if line.startswith(b'ctxt'):
ctx_switches = int(line.split()[1])
Expand All @@ -445,10 +447,14 @@ def cpu_stats():
procs_blocked = int(line.split()[1])
elif line.startswith(b'intr'):
interrupts = int(line.split()[1])
elif line.startswith(b'softirq'):
soft_interrupts = int(line.split()[1])
if ctx_switches is not None and procs_running is not None and \
procs_blocked is not None and interrupts is not None:
soft_interrupts is not None and procs_blocked is not None \
and interrupts is not None:
break
return scpustats(ctx_switches, interrupts, procs_running, procs_blocked)
return scpustats(ctx_switches, interrupts, soft_interrupts, procs_running,
procs_blocked)


# --- other system functions
Expand Down

0 comments on commit d4817f2

Please sign in to comment.