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

AIX support #1123

Merged
merged 9 commits into from
Sep 26, 2017
Merged
Show file tree
Hide file tree
Changes from 5 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
72 changes: 41 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 @@ -2110,7 +2120,7 @@ Constants
.. _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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add the new AIX constant in the doc and mark it as .. versionadded:: 5.4.0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs have a section called .. _const-oses:. Is it ok if I add AIX to this section with:

.. versionchanged:: 5.4.0 added AIX

in order to keep this const in the same group as the rest?

Expand Down
25 changes: 25 additions & 0 deletions psutil/TODO.aix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
AIX support is experimental and incomplete at this time.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just say it's experimental at this point, but not incomplete.

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
psutil.cpu_stats ctx_switches and soft_interrupts are always 0

The following unit tests may fail:
test_fetch_all `cwd` can return None (also on Solaris)
test_proc_cmdline unicode name tests don't work, name is empty (also on Solaris)
test_proc_exe unicode name tests don't work, name is empty (also on Solaris)
test_proc_name unicode name tests don't work, name is empty (also on Solaris)
test_prog_w_funky_name funky name tests don't work, name is empty (also on Solaris)
test_setup_script TBD (also on Solaris)
test_cmdline long args are cut from cmdline in /proc/pid/psinfo and getargs
test_io_counters io_counters read count is always 0
test_zombie_process trying to create a zombie process doesn't create a zombie process on AIX
test_create_zombie_proc trying to create a zombie process doesn't create a zombie process on AIX
test_procinfo missing API
test_cpu_stats cpu_stats always returns ctx_switches=0
test_disk_usage df returns "-" for all procfs fields but API returns something real
test_pid_exists_2 there are pids in /proc that don't really exist
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still worries me and should be discussed. I suppose I'll have a better idea of what this means once I look at the test results.

24 changes: 16 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,12 @@ 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 not AIX:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using if hasattr(_psplatform.Process, "num_ctx_switches"): instead

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 +1180,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