Skip to content

Commit

Permalink
#720: sysinfo osx
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Mar 4, 2016
1 parent c9b2ef5 commit a26fa59
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 24 deletions.
48 changes: 24 additions & 24 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -543,37 +543,37 @@ Other system info

ctx_switches, interrupts, nthreads, traps, syscalls

+---------------+---------+--------------+--------------+------------+-------------+--------------+
| Linux | OSX | Windows | SunOS | FreeBSD | OpenBSD | NetBSD |
+===============+=========+==============+==============+============+=============+==============+
| procs_running | | ctx_switches | ctx_switches | max_files | max_files | max_files |
+---------------+---------+--------------+--------------+------------+-------------+--------------+
| procs_blocked | | interrupts | interrupts | max_procs | max_procs | max_procs |
+---------------+---------+--------------+--------------+------------+-------------+--------------+
| ctx_switches | | dpcs | num_threads | max_pid | max_threads | ctx_switches |
+---------------+---------+--------------+--------------+------------+-------------+--------------+
| open_files | | syscalls | traps | open_files | open_files | interrupts |
+---------------+---------+--------------+--------------+------------+-------------+--------------+
| interrupts | | | syscalls | | num_threads | |
+--------+------+---------+--------------+--------------+------------+-------------+--------------+
| max_threads | | | | | | |
+---------------+---------+--------------+--------------+------------+-------------+--------------+
| max_files | | | | | | |
+--------+------+---------+--------------+--------------+------------+-------------+--------------+
| max_pid | | | | | | |
+---------------+---------+--------------+--------------+------------+-------------+--------------+
| max_procs | | | | | | |
+---------------+---------+--------------+--------------+------------+-------------+--------------+
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| Linux | OSX | Windows | SunOS | FreeBSD | OpenBSD | NetBSD |
+===============+==============+==============+==============+============+=============+==============+
| procs_running | ctx_switches | ctx_switches | ctx_switches | max_files | max_files | max_files |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| procs_blocked | interrupts | interrupts | interrupts | max_procs | max_procs | max_procs |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| ctx_switches | syscalls | dpcs | num_threads | max_pid | max_threads | ctx_switches |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| open_files | | syscalls | traps | open_files | open_files | interrupts |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| interrupts | | | syscalls | | num_threads | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| max_threads | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| max_files | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| max_pid | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+
| max_procs | | | | | | |
+---------------+--------------+--------------+--------------+------------+-------------+--------------+

- **procs_running** (Linux): current number of actively running processes.
- **procs_blocked** (Linux): current number of processes waiting for I/O.
- **ctx_switches** (Linux, Windows, NetBSD, SunOS):
- **ctx_switches** (Linux, Windows, NetBSD, SunOS, OSX):
number of system-wide context switches (voluntary and involuntary) since
boot (cumulative, always increasing)
- **open_files** (Linux, FreeBSD):
total number of opened file descriptors (regular files, sockets, etc.),
system-wide.
- **interrupts** (Linux, Windows, NetBSD, SunOS):
- **interrupts** (Linux, OSX, Windows, NetBSD, SunOS):
number of total system-wide interrupts since boot (cumulative, always
increasing).
- **max_threads** (Linux): maximum number of threads which can be run,
Expand All @@ -585,7 +585,7 @@ Other system info
system-wide.
- **num_threads** (OpenBSD): total number of running threads, system-wide.
- **traps** (SunOS): number of kernel traps.
- **syscalls** (Windows, SunOS): number of syscalls.
- **syscalls** (Windows, OSX, SunOS): number of syscalls.
- **pdcs** (Windows): number of deferred procedure calls.

Example (Linux):
Expand Down
4 changes: 4 additions & 0 deletions psutil/_psosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def users():
return retlist


def sysinfo():
return cext.sysinfo()


def net_connections(kind='inet'):
# Note: on OSX this will fail with AccessDenied unless
# the process is owned by root.
Expand Down
29 changes: 29 additions & 0 deletions psutil/_psutil_osx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,33 @@ psutil_users(PyObject *self, PyObject *args) {
}


/*
* Return various system info.
*/
static PyObject *
psutil_sysinfo(PyObject *self, PyObject *args) {
struct vmmeter vmstat;
kern_return_t ret;
mach_msg_type_number_t count = sizeof(vmstat) / sizeof(integer_t);
mach_port_t mport = mach_host_self();

ret = host_statistics(mport, HOST_VM_INFO, (host_info_t)&vmstat, &count);
if (ret != KERN_SUCCESS) {
PyErr_Format(PyExc_RuntimeError,
"host_statistics() failed: %s", mach_error_string(ret));
return NULL;
}
mach_port_deallocate(mach_task_self(), mport);

return Py_BuildValue(
"III",
vmstat.v_swtch, // ctx switches
vmstat.v_intr, // interrupts
vmstat.v_syscall // syscalls
);
}


/*
* define the psutil C module methods and initialize the module.
*/
Expand Down Expand Up @@ -1867,6 +1894,8 @@ PsutilMethods[] = {
"Return dict of tuples of disks I/O information."},
{"users", psutil_users, METH_VARARGS,
"Return currently connected users as a list of tuples"},
{"sysinfo", psutil_sysinfo, METH_VARARGS,
"Return various system info"},

{NULL, NULL, 0, NULL}
};
Expand Down

0 comments on commit a26fa59

Please sign in to comment.