Skip to content

Commit

Permalink
AIX support (#1123)
Browse files Browse the repository at this point in the history
* AIX support

* AIX support

* AIX support

* AIX support - use get_procfs_path() instead of /proc

* AIX support - group sections like in other modules

* AIX support

* AIX support

* AIX support

* AIX support - remove unnecessary dict copy
  • Loading branch information
wiggin15 authored and giampaolo committed Sep 26, 2017
1 parent 730e0fb commit 1ebe625
Show file tree
Hide file tree
Showing 22 changed files with 2,429 additions and 52 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ include psutil/arch/windows/services.h
include psutil/tests/README.rst
include psutil/tests/__init__.py
include psutil/tests/__main__.py
include psutil/tests/test_aix.py
include psutil/tests/test_bsd.py
include psutil/tests/test_connections.py
include psutil/tests/test_contracts.py
Expand Down
74 changes: 43 additions & 31 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ Network
| ``"all"`` | the sum of all the possible families and protocols |
+----------------+-----------------------------------------------------+

On OSX this function requires root privileges.
On OSX and AIX this function requires root privileges.
To get per-process connections use :meth:`Process.connections`.
Also, see
`netstat.py sample script <https://github.com/giampaolo/psutil/blob/master/scripts/netstat.py>`__.
Expand All @@ -563,6 +563,10 @@ Network
(OSX) :class:`psutil.AccessDenied` is always raised unless running as root.
This is a limitation of the OS and ``lsof`` does the same.

.. note::
(AIX) :class:`psutil.AccessDenied` is always raised unless running as root
(lsof does the same).

.. note::
(Solaris) UNIX sockets are not supported.

Expand Down Expand Up @@ -1358,7 +1362,7 @@ Process class
>>> p.io_counters()
pio(read_count=454556, write_count=3456, read_bytes=110592, write_bytes=0, read_chars=769931, write_chars=203)

Availability: all platforms except OSX and Solaris
Availability: Linux, BSD, Windows, AIX

.. versionchanged:: 5.2.0 added *read_chars* and *write_chars* on Linux;
added *other_count* and *other_bytes* on Windows.
Expand All @@ -1368,6 +1372,8 @@ Process class
The number voluntary and involuntary context switches performed by
this process (cumulative).

Availability: all platforms except AIX

.. method:: num_fds()

The number of file descriptors currently opened by this process
Expand Down Expand Up @@ -1503,33 +1509,33 @@ Process class
The "portable" fields available on all plaforms are `rss` and `vms`.
All numbers are expressed in bytes.

+---------+---------+-------+---------+------------------------------+
| Linux | OSX | BSD | Solaris | Windows |
+=========+=========+=======+=========+==============================+
| rss | rss | rss | rss | rss (alias for ``wset``) |
+---------+---------+-------+---------+------------------------------+
| vms | vms | vms | vms | vms (alias for ``pagefile``) |
+---------+---------+-------+---------+------------------------------+
| shared | pfaults | text | | num_page_faults |
+---------+---------+-------+---------+------------------------------+
| text | pageins | data | | peak_wset |
+---------+---------+-------+---------+------------------------------+
| lib | | stack | | wset |
+---------+---------+-------+---------+------------------------------+
| data | | | | peak_paged_pool |
+---------+---------+-------+---------+------------------------------+
| dirty | | | | paged_pool |
+---------+---------+-------+---------+------------------------------+
| | | | | peak_nonpaged_pool |
+---------+---------+-------+---------+------------------------------+
| | | | | nonpaged_pool |
+---------+---------+-------+---------+------------------------------+
| | | | | pagefile |
+---------+---------+-------+---------+------------------------------+
| | | | | peak_pagefile |
+---------+---------+-------+---------+------------------------------+
| | | | | private |
+---------+---------+-------+---------+------------------------------+
+---------+---------+-------+---------+-----+------------------------------+
| Linux | OSX | BSD | Solaris | AIX | Windows |
+=========+=========+=======+=========+=====+==============================+
| rss | rss | rss | rss | rss | rss (alias for ``wset``) |
+---------+---------+-------+---------+-----+------------------------------+
| vms | vms | vms | vms | vms | vms (alias for ``pagefile``) |
+---------+---------+-------+---------+-----+------------------------------+
| shared | pfaults | text | | | num_page_faults |
+---------+---------+-------+---------+-----+------------------------------+
| text | pageins | data | | | peak_wset |
+---------+---------+-------+---------+-----+------------------------------+
| lib | | stack | | | wset |
+---------+---------+-------+---------+-----+------------------------------+
| data | | | | | peak_paged_pool |
+---------+---------+-------+---------+-----+------------------------------+
| dirty | | | | | paged_pool |
+---------+---------+-------+---------+-----+------------------------------+
| | | | | | peak_nonpaged_pool |
+---------+---------+-------+---------+-----+------------------------------+
| | | | | | nonpaged_pool |
+---------+---------+-------+---------+-----+------------------------------+
| | | | | | pagefile |
+---------+---------+-------+---------+-----+------------------------------+
| | | | | | peak_pagefile |
+---------+---------+-------+---------+-----+------------------------------+
| | | | | | private |
+---------+---------+-------+---------+-----+------------------------------+

- **rss**: aka "Resident Set Size", this is the non-swapped physical
memory a process has used.
Expand Down Expand Up @@ -1700,7 +1706,7 @@ Process class
pmmap_ext(addr='02829000-02ccf000', perms='rw-p', path='[heap]', rss=4743168, size=4874240, pss=4743168, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=4743168, referenced=4718592, anonymous=4743168, swap=0),
...]

