Skip to content

Commit

Permalink
#357: does not support cpu_num() on Net and Open BSD
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Nov 26, 2016
1 parent d7aed98 commit 4b52141
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Expand Up @@ -837,7 +837,7 @@ Process class
+------------------------------+-------------------------------+------------------------------+------------------------------+--------------------------+
| :meth:`memory_maps` | | | | |
+------------------------------+-------------------------------+------------------------------+------------------------------+--------------------------+
| *speedup: +2.5x* | *speedup: +1.8x / +6.5x* | *speedup: +1.9x* | *speedup: +2.0x* | *speedup: +1.3x* |
| *speedup: +2.6x* | *speedup: +1.8x / +6.5x* | *speedup: +1.9x* | *speedup: +2.0x* | *speedup: +1.3x* |
+------------------------------+-------------------------------+------------------------------+------------------------------+--------------------------+

.. versionadded:: 5.0.0
Expand Down
7 changes: 4 additions & 3 deletions psutil/_psbsd.py
Expand Up @@ -590,9 +590,10 @@ def cpu_times(self):
rawtuple[kinfo_proc_map['ch_user_time']],
rawtuple[kinfo_proc_map['ch_sys_time']])

@wrap_exceptions
def cpu_num(self):
return self.oneshot()[kinfo_proc_map['cpunum']]
if FREEBSD:
@wrap_exceptions
def cpu_num(self):
return self.oneshot()[kinfo_proc_map['cpunum']]

@wrap_exceptions
def memory_info(self):
Expand Down
8 changes: 8 additions & 0 deletions psutil/_psutil_bsd.c
Expand Up @@ -258,13 +258,21 @@ psutil_proc_oneshot_info(PyObject *self, PyObject *args) {
memstack = (long)kp.p_vm_ssize * pagesize;
#endif

#ifdef __FreeBSD__
// what CPU we're on; top was used as an example:
// https://svnweb.freebsd.org/base/head/usr.bin/top/machine.c?
// view=markup&pathrev=273835
if (kp.ki_stat == SRUN && kp.ki_oncpu != NOCPU)
oncpu = kp.ki_oncpu;
else
oncpu = kp.ki_lastcpu;
#else
// On Net/OpenBSD we have kp.p_cpuid but it appears it's always
// set to KI_NOCPU. Even if it's not, ki_lastcpu does not exist
// so there's no way to determine where "sleeping" processes
// were. Not supported.
oncpu = -1;
#endif

// Return a single big tuple with all process info.
py_retlist = Py_BuildValue(
Expand Down
7 changes: 5 additions & 2 deletions scripts/internal/bench_oneshot.py
Expand Up @@ -37,10 +37,11 @@

if psutil.LINUX:
names += [
'cpu_times',
'gids',
# 'memory_full_info',
# 'memory_maps',
'cpu_num',
'cpu_times',
'gids',
'name',
'num_ctx_switches',
'num_threads',
Expand All @@ -63,6 +64,8 @@
'terminal',
'uids',
]
if psutil.FREEBSD:
names.append('cpu_num')
elif psutil.SUNOS:
names += [
'cmdline',
Expand Down

0 comments on commit 4b52141

Please sign in to comment.