Skip to content

Commit

Permalink
#799 - oneshot: solaris implementation 1.37x speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Aug 5, 2016
1 parent d2aaf8c commit 630b40d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 47 deletions.
70 changes: 38 additions & 32 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -778,38 +778,44 @@ Process class
The last column (speedup) shows an approximation of the speedup you can get
if you collect all this methods together (best case scenario).

+------------------------------+-------------+-------+------------------------------+
| Linux | Windows | OSX | BSD |
+==============================+=============+=======+==============================+
| :meth:`~Process.cpu_percent` | | | :meth:`~Process.cpu_percent` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`~Process.cpu_times` | | | :meth:`~Process.cpu_times` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`create_time` | | | :meth:`create_time` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`name` | | | :meth:`gids` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`ppid` | | | :meth:`io_counters` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`status` | | | :meth:`memory_full_info` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`terminal` | | | :meth:`memory_info` |
+------------------------------+-------------+-------+------------------------------+
| | | | :meth:`memory_percent` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`gids` | | | :meth:`num_ctx_switches` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`num_ctx_switches` | | | :meth:`ppid` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`num_threads` | | | :meth:`status` |
+------------------------------+-------------+-------+------------------------------+
| :meth:`uids` | | | :meth:`terminal` |
+------------------------------+-------------+-------+------------------------------+
| | | | :meth:`uids` |
+------------------------------+-------------+-------+------------------------------+
+------------------------------+-------------+-------+------------------------------+
| *speedup: +2.5x* | | | *speedup: +2x* |
+------------------------------+-------------+-------+------------------------------+

+------------------------------+-------------+-------+------------------------------+--------------------------+
| Linux | Windows | OSX | BSD | SunOS |
+==============================+=============+=======+==============================+==========================+
| :meth:`~Process.cpu_percent` | | | :meth:`~Process.cpu_percent` | :meth:`name` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`~Process.cpu_times` | | | :meth:`~Process.cpu_times` | :meth:`cmdline` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`create_time` | | | :meth:`create_time` | |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`name` | | | :meth:`gids` | :meth:`create_time` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`ppid` | | | :meth:`io_counters` | :meth:`memory_full_info` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`status` | | | :meth:`memory_full_info` | :meth:`memory_info` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`terminal` | | | :meth:`memory_info` | :meth:`memory_percent` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| | | | :meth:`memory_percent` | :meth:`nice` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`gids` | | | :meth:`num_ctx_switches` | :meth:`num_threads` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`num_ctx_switches` | | | :meth:`ppid` | :meth:`ppid` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`num_threads` | | | :meth:`status` | :meth:`status` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| :meth:`uids` | | | :meth:`terminal` | :meth:`terminal` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| | | | :meth:`uids` | |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| | | | | :meth:`gids` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| | | | | :meth:`uids` |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| | | | | |
+------------------------------+-------------+-------+------------------------------+--------------------------+
| *speedup: +2.5x* | | | *speedup: +2x* | |
+------------------------------+-------------+-------+------------------------------+--------------------------+

.. versionadded:: 5.0.0

Expand Down
44 changes: 29 additions & 15 deletions psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from . import _psutil_posix as cext_posix
from . import _psutil_sunos as cext
from ._common import isfile_strict
from ._common import memoize_when_activated
from ._common import sockfam_to_enum
from ._common import socktype_to_enum
from ._common import usage_percent
Expand Down Expand Up @@ -348,15 +349,31 @@ def __init__(self, pid):
self._procfs_path = get_procfs_path()

def oneshot_enter(self):
pass
self._proc_name_and_args.cache_activate()
self._proc_basic_info.cache_activate()
self._proc_cred.cache_activate()

def oneshot_exit(self):
pass
self._proc_name_and_args.cache_deactivate()
self._proc_basic_info.cache_deactivate()
self._proc_cred.cache_deactivate()

@memoize_when_activated
def _proc_name_and_args(self):
return cext.proc_name_and_args(self.pid, self._procfs_path)

@memoize_when_activated
def _proc_basic_info(self):
return cext.proc_basic_info(self.pid, self._procfs_path)

@memoize_when_activated
def _proc_cred(self):
return cext.proc_cred(self.pid, self._procfs_path)

@wrap_exceptions
def name(self):
# note: max len == 15
return cext.proc_name_and_args(self.pid, self._procfs_path)[0]
return self._proc_name_and_args()[0]

@wrap_exceptions
def exe(self):
Expand All @@ -373,16 +390,15 @@ def exe(self):

@wrap_exceptions
def cmdline(self):
return cext.proc_name_and_args(
self.pid, self._procfs_path)[1].split(' ')
return self._proc_name_and_args()[1].split(' ')

@wrap_exceptions
def create_time(self):
return cext.proc_basic_info(self.pid, self._procfs_path)[3]
return self._proc_basic_info()[3]

@wrap_exceptions
def num_threads(self):
return cext.proc_basic_info(self.pid, self._procfs_path)[5]
return self._proc_basic_info()[5]

@wrap_exceptions
def nice_get(self):
Expand Down Expand Up @@ -415,19 +431,17 @@ def nice_set(self, value):

@wrap_exceptions
def ppid(self):
self._ppid = cext.proc_basic_info(self.pid, self._procfs_path)[0]
self._ppid = self._proc_basic_info()[0]
return self._ppid

@wrap_exceptions
def uids(self):
real, effective, saved, _, _, _ = \
cext.proc_cred(self.pid, self._procfs_path)
real, effective, saved, _, _, _ = self._proc_cred()
return _common.puids(real, effective, saved)

@wrap_exceptions
def gids(self):
_, _, _, real, effective, saved = \
cext.proc_cred(self.pid, self._procfs_path)
_, _, _, real, effective, saved = self._proc_cred()
return _common.puids(real, effective, saved)

@wrap_exceptions
Expand All @@ -440,7 +454,7 @@ def terminal(self):
procfs_path = self._procfs_path
hit_enoent = False
tty = wrap_exceptions(
cext.proc_basic_info(self.pid, self._procfs_path)[0])
self._proc_basic_info()[0])
if tty != cext.PRNODEV:
for x in (0, 1, 2, 255):
try:
Expand Down Expand Up @@ -472,15 +486,15 @@ def cwd(self):

@wrap_exceptions
def memory_info(self):
ret = cext.proc_basic_info(self.pid, self._procfs_path)
ret = self._proc_basic_info()
rss, vms = ret[1] * 1024, ret[2] * 1024
return pmem(rss, vms)

memory_full_info = memory_info

@wrap_exceptions
def status(self):
code = cext.proc_basic_info(self.pid, self._procfs_path)[6]
code = self._proc_basic_info()[6]
# XXX is '?' legit? (we're not supposed to return it anyway)
return PROC_STATUSES.get(code, '?')

Expand Down
15 changes: 15 additions & 0 deletions scripts/internal/bench_oneshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@
'terminal',
'uids',
)
elif psutil.SUNOS:
names = (
'cmdline',
'create_time',
'gids',
'memory_full_info',
'memory_info',
'memory_percent',
'name',
'num_threads',
'ppid',
'status',
'terminal',
'uids',
)
else:
raise RuntimeError("platform %r not supported" % sys.platform)

Expand Down

0 comments on commit 630b40d

Please sign in to comment.