Availability: All platforms except OpenBSD and NetBSD.
Availability: All platforms except OpenBSD, NetBSD and AIX.

.. method:: children(recursive=False)

Expand Down Expand Up @@ -1864,6 +1870,10 @@ Process class

.. versionchanged:: 5.3.0 : "laddr" and "raddr" are named tuples.

.. note::
(AIX) :class:`psutil.AccessDenied` is always raised unless running
as root (lsof does the same).

.. method:: is_running()

Return whether the current process is running in the current process list.
Expand Down Expand Up @@ -2101,16 +2111,18 @@ Constants
.. data:: OPENBSD
.. data:: BSD
.. data:: SUNOS
.. data:: AIX

``bool`` constants which define what platform you're on. E.g. if on Windows,
:const:`WINDOWS` constant will be ``True``, all others will be ``False``.

.. versionadded:: 4.0.0
.. versionchanged:: 5.4.0 added AIX

.. _const-procfs_path:
.. data:: PROCFS_PATH

The path of the /proc filesystem on Linux and Solaris (defaults to
The path of the /proc filesystem on Linux, Solaris and AIX (defaults to
``"/proc"``).
You may want to re-set this constant right after importing psutil in case
your /proc filesystem is mounted elsewhere or if you want to retrieve
Expand Down
16 changes: 16 additions & 0 deletions psutil/TODO.aix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
AIX support is experimental at this time.
The following functions and methods are unsupported on the AIX platform:

psutil.Process.memory_maps
psutil.Process.num_ctx_switches

Known limitations:
psutil.Process.io_counters read count is always 0
reading basic process info may fail or return incorrect values when process is starting
(see IBM APAR IV58499 - fixed in newer AIX versions)
sockets and pipes may not be counted in num_fds (fixed in newer AIX versions)

The following unit tests may fail:
test_prog_w_funky_name funky name tests don't work, name is truncated
test_cmdline long args are cut from cmdline in /proc/pid/psinfo and getargs
test_pid_exists_2 there are pids in /proc that don't really exist
25 changes: 17 additions & 8 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from ._common import NIC_DUPLEX_HALF
from ._common import NIC_DUPLEX_UNKNOWN

from ._common import AIX
from ._common import BSD
from ._common import FREEBSD # NOQA
from ._common import LINUX
Expand Down Expand Up @@ -158,6 +159,13 @@
# _pssunos.py via sys.modules.
PROCFS_PATH = "/proc"

elif AIX:
from . import _psaix as _psplatform

# This is public API and it will be retrieved from _pslinux.py
# via sys.modules.
PROCFS_PATH = "/proc"

else: # pragma: no cover
raise NotImplementedError('platform %s is not supported' % sys.platform)

Expand Down Expand Up @@ -185,7 +193,7 @@
"POWER_TIME_UNKNOWN", "POWER_TIME_UNLIMITED",

"BSD", "FREEBSD", "LINUX", "NETBSD", "OPENBSD", "OSX", "POSIX", "SUNOS",
"WINDOWS",
"WINDOWS", "AIX",

# classes
"Process", "Popen",
Expand Down Expand Up @@ -785,7 +793,7 @@ def num_fds(self):
"""
return self._proc.num_fds()

# Linux, BSD and Windows only
# Linux, BSD, AIX and Windows only
if hasattr(_psplatform.Process, "io_counters"):

def io_counters(self):
Expand Down Expand Up @@ -890,11 +898,13 @@ def num_handles(self):
"""
return self._proc.num_handles()

def num_ctx_switches(self):
"""Return the number of voluntary and involuntary context
switches performed by this process.
"""
return self._proc.num_ctx_switches()
if hasattr(_psplatform.Process, "num_ctx_switches"):

def num_ctx_switches(self):
"""Return the number of voluntary and involuntary context
switches performed by this process.
"""
return self._proc.num_ctx_switches()

def num_threads(self):
"""Return the number of threads used by this process."""
Expand Down Expand Up @@ -1171,7 +1181,6 @@ def memory_percent(self, memtype="rss"):

if hasattr(_psplatform.Process, "memory_maps"):
# Available everywhere except OpenBSD and NetBSD.

def memory_maps(self, grouped=True):
"""Return process' mapped memory regions as a list of namedtuples
whose fields are variable depending on the platform.
Expand Down
1 change: 1 addition & 0 deletions psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
NETBSD = sys.platform.startswith("netbsd")
BSD = FREEBSD or OPENBSD or NETBSD
SUNOS = sys.platform.startswith("sunos") or sys.platform.startswith("solaris")
AIX = sys.platform.startswith("aix")


# ===================================================================
Expand Down
Loading

0 comments on commit 1ebe625

Please sign in to comment.