summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-12-26 23:25:19 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2020-12-26 23:25:19 +0100
commit4d430b2ad4ff65a59bb093c0f8d5661d617083b4 (patch)
treeba3cfee8d417f760d66a359dc5e095d3a8953536
parent4acae428a868b47480cc160b77fea5d09aca34c9 (diff)
parenta7520d5e27c99dc9f70e74e2f34cb90f0e5c2337 (diff)
downloadpsutil-4d430b2ad4ff65a59bb093c0f8d5661d617083b4.tar.gz
Merge branch 'master' into wifi
-rw-r--r--.github/workflows/build.yml22
-rw-r--r--.github/workflows/issues.py94
-rw-r--r--.github/workflows/issues.yml2
-rw-r--r--CREDITS4
-rw-r--r--HISTORY.rst25
-rw-r--r--MANIFEST.in4
-rw-r--r--Makefile4
-rw-r--r--README.rst7
-rw-r--r--docs/index.rst16
-rw-r--r--psutil/__init__.py4
-rw-r--r--psutil/_psaix.py2
-rw-r--r--psutil/_psbsd.py11
-rw-r--r--psutil/_pslinux.py4
-rw-r--r--psutil/_psosx.py6
-rw-r--r--psutil/_pssunos.py6
-rw-r--r--psutil/_psutil_bsd.c5
-rw-r--r--psutil/_psutil_osx.c150
-rw-r--r--psutil/_psutil_sunos.c8
-rw-r--r--psutil/_psutil_windows.c6
-rw-r--r--psutil/_pswindows.py8
-rw-r--r--psutil/arch/freebsd/cpu.c130
-rw-r--r--psutil/arch/freebsd/cpu.h11
-rw-r--r--psutil/arch/freebsd/specific.c109
-rw-r--r--psutil/arch/freebsd/specific.h14
-rw-r--r--psutil/arch/osx/cpu.c140
-rw-r--r--psutil/arch/osx/cpu.h13
-rw-r--r--psutil/arch/windows/cpu.c7
-rw-r--r--psutil/arch/windows/cpu.h2
-rw-r--r--psutil/arch/windows/disk.c2
-rw-r--r--psutil/arch/windows/disk.h2
-rw-r--r--psutil/arch/windows/ntextapi.h2
-rwxr-xr-xpsutil/tests/test_linux.py8
-rwxr-xr-xpsutil/tests/test_memleaks.py2
-rwxr-xr-xpsutil/tests/test_osx.py2
-rwxr-xr-xpsutil/tests/test_system.py16
-rwxr-xr-xpsutil/tests/test_windows.py2
-rwxr-xr-xsetup.py2
37 files changed, 482 insertions, 370 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 25efdbc1..8427a929 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -1,13 +1,20 @@
# Executed on every push by GitHub Actions. This runs CI tests and
-# generates wheels on the following platforms:
+# generates wheels (not all) on the following platforms:
#
# * Linux
# * macOS
+# * Windows (commented)
# * FreeBSD
#
-# Windows works as well but it's disabled (we do it via AppVeyor).
# To skip certain builds see:
# https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip
+#
+# External GH actions:
+# * https://github.com/actions/checkout
+# * https://github.com/actions/setup-python
+# * https://github.com/actions/upload-artifact
+# * https://github.com/marketplace/actions/cancel-workflow-action
+# * https://github.com/vmactions/freebsd-vm
on: [push]
name: build
@@ -85,6 +92,7 @@ jobs:
run: |
set +e
export \
+ PYTHONUNBUFFERED=1 \
PYTHONWARNINGS=always \
PSUTIL_TESTING=1 \
PSUTIL_DEBUG=1
@@ -98,10 +106,12 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- - name: 'Linters'
+ - name: 'Run linters'
run: |
- python -m pip install flake8
- python -m flake8 .
+ python2 -m pip install flake8
+ python3 -m pip install flake8
+ python2 -m flake8 .
+ python3 -m flake8 .
echo "flake8 linting OK"
- find . -type f \( -iname "*.c" -o -iname "*.h" \) | xargs python scripts/internal/clinter.py
+ find . -type f \( -iname "*.c" -o -iname "*.h" \) | xargs python3 scripts/internal/clinter.py
echo "C linting OK"
diff --git a/.github/workflows/issues.py b/.github/workflows/issues.py
index c9f92d31..91e12202 100644
--- a/.github/workflows/issues.py
+++ b/.github/workflows/issues.py
@@ -10,9 +10,11 @@ is created. Assign labels, provide replies, closes issues, etc. depending
on the situation.
"""
+import functools
+import json
import os
import re
-import sys
+from pprint import pprint as pp
from github import Github
@@ -122,24 +124,15 @@ If this was a mistake or you think there's a bug with psutil installation \
process, please add a comment to reopen this issue.
"""
+# REPLY_UPDATE_CHANGELOG = """\
+# """
-# --- utils
-
-def is_pr(issue):
- return 'PullRequest' in issue.__module__
-
-
-def is_issue(issue):
- return not is_pr(issue)
-
-
-def is_new(issue):
- return issue.comments == 0
+# --- github API utils
-def is_comment(issue):
- return not is_new(issue)
+def is_pr(issue):
+ return issue.pull_request is not None
def has_label(issue, label):
@@ -161,6 +154,49 @@ def get_repo():
return Github(token).get_repo(repo)
+# --- event utils
+
+
+@functools.lru_cache()
+def _get_event_data():
+ ret = json.load(open(os.environ["GITHUB_EVENT_PATH"]))
+ pp(ret)
+ return ret
+
+
+def is_event_new_issue():
+ data = _get_event_data()
+ try:
+ return data['action'] == 'opened' and 'issue' in data
+ except KeyError:
+ return False
+
+
+def is_event_new_pr():
+ data = _get_event_data()
+ try:
+ return data['action'] == 'opened' and 'pull_request' in data
+ except KeyError:
+ return False
+
+
+def is_event_new_comment():
+ data = _get_event_data()
+ try:
+ return data['action'] == 'created' and 'comment' in data
+ except KeyError:
+ return False
+
+
+def get_issue():
+ data = _get_event_data()
+ try:
+ num = data['issue']['number']
+ except KeyError:
+ num = data['pull_request']['number']
+ return get_repo().get_issue(number=num)
+
+
# --- actions
@@ -275,6 +311,10 @@ def on_new_issue(issue):
def on_new_pr(issue):
pass
+ # pr = get_repo().get_pull(issue.number)
+ # files = [x.filename for x in list(pr.get_files())]
+ # if "HISTORY.rst" not in files:
+ # issue.create_comment(REPLY_UPDATE_CHANGELOG)
def on_new_comment(issue):
@@ -282,21 +322,25 @@ def on_new_comment(issue):
def main():
- issue = get_repo().get_issue(number=int(sys.argv[1]))
- stype = "issue" if is_issue(issue) else "PR"
+ issue = get_issue()
+ stype = "PR" if is_pr(issue) else "issue"
log("running issue bot for %s %r" % (stype, issue))
- if is_new(issue):
- log("new %s\n%s" % (stype, issue.body))
+ if is_event_new_issue():
+ log("created new issue %s" % issue)
add_labels_from_text(issue, issue.title)
add_labels_from_new_body(issue, issue.body)
- if is_issue(issue):
- on_new_issue(issue)
- if is_pr(issue):
- on_new_pr(issue)
- else:
- log("new comment: \n" % issue.body)
+ on_new_issue(issue)
+ elif is_event_new_pr():
+ log("created new PR %s" % issue)
+ add_labels_from_text(issue, issue.title)
+ add_labels_from_new_body(issue, issue.body)
+ on_new_pr(issue)
+ elif is_event_new_comment():
+ log("created new comment for %s" % issue)
on_new_comment(issue)
+ else:
+ raise ValueError("unhandled event")
if __name__ == '__main__':
diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml
index 2c2e38e3..fa739eab 100644
--- a/.github/workflows/issues.yml
+++ b/.github/workflows/issues.yml
@@ -25,4 +25,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
- python .github/workflows/issues.py ${{ github.event.issue.number }}
+ PYTHONUNBUFFERED=1 python .github/workflows/issues.py
diff --git a/CREDITS b/CREDITS
index 9ab16c6e..7e7ce954 100644
--- a/CREDITS
+++ b/CREDITS
@@ -95,6 +95,10 @@ I: 557
Donations
-------------------------------------------------------------------------------
+N: Daniel Widdis
+C: Washington, USA
+W: https://github.com/dbwiddis
+
N: Rodion Stratov
C: Canada
diff --git a/HISTORY.rst b/HISTORY.rst
index 5aee3a95..9f5281f9 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -1,5 +1,16 @@
*Bug tracker at https://github.com/giampaolo/psutil/issues*
+5.8.1 (IN DEVELOPMENT)
+======================
+
+XXXX-XX-XX
+
+**Bug fixes**
+
+- 1456_: [macOS] psutil.cpu_freq()'s min and max are set to 0 if can't be
+ determined (instead of crashing).
+- 1892_: [macOS] psutil.cpu_freq() broken on Apple M1.
+
5.8.0
=====
@@ -48,8 +59,8 @@
**Bug fixes**
-- 1620_: [Linux] physical cpu_count() result is incorrect on systems with more
- than one CPU socket. (patch by Vincent A. Arcila)
+- 1620_: [Linux] cpu_count(logical=False) result is incorrect on systems with
+ more than one CPU socket. (patch by Vincent A. Arcila)
- 1738_: [macOS] Process.exe() may raise FileNotFoundError if process is still
alive but the exe file which launched it got deleted.
- 1791_: [macOS] fix missing include for getpagesize().
@@ -245,7 +256,7 @@
average calculation, including on Windows (emulated). (patch by Ammar Askar)
- 1404_: [Linux] cpu_count(logical=False) uses a second method (read from
`/sys/devices/system/cpu/cpu[0-9]/topology/core_id`) in order to determine
- the number of physical CPUs in case /proc/cpuinfo does not provide this info.
+ the number of CPU cores in case /proc/cpuinfo does not provide this info.
- 1458_: provide coloured test output. Also show failures on KeyboardInterrupt.
- 1464_: various docfixes (always point to python3 doc, fix links, etc.).
- 1476_: [Windows] it is now possible to set process high I/O priority
@@ -491,7 +502,7 @@
- 694_: [SunOS] cmdline() could be truncated at the 15th character when
reading it from /proc. An extra effort is made by reading it from process
address space first. (patch by Georg Sauthoff)
-- 771_: [Windows] cpu_count() (both logical and physical) return a wrong
+- 771_: [Windows] cpu_count() (both logical and cores) return a wrong
(smaller) number on systems using process groups (> 64 cores).
- 771_: [Windows] cpu_times(percpu=True) return fewer CPUs on systems using
process groups (> 64 cores).
@@ -1295,8 +1306,8 @@
- 593_: [FreeBSD] Process().memory_maps() segfaults.
- 606_: Process.parent() may swallow NoSuchProcess exceptions.
- 611_: [SunOS] net_io_counters has send and received swapped
-- 614_: [Linux]: cpu_count(logical=False) return the number of physical CPUs
- instead of physical cores.
+- 614_: [Linux]: cpu_count(logical=False) return the number of sockets instead
+ of cores.
- 618_: [SunOS] swap tests fail on Solaris when run as normal user
- 628_: [Linux] Process.name() truncates process name in case it contains
spaces or parentheses.
@@ -1413,7 +1424,7 @@
**Enhancements**
- 424_: [Windows] installer for Python 3.X 64 bit.
-- 427_: number of logical and physical CPUs (psutil.cpu_count()).
+- 427_: number of logical CPUs and physical cores (psutil.cpu_count()).
- 447_: psutil.wait_procs() timeout parameter is now optional.
- 452_: make Process instances hashable and usable with set()s.
- 453_: tests on Python < 2.7 require unittest2 module.
diff --git a/MANIFEST.in b/MANIFEST.in
index 6936fb02..67c5d007 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -48,6 +48,8 @@ include psutil/arch/aix/ifaddrs.h
include psutil/arch/aix/net_connections.c
include psutil/arch/aix/net_connections.h
include psutil/arch/aix/net_kernel_structs.h
+include psutil/arch/freebsd/cpu.c
+include psutil/arch/freebsd/cpu.h
include psutil/arch/freebsd/proc_socks.c
include psutil/arch/freebsd/proc_socks.h
include psutil/arch/freebsd/specific.c
@@ -62,6 +64,8 @@ include psutil/arch/netbsd/specific.c
include psutil/arch/netbsd/specific.h
include psutil/arch/openbsd/specific.c
include psutil/arch/openbsd/specific.h
+include psutil/arch/osx/cpu.c
+include psutil/arch/osx/cpu.h
include psutil/arch/osx/process_info.c
include psutil/arch/osx/process_info.h
include psutil/arch/solaris/environ.c
diff --git a/Makefile b/Makefile
index d8ee5edc..087ddd78 100644
--- a/Makefile
+++ b/Makefile
@@ -47,7 +47,7 @@ all: test
# ===================================================================
clean: ## Remove all build files.
- rm -rf `find . -type d -name __pycache__ \
+ @rm -rfv `find . -type d -name __pycache__ \
-o -type f -name \*.bak \
-o -type f -name \*.orig \
-o -type f -name \*.pyc \
@@ -57,7 +57,7 @@ clean: ## Remove all build files.
-o -type f -name \*.so \
-o -type f -name \*.~ \
-o -type f -name \*\$testfn`
- rm -rf \
+ @rm -rfv \
*.core \
*.egg-info \
*\@psutil-* \
diff --git a/README.rst b/README.rst
index 8486cda7..83e79aab 100644
--- a/README.rst
+++ b/README.rst
@@ -130,16 +130,17 @@ Sponsors
Supporters
==========
-None yet.
-
.. raw:: html
+ <div>
+ <a href="https://github.com/dbwiddis"><img height="40" width="40" src="https://avatars1.githubusercontent.com/u/9291703?s=88&amp;u=3a4cbf1ea36068a36392856adb2fb02f623a3235&amp;v=4" /></a>
+ </div>
<sup><a href="https://github.com/sponsors/giampaolo">add your avatar</a></sup>
Contributing
============
-See `CONTRIBUTING.md <https://github.com/giampaolo/psutil/blob/master/CONTRIBUTING.md>`__ guidelines.
+See `contributing guidelines <https://github.com/giampaolo/psutil/blob/master/CONTRIBUTING.md>`__.
Example usages
==============
diff --git a/docs/index.rst b/docs/index.rst
index 8c3b432b..d452c51c 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -205,13 +205,13 @@ CPU
Return the number of logical CPUs in the system (same as `os.cpu_count`_
in Python 3.4) or ``None`` if undetermined.
- *logical* cores means the number of physical cores multiplied by the number
+ "logical CPUs" means the number of physical cores multiplied by the number
of threads that can run on each core (this is known as Hyper Threading).
- If *logical* is ``False`` return the number of physical cores only (Hyper
- Thread CPUs are excluded) or ``None`` if undetermined.
+ If *logical* is ``False`` return the number of physical cores only, or
+ ``None`` if undetermined.
On OpenBSD and NetBSD ``psutil.cpu_count(logical=False)`` always return
``None``.
- Example on a system having 2 physical hyper-thread CPU cores:
+ Example on a system having 2 cores + Hyper Threading:
>>> import psutil
>>> psutil.cpu_count()
@@ -219,11 +219,11 @@ CPU
>>> psutil.cpu_count(logical=False)
2
- Note that this number is not equivalent to the number of CPUs the current
- process can actually use.
+ Note that ``psutil.cpu_count()`` may not necessarily be equivalent to the
+ actual number of CPUs the current process can use.
That can vary in case process CPU affinity has been changed, Linux cgroups
- are being used or on Windows systems using processor groups or having more
- than 64 CPUs.
+ are being used or (in case of Windows) on systems using processor groups or
+ having more than 64 CPUs.
The number of usable CPUs can be obtained with:
>>> len(psutil.Process().cpu_affinity())
diff --git a/psutil/__init__.py b/psutil/__init__.py
index 46f85056..be3f0843 100644
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -209,7 +209,7 @@ if hasattr(_psplatform.Process, "rlimit"):
AF_LINK = _psplatform.AF_LINK
__author__ = "Giampaolo Rodola'"
-__version__ = "5.8.0"
+__version__ = "5.8.1"
version_info = tuple([int(num) for num in __version__.split('.')])
_timer = getattr(time, 'monotonic', time.time)
@@ -1575,7 +1575,7 @@ def cpu_count(logical=True):
if logical:
ret = _psplatform.cpu_count_logical()
else:
- ret = _psplatform.cpu_count_physical()
+ ret = _psplatform.cpu_count_cores()
if ret is not None and ret < 1:
ret = None
return ret
diff --git a/psutil/_psaix.py b/psutil/_psaix.py
index 7160ecd6..3e3a3d14 100644
--- a/psutil/_psaix.py
+++ b/psutil/_psaix.py
@@ -143,7 +143,7 @@ def cpu_count_logical():
return None
-def cpu_count_physical():
+def cpu_count_cores():
cmd = "lsdev -Cc processor"
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 764463e9..bdcfc1e6 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -249,19 +249,19 @@ def cpu_count_logical():
if OPENBSD or NETBSD:
- def cpu_count_physical():
+ def cpu_count_cores():
# OpenBSD and NetBSD do not implement this.
return 1 if cpu_count_logical() == 1 else None
else:
- def cpu_count_physical():
- """Return the number of physical CPUs in the system."""
+ def cpu_count_cores():
+ """Return the number of CPU cores in the system."""
# From the C module we'll get an XML string similar to this:
# http://manpages.ubuntu.com/manpages/precise/man4/smp.4freebsd.html
# We may get None in case "sysctl kern.sched.topology_spec"
# is not supported on this BSD version, in which case we'll mimic
# os.cpu_count() and return None.
ret = None
- s = cext.cpu_count_phys()
+ s = cext.cpu_topology()
if s is not None:
# get rid of padding chars appended at the end of the string
index = s.rfind("</groups>")
@@ -274,8 +274,7 @@ else:
# needed otherwise it will memleak
root.clear()
if not ret:
- # If logical CPUs are 1 it's obvious we'll have only 1
- # physical CPU.
+ # If logical CPUs == 1 it's obvious we' have only 1 core.
if cpu_count_logical() == 1:
return 1
return ret
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index c9a1b7d4..597de1d2 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -679,8 +679,8 @@ def cpu_count_logical():
return num
-def cpu_count_physical():
- """Return the number of physical cores in the system."""
+def cpu_count_cores():
+ """Return the number of CPU cores in the system."""
# Method #1
ls = set()
# These 2 files are the same but */core_cpus_list is newer while
diff --git a/psutil/_psosx.py b/psutil/_psosx.py
index c7770d65..d948cc15 100644
--- a/psutil/_psosx.py
+++ b/psutil/_psosx.py
@@ -159,9 +159,9 @@ def cpu_count_logical():
return cext.cpu_count_logical()
-def cpu_count_physical():
- """Return the number of physical CPUs in the system."""
- return cext.cpu_count_phys()
+def cpu_count_cores():
+ """Return the number of CPU cores in the system."""
+ return cext.cpu_count_cores()
def cpu_stats():
diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py
index 5618bd44..816ebf07 100644
--- a/psutil/_pssunos.py
+++ b/psutil/_pssunos.py
@@ -190,9 +190,9 @@ def cpu_count_logical():
return None
-def cpu_count_physical():
- """Return the number of physical CPUs in the system."""
- return cext.cpu_count_phys()
+def cpu_count_cores():
+ """Return the number of CPU cores in the system."""
+ return cext.cpu_count_cores()
def cpu_stats():
diff --git a/psutil/_psutil_bsd.c b/psutil/_psutil_bsd.c
index 15b646e3..69ce6e8e 100644
--- a/psutil/_psutil_bsd.c
+++ b/psutil/_psutil_bsd.c
@@ -63,6 +63,7 @@
#include "_psutil_posix.h"
#ifdef PSUTIL_FREEBSD
+ #include "arch/freebsd/cpu.h"
#include "arch/freebsd/specific.h"
#include "arch/freebsd/sys_socks.h"
#include "arch/freebsd/proc_socks.h"
@@ -1096,8 +1097,8 @@ static PyMethodDef mod_methods[] = {
"Get process resource limits."},
{"proc_setrlimit", psutil_proc_setrlimit, METH_VARARGS,
"Set process resource limits."},
- {"cpu_count_phys", psutil_cpu_count_phys, METH_VARARGS,
- "Return an XML string to determine the number physical CPUs."},
+ {"cpu_topology", psutil_cpu_topology, METH_VARARGS,
+ "Return CPU topology as an XML string."},
#endif
{"proc_environ", psutil_proc_environ, METH_VARARGS,
"Return process environment"},
diff --git a/psutil/_psutil_osx.c b/psutil/_psutil_osx.c
index 13d0bb68..62a95774 100644
--- a/psutil/_psutil_osx.c
+++ b/psutil/_psutil_osx.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
+ * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -14,7 +14,6 @@
#include <stdio.h>
#include <utmpx.h>
#include <sys/sysctl.h>
-#include <sys/vmmeter.h>
#include <libproc.h>
#include <sys/proc_info.h>
#include <netinet/tcp_fsm.h>
@@ -22,13 +21,7 @@
#include <net/if_dl.h>
#include <pwd.h>
#include <unistd.h>
-
#include <mach/mach.h>
-#include <mach/task.h>
-#include <mach/mach_init.h>
-#include <mach/host_info.h>
-#include <mach/mach_host.h>
-#include <mach/mach_traps.h>
#include <mach/mach_vm.h>
#include <mach/shared_region.h>
@@ -45,6 +38,7 @@
#include "_psutil_common.h"
#include "_psutil_posix.h"
#include "arch/osx/process_info.h"
+#include "arch/osx/cpu.h"
#define PSUTIL_TV2DOUBLE(t) ((t).tv_sec + (t).tv_usec / 1000000.0)
@@ -354,50 +348,6 @@ psutil_proc_environ(PyObject *self, PyObject *args) {
/*
- * Return the number of logical CPUs in the system.
- * XXX this could be shared with BSD.
- */
-static PyObject *
-psutil_cpu_count_logical(PyObject *self, PyObject *args) {
- /*
- int mib[2];
- int ncpu;
- size_t len;
- mib[0] = CTL_HW;
- mib[1] = HW_NCPU;
- len = sizeof(ncpu);
-
- if (sysctl(mib, 2, &ncpu, &len, NULL, 0) == -1)
- Py_RETURN_NONE; // mimic os.cpu_count()
- else
- return Py_BuildValue("i", ncpu);
- */
- int num;
- size_t size = sizeof(int);
-
- if (sysctlbyname("hw.logicalcpu", &num, &size, NULL, 2))
- Py_RETURN_NONE; // mimic os.cpu_count()
- else
- return Py_BuildValue("i", num);
-}
-
-
-/*
- * Return the number of physical CPUs in the system.
- */
-static PyObject *
-psutil_cpu_count_phys(PyObject *self, PyObject *args) {
- int num;
- size_t size = sizeof(int);
-
- if (sysctlbyname("hw.physicalcpu", &num, &size, NULL, 0))
- Py_RETURN_NONE; // mimic os.cpu_count()
- else
- return Py_BuildValue("i", num);
-}
-
-
-/*
* Indicates if the given virtual address on the given architecture is in the
* shared VM region.
*/
@@ -588,36 +538,6 @@ psutil_swap_mem(PyObject *self, PyObject *args) {
/*
- * Return a Python tuple representing user, kernel and idle CPU times
- */
-static PyObject *
-psutil_cpu_times(PyObject *self, PyObject *args) {
- mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT;
- kern_return_t error;
- host_cpu_load_info_data_t r_load;
-
- mach_port_t host_port = mach_host_self();
- error = host_statistics(host_port, HOST_CPU_LOAD_INFO,
- (host_info_t)&r_load, &count);
- if (error != KERN_SUCCESS) {
- return PyErr_Format(
- PyExc_RuntimeError,
- "host_statistics(HOST_CPU_LOAD_INFO) syscall failed: %s",
- mach_error_string(error));
- }
- mach_port_deallocate(mach_task_self(), host_port);
-
- return Py_BuildValue(
- "(dddd)",
- (double)r_load.cpu_ticks[CPU_STATE_USER] / CLK_TCK,
- (double)r_load.cpu_ticks[CPU_STATE_NICE] / CLK_TCK,
- (double)r_load.cpu_ticks[CPU_STATE_SYSTEM] / CLK_TCK,
- (double)r_load.cpu_ticks[CPU_STATE_IDLE] / CLK_TCK
- );
-}
-
-
-/*
* Return a Python list of tuple representing per-cpu times
*/
static PyObject *
@@ -684,37 +604,6 @@ error:
/*
- * Retrieve CPU frequency.
- */
-static PyObject *
-psutil_cpu_freq(PyObject *self, PyObject *args) {
- int64_t curr;
- int64_t min;
- int64_t max;
- size_t size = sizeof(int64_t);
-
- if (sysctlbyname("hw.cpufrequency", &curr, &size, NULL, 0)) {
- return PyErr_SetFromOSErrnoWithSyscall(
- "sysctlbyname('hw.cpufrequency')");
- }
- if (sysctlbyname("hw.cpufrequency_min", &min, &size, NULL, 0)) {
- return PyErr_SetFromOSErrnoWithSyscall(
- "sysctlbyname('hw.cpufrequency_min')");
- }
- if (sysctlbyname("hw.cpufrequency_max", &max, &size, NULL, 0)) {
- return PyErr_SetFromOSErrnoWithSyscall(
- "sysctlbyname('hw.cpufrequency_max')");
- }
-
- return Py_BuildValue(
- "KKK",
- curr / 1000 / 1000,
- min / 1000 / 1000,
- max / 1000 / 1000);
-}
-
-
-/*
* Return a Python float indicating the system boot time expressed in
* seconds since the epoch.
*/
@@ -1632,37 +1521,6 @@ error:
/*
- * Return CPU statistics.
- */
-static PyObject *
-psutil_cpu_stats(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(HOST_VM_INFO) failed: %s",
- mach_error_string(ret));
- return NULL;
- }
- mach_port_deallocate(mach_task_self(), mport);
-
- return Py_BuildValue(
- "IIIII",
- vmstat.v_swtch, // ctx switches
- vmstat.v_intr, // interrupts
- vmstat.v_soft, // software interrupts
- vmstat.v_syscall, // syscalls
- vmstat.v_trap // traps
- );
-}
-
-
-/*
* Return battery information.
*/
static PyObject *
@@ -1786,8 +1644,8 @@ static PyMethodDef mod_methods[] = {
"Returns a list of PIDs currently running on the system"},
{"cpu_count_logical", psutil_cpu_count_logical, METH_VARARGS,
"Return number of logical CPUs on the system"},
- {"cpu_count_phys", psutil_cpu_count_phys, METH_VARARGS,
- "Return number of physical CPUs on the system"},
+ {"cpu_count_cores", psutil_cpu_count_cores, METH_VARARGS,
+ "Return number of CPU cores on the system"},
{"virtual_mem", psutil_virtual_mem, METH_VARARGS,
"Return system virtual memory stats"},
{"swap_mem", psutil_swap_mem, METH_VARARGS,
diff --git a/psutil/_psutil_sunos.c b/psutil/_psutil_sunos.c
index 82114c8c..342798a8 100644
--- a/psutil/_psutil_sunos.c
+++ b/psutil/_psutil_sunos.c
@@ -1437,10 +1437,10 @@ psutil_boot_time(PyObject *self, PyObject *args) {
/*
- * Return the number of physical CPU cores on the system.
+ * Return the number of CPU cores on the system.
*/
static PyObject *
-psutil_cpu_count_phys(PyObject *self, PyObject *args) {
+psutil_cpu_count_cores(PyObject *self, PyObject *args) {
kstat_ctl_t *kc;
kstat_t *ksp;
int ncpus = 0;
@@ -1669,8 +1669,8 @@ PsutilMethods[] = {
"Return a Python dict of tuples for network I/O statistics."},
{"boot_time", psutil_boot_time, METH_VARARGS,
"Return system boot time in seconds since the EPOCH."},
- {"cpu_count_phys", psutil_cpu_count_phys, METH_VARARGS,
- "Return the number of physical CPUs on the system."},
+ {"cpu_count_cores", psutil_cpu_count_cores, METH_VARARGS,
+ "Return the number of CPU cores on the system."},
{"net_connections", psutil_net_connections, METH_VARARGS,
"Return TCP and UDP syste-wide open connections."},
{"net_if_stats", psutil_net_if_stats, METH_VARARGS,
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index faeaf4e0..4aec2d70 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -1612,8 +1612,8 @@ PsutilMethods[] = {
"Determine if the process exists in the current process list."},
{"cpu_count_logical", psutil_cpu_count_logical, METH_VARARGS,
"Returns the number of logical CPUs on the system"},
- {"cpu_count_phys", psutil_cpu_count_phys, METH_VARARGS,
- "Returns the number of physical CPUs on the system"},
+ {"cpu_count_cores", psutil_cpu_count_cores, METH_VARARGS,
+ "Returns the number of CPU cores on the system"},
{"boot_time", psutil_boot_time, METH_VARARGS,
"Return the system boot time expressed in seconds since the epoch."},
{"virtual_mem", psutil_virtual_mem, METH_VARARGS,
@@ -1671,7 +1671,7 @@ PsutilMethods[] = {
"Stop a service"},
// --- windows API bindings
- {"win32_QueryDosDevice", psutil_win32_QueryDosDevice, METH_VARARGS,
+ {"QueryDosDevice", psutil_QueryDosDevice, METH_VARARGS,
"QueryDosDevice binding"},
// --- others
diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py
index 2997db6e..8188be93 100644
--- a/psutil/_pswindows.py
+++ b/psutil/_pswindows.py
@@ -197,7 +197,7 @@ def convert_dos_path(s):
"C:\Windows\systemew\file.txt"
"""
rawdrive = '\\'.join(s.split('\\')[:3])
- driveletter = cext.win32_QueryDosDevice(rawdrive)
+ driveletter = cext.QueryDosDevice(rawdrive)
remainder = s[len(rawdrive):]
return os.path.join(driveletter, remainder)
@@ -304,9 +304,9 @@ def cpu_count_logical():
return cext.cpu_count_logical()
-def cpu_count_physical():
- """Return the number of physical CPU cores in the system."""
- return cext.cpu_count_phys()
+def cpu_count_cores():
+ """Return the number of CPU cores in the system."""
+ return cext.cpu_count_cores()
def cpu_stats():
diff --git a/psutil/arch/freebsd/cpu.c b/psutil/arch/freebsd/cpu.c
new file mode 100644
index 00000000..f31e9bb0
--- /dev/null
+++ b/psutil/arch/freebsd/cpu.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/*
+System-wide CPU related functions.
+Original code was refactored and moved from psutil/arch/freebsd/specific.c
+in 2020 (and was moved in there previously already) from cset.
+a4c0a0eb0d2a872ab7a45e47fcf37ef1fde5b012
+For reference, here's the git history with original(ish) implementations:
+- CPU stats: fb0154ef164d0e5942ac85102ab660b8d2938fbb
+- CPU freq: 459556dd1e2979cdee22177339ced0761caf4c83
+- CPU cores: e0d6d7865df84dc9a1d123ae452fd311f79b1dde
+*/
+
+
+#include <Python.h>
+#include <sys/sysctl.h>
+
+#include "../../_psutil_common.h"
+#include "../../_psutil_posix.h"
+
+
+PyObject *
+psutil_cpu_topology(PyObject *self, PyObject *args) {
+ void *topology = NULL;
+ size_t size = 0;
+ PyObject *py_str;
+
+ if (sysctlbyname("kern.sched.topology_spec", NULL, &size, NULL, 0))
+ goto error;
+
+ topology = malloc(size);
+ if (!topology) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ if (sysctlbyname("kern.sched.topology_spec", topology, &size, NULL, 0))
+ goto error;
+
+ py_str = Py_BuildValue("s", topology);
+ free(topology);
+ return py_str;
+
+error:
+ if (topology != NULL)
+ free(topology);
+ Py_RETURN_NONE;
+}
+
+
+PyObject *
+psutil_cpu_stats(PyObject *self, PyObject *args) {
+ unsigned int v_soft;
+ unsigned int v_intr;
+ unsigned int v_syscall;
+ unsigned int v_trap;
+ unsigned int v_swtch;
+ size_t size = sizeof(v_soft);
+
+ if (sysctlbyname("vm.stats.sys.v_soft", &v_soft, &size, NULL, 0)) {
+ return PyErr_SetFromOSErrnoWithSyscall(
+ "sysctlbyname('vm.stats.sys.v_soft')");
+ }
+ if (sysctlbyname("vm.stats.sys.v_intr", &v_intr, &size, NULL, 0)) {
+ return PyErr_SetFromOSErrnoWithSyscall(
+ "sysctlbyname('vm.stats.sys.v_intr')");
+ }
+ if (sysctlbyname("vm.stats.sys.v_syscall", &v_syscall, &size, NULL, 0)) {
+ return PyErr_SetFromOSErrnoWithSyscall(
+ "sysctlbyname('vm.stats.sys.v_syscall')");
+ }
+ if (sysctlbyname("vm.stats.sys.v_trap", &v_trap, &size, NULL, 0)) {
+ return PyErr_SetFromOSErrnoWithSyscall(
+ "sysctlbyname('vm.stats.sys.v_trap')");
+ }
+ if (sysctlbyname("vm.stats.sys.v_swtch", &v_swtch, &size, NULL, 0)) {
+ return PyErr_SetFromOSErrnoWithSyscall(
+ "sysctlbyname('vm.stats.sys.v_swtch')");
+ }
+
+ return Py_BuildValue(
+ "IIIII",
+ v_swtch, // ctx switches
+ v_intr, // interrupts
+ v_soft, // software interrupts
+ v_syscall, // syscalls
+ v_trap // traps
+ );
+}
+
+
+/*
+ * Return frequency information of a given CPU.
+ * As of Dec 2018 only CPU 0 appears to be supported and all other
+ * cores match the frequency of CPU 0.
+ */
+PyObject *
+psutil_cpu_freq(PyObject *self, PyObject *args) {
+ int current;
+ int core;
+ char sensor[26];
+ char available_freq_levels[1000];
+ size_t size = sizeof(current);
+
+ if (! PyArg_ParseTuple(args, "i", &core))
+ return NULL;
+ // https://www.unix.com/man-page/FreeBSD/4/cpufreq/
+ sprintf(sensor, "dev.cpu.%d.freq", core);
+ if (sysctlbyname(sensor, &current, &size, NULL, 0))
+ goto error;
+
+ size = sizeof(available_freq_levels);
+ // https://www.unix.com/man-page/FreeBSD/4/cpufreq/
+ // In case of failure, an empty string is returned.
+ sprintf(sensor, "dev.cpu.%d.freq_levels", core);
+ sysctlbyname(sensor, &available_freq_levels, &size, NULL, 0);
+
+ return Py_BuildValue("is", current, available_freq_levels);
+
+error:
+ if (errno == ENOENT)
+ PyErr_SetString(PyExc_NotImplementedError, "unable to read frequency");
+ else
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+}
diff --git a/psutil/arch/freebsd/cpu.h b/psutil/arch/freebsd/cpu.h
new file mode 100644
index 00000000..8decd773
--- /dev/null
+++ b/psutil/arch/freebsd/cpu.h
@@ -0,0 +1,11 @@
+/*
+ * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <Python.h>
+
+PyObject* psutil_cpu_freq(PyObject* self, PyObject* args);
+PyObject* psutil_cpu_stats(PyObject* self, PyObject* args);
+PyObject* psutil_cpu_topology(PyObject* self, PyObject* args);
diff --git a/psutil/arch/freebsd/specific.c b/psutil/arch/freebsd/specific.c
index 2776de8c..423f0c7b 100644
--- a/psutil/arch/freebsd/specific.c
+++ b/psutil/arch/freebsd/specific.c
@@ -363,37 +363,6 @@ error:
}
-PyObject *
-psutil_cpu_count_phys(PyObject *self, PyObject *args) {
- // Return an XML string from which we'll determine the number of
- // physical CPU cores in the system.
- void *topology = NULL;
- size_t size = 0;
- PyObject *py_str;
-
- if (sysctlbyname("kern.sched.topology_spec", NULL, &size, NULL, 0))
- goto error;
-
- topology = malloc(size);
- if (!topology) {
- PyErr_NoMemory();
- return NULL;
- }
-
- if (sysctlbyname("kern.sched.topology_spec", topology, &size, NULL, 0))
- goto error;
-
- py_str = Py_BuildValue("s", topology);
- free(topology);
- return py_str;
-
-error:
- if (topology != NULL)
- free(topology);
- Py_RETURN_NONE;
-}
-
-
/*
* Return virtual memory usage statistics.
*/
@@ -932,47 +901,6 @@ error:
}
-PyObject *
-psutil_cpu_stats(PyObject *self, PyObject *args) {
- unsigned int v_soft;
- unsigned int v_intr;
- unsigned int v_syscall;
- unsigned int v_trap;
- unsigned int v_swtch;
- size_t size = sizeof(v_soft);
-
- if (sysctlbyname("vm.stats.sys.v_soft", &v_soft, &size, NULL, 0)) {
- return PyErr_SetFromOSErrnoWithSyscall(
- "sysctlbyname('vm.stats.sys.v_soft')");
- }
- if (sysctlbyname("vm.stats.sys.v_intr", &v_intr, &size, NULL, 0)) {
- return PyErr_SetFromOSErrnoWithSyscall(
- "sysctlbyname('vm.stats.sys.v_intr')");
- }
- if (sysctlbyname("vm.stats.sys.v_syscall", &v_syscall, &size, NULL, 0)) {
- return PyErr_SetFromOSErrnoWithSyscall(
- "sysctlbyname('vm.stats.sys.v_syscall')");
- }
- if (sysctlbyname("vm.stats.sys.v_trap", &v_trap, &size, NULL, 0)) {
- return PyErr_SetFromOSErrnoWithSyscall(
- "sysctlbyname('vm.stats.sys.v_trap')");
- }
- if (sysctlbyname("vm.stats.sys.v_swtch", &v_swtch, &size, NULL, 0)) {
- return PyErr_SetFromOSErrnoWithSyscall(
- "sysctlbyname('vm.stats.sys.v_swtch')");
- }
-
- return Py_BuildValue(
- "IIIII",
- v_swtch, // ctx switches
- v_intr, // interrupts
- v_soft, // software interrupts
- v_syscall, // syscalls
- v_trap // traps
- );
-}
-
-
/*
* Return battery information.
*/
@@ -1037,43 +965,6 @@ error:
/*
- * Return frequency information of a given CPU.
- * As of Dec 2018 only CPU 0 appears to be supported and all other
- * cores match the frequency of CPU 0.
- */
-PyObject *
-psutil_cpu_freq(PyObject *self, PyObject *args) {
- int current;
- int core;
- char sensor[26];
- char available_freq_levels[1000];
- size_t size = sizeof(current);
-
- if (! PyArg_ParseTuple(args, "i", &core))
- return NULL;
- // https://www.unix.com/man-page/FreeBSD/4/cpufreq/
- sprintf(sensor, "dev.cpu.%d.freq", core);
- if (sysctlbyname(sensor, &current, &size, NULL, 0))
- goto error;
-
- size = sizeof(available_freq_levels);
- // https://www.unix.com/man-page/FreeBSD/4/cpufreq/
- // In case of failure, an empty string is returned.
- sprintf(sensor, "dev.cpu.%d.freq_levels", core);
- sysctlbyname(sensor, &available_freq_levels, &size, NULL, 0);
-
- return Py_BuildValue("is", current, available_freq_levels);
-
-error:
- if (errno == ENOENT)
- PyErr_SetString(PyExc_NotImplementedError, "unable to read frequency");
- else
- PyErr_SetFromErrno(PyExc_OSError);
- return NULL;
-}
-
-
-/*
* An emulation of Linux prlimit(). Returns a (soft, hard) tuple.
*/
PyObject *
diff --git a/psutil/arch/freebsd/specific.h b/psutil/arch/freebsd/specific.h
index 61c3f07b..57f0a2a4 100644
--- a/psutil/arch/freebsd/specific.h
+++ b/psutil/arch/freebsd/specific.h
@@ -11,8 +11,6 @@ typedef struct kinfo_proc kinfo_proc;
int psutil_get_proc_list(struct kinfo_proc **procList, size_t *procCount);
int psutil_kinfo_proc(const pid_t pid, struct kinfo_proc *proc);
-//
-PyObject* psutil_cpu_count_phys(PyObject* self, PyObject* args);
PyObject* psutil_disk_io_counters(PyObject* self, PyObject* args);
PyObject* psutil_get_cmdline(long pid);
PyObject* psutil_per_cpu_times(PyObject* self, PyObject* args);
@@ -20,17 +18,13 @@ PyObject* psutil_proc_cpu_affinity_get(PyObject* self, PyObject* args);
PyObject* psutil_proc_cpu_affinity_set(PyObject* self, PyObject* args);
PyObject* psutil_proc_cwd(PyObject* self, PyObject* args);
PyObject* psutil_proc_exe(PyObject* self, PyObject* args);
+PyObject* psutil_proc_getrlimit(PyObject* self, PyObject* args);
PyObject* psutil_proc_memory_maps(PyObject* self, PyObject* args);
PyObject* psutil_proc_num_fds(PyObject* self, PyObject* args);
PyObject* psutil_proc_num_threads(PyObject* self, PyObject* args);
-PyObject* psutil_proc_threads(PyObject* self, PyObject* args);
-PyObject* psutil_proc_getrlimit(PyObject* self, PyObject* args);
PyObject* psutil_proc_setrlimit(PyObject* self, PyObject* args);
-PyObject* psutil_swap_mem(PyObject* self, PyObject* args);
-PyObject* psutil_virtual_mem(PyObject* self, PyObject* args);
-PyObject* psutil_cpu_stats(PyObject* self, PyObject* args);
-#if defined(PSUTIL_FREEBSD)
+PyObject* psutil_proc_threads(PyObject* self, PyObject* args);
PyObject* psutil_sensors_battery(PyObject* self, PyObject* args);
PyObject* psutil_sensors_cpu_temperature(PyObject* self, PyObject* args);
-PyObject* psutil_cpu_freq(PyObject* self, PyObject* args);
-#endif
+PyObject* psutil_swap_mem(PyObject* self, PyObject* args);
+PyObject* psutil_virtual_mem(PyObject* self, PyObject* args);
diff --git a/psutil/arch/osx/cpu.c b/psutil/arch/osx/cpu.c
new file mode 100644
index 00000000..37141a2d
--- /dev/null
+++ b/psutil/arch/osx/cpu.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/*
+System-wide CPU related functions.
+
+Original code was refactored and moved from psutil/_psutil_osx.c in 2020
+right before a4c0a0eb0d2a872ab7a45e47fcf37ef1fde5b012.
+For reference, here's the git history with original implementations:
+
+- CPU count logical: 3d291d425b856077e65163e43244050fb188def1
+- CPU count physical: 4263e354bb4984334bc44adf5dd2f32013d69fba
+- CPU times: 32488bdf54aed0f8cef90d639c1667ffaa3c31c7
+- CPU stat: fa00dfb961ef63426c7818899340866ced8d2418
+- CPU frequency: 6ba1ac4ebfcd8c95fca324b15606ab0ec1412d39
+*/
+
+#include <Python.h>
+#include <sys/sysctl.h>
+#include <sys/vmmeter.h>
+
+#include <mach/mach_error.h>
+#include <mach/mach_host.h>
+#include <mach/mach_port.h>
+
+#include "../../_psutil_common.h"
+#include "../../_psutil_posix.h"
+
+
+
+PyObject *
+psutil_cpu_count_logical(PyObject *self, PyObject *args) {
+ int num;
+ size_t size = sizeof(int);
+
+ if (sysctlbyname("hw.logicalcpu", &num, &size, NULL, 2))
+ Py_RETURN_NONE; // mimic os.cpu_count()
+ else
+ return Py_BuildValue("i", num);
+}
+
+
+PyObject *
+psutil_cpu_count_cores(PyObject *self, PyObject *args) {
+ int num;
+ size_t size = sizeof(int);
+
+ if (sysctlbyname("hw.physicalcpu", &num, &size, NULL, 0))
+ Py_RETURN_NONE; // mimic os.cpu_count()
+ else
+ return Py_BuildValue("i", num);
+}
+
+
+PyObject *
+psutil_cpu_times(PyObject *self, PyObject *args) {
+ mach_msg_type_number_t count = HOST_CPU_LOAD_INFO_COUNT;
+ kern_return_t error;
+ host_cpu_load_info_data_t r_load;
+
+ mach_port_t host_port = mach_host_self();
+ error = host_statistics(host_port, HOST_CPU_LOAD_INFO,
+ (host_info_t)&r_load, &count);
+ if (error != KERN_SUCCESS) {
+ return PyErr_Format(
+ PyExc_RuntimeError,
+ "host_statistics(HOST_CPU_LOAD_INFO) syscall failed: %s",
+ mach_error_string(error));
+ }
+ mach_port_deallocate(mach_task_self(), host_port);
+
+ return Py_BuildValue(
+ "(dddd)",
+ (double)r_load.cpu_ticks[CPU_STATE_USER] / CLK_TCK,
+ (double)r_load.cpu_ticks[CPU_STATE_NICE] / CLK_TCK,
+ (double)r_load.cpu_ticks[CPU_STATE_SYSTEM] / CLK_TCK,
+ (double)r_load.cpu_ticks[CPU_STATE_IDLE] / CLK_TCK
+ );
+}
+
+
+PyObject *
+psutil_cpu_stats(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(HOST_VM_INFO) failed: %s",
+ mach_error_string(ret));
+ return NULL;
+ }
+ mach_port_deallocate(mach_task_self(), mport);
+
+ return Py_BuildValue(
+ "IIIII",
+ vmstat.v_swtch, // ctx switches
+ vmstat.v_intr, // interrupts
+ vmstat.v_soft, // software interrupts
+ vmstat.v_syscall, // syscalls
+ vmstat.v_trap // traps
+ );
+}
+
+
+PyObject *
+psutil_cpu_freq(PyObject *self, PyObject *args) {
+ unsigned int curr;
+ int64_t min = 0;
+ int64_t max = 0;
+ int mib[2];
+ size_t len = sizeof(curr);
+ size_t size = sizeof(min);
+
+ // also availble as "hw.cpufrequency" but it's deprecated
+ mib[0] = CTL_HW;
+ mib[1] = HW_CPU_FREQ;
+
+ if (sysctl(mib, 2, &curr, &len, NULL, 0) < 0)
+ return PyErr_SetFromOSErrnoWithSyscall("sysctl(HW_CPU_FREQ)");
+
+ if (sysctlbyname("hw.cpufrequency_min", &min, &size, NULL, 0))
+ psutil_debug("sysct('hw.cpufrequency_min') failed (set to 0)");
+
+ if (sysctlbyname("hw.cpufrequency_max", &max, &size, NULL, 0))
+ psutil_debug("sysctl('hw.cpufrequency_min') failed (set to 0)");
+
+ return Py_BuildValue(
+ "IKK",
+ curr / 1000 / 1000,
+ min / 1000 / 1000,
+ max / 1000 / 1000);
+}
diff --git a/psutil/arch/osx/cpu.h b/psutil/arch/osx/cpu.h
new file mode 100644
index 00000000..aac0f809
--- /dev/null
+++ b/psutil/arch/osx/cpu.h
@@ -0,0 +1,13 @@
+/*
+ * Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <Python.h>
+
+PyObject *psutil_cpu_count_logical(PyObject *self, PyObject *args);
+PyObject *psutil_cpu_count_cores(PyObject *self, PyObject *args);
+PyObject *psutil_cpu_times(PyObject *self, PyObject *args);
+PyObject *psutil_cpu_freq(PyObject *self, PyObject *args);
+PyObject *psutil_cpu_stats(PyObject *self, PyObject *args);
diff --git a/psutil/arch/windows/cpu.c b/psutil/arch/windows/cpu.c
index 18f32e59..355de6df 100644
--- a/psutil/arch/windows/cpu.c
+++ b/psutil/arch/windows/cpu.c
@@ -177,11 +177,10 @@ psutil_cpu_count_logical(PyObject *self, PyObject *args) {
/*
- * Return the number of physical CPU cores (hyper-thread CPUs count
- * is excluded).
+ * Return the number of CPU cores (non hyper-threading).
*/
PyObject *
-psutil_cpu_count_phys(PyObject *self, PyObject *args) {
+psutil_cpu_count_cores(PyObject *self, PyObject *args) {
DWORD rc;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX buffer = NULL;
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX ptr = NULL;
@@ -196,7 +195,7 @@ psutil_cpu_count_phys(PyObject *self, PyObject *args) {
// than 64 CPUs. See:
// https://bugs.python.org/issue33166
if (GetLogicalProcessorInformationEx == NULL) {
- psutil_debug("Win < 7; cpu_count_phys() forced to None");
+ psutil_debug("Win < 7; cpu_count_cores() forced to None");
Py_RETURN_NONE;
}
diff --git a/psutil/arch/windows/cpu.h b/psutil/arch/windows/cpu.h
index d88c2212..1ef3ff1f 100644
--- a/psutil/arch/windows/cpu.h
+++ b/psutil/arch/windows/cpu.h
@@ -7,7 +7,7 @@
#include <Python.h>
PyObject *psutil_cpu_count_logical(PyObject *self, PyObject *args);
-PyObject *psutil_cpu_count_phys(PyObject *self, PyObject *args);
+PyObject *psutil_cpu_count_cores(PyObject *self, PyObject *args);
PyObject *psutil_cpu_freq(PyObject *self, PyObject *args);
PyObject *psutil_cpu_stats(PyObject *self, PyObject *args);
PyObject *psutil_cpu_times(PyObject *self, PyObject *args);
diff --git a/psutil/arch/windows/disk.c b/psutil/arch/windows/disk.c
index 92171fe5..29bd0a20 100644
--- a/psutil/arch/windows/disk.c
+++ b/psutil/arch/windows/disk.c
@@ -364,7 +364,7 @@ error:
If no match is found return an empty string.
*/
PyObject *
-psutil_win32_QueryDosDevice(PyObject *self, PyObject *args) {
+psutil_QueryDosDevice(PyObject *self, PyObject *args) {
LPCTSTR lpDevicePath;
TCHAR d = TEXT('A');
TCHAR szBuff[5];
diff --git a/psutil/arch/windows/disk.h b/psutil/arch/windows/disk.h
index 298fb6ba..28bed22b 100644
--- a/psutil/arch/windows/disk.h
+++ b/psutil/arch/windows/disk.h
@@ -9,4 +9,4 @@
PyObject *psutil_disk_io_counters(PyObject *self, PyObject *args);
PyObject *psutil_disk_partitions(PyObject *self, PyObject *args);
PyObject *psutil_disk_usage(PyObject *self, PyObject *args);
-PyObject *psutil_win32_QueryDosDevice(PyObject *self, PyObject *args);
+PyObject *psutil_QueryDosDevice(PyObject *self, PyObject *args);
diff --git a/psutil/arch/windows/ntextapi.h b/psutil/arch/windows/ntextapi.h
index ea1f4281..e0662fa0 100644
--- a/psutil/arch/windows/ntextapi.h
+++ b/psutil/arch/windows/ntextapi.h
@@ -399,7 +399,7 @@ typedef struct _WTSINFOW {
#define PWTSINFO PWTSINFOW
-// cpu_count_phys()
+// cpu_count_cores()
#if (_WIN32_WINNT < 0x0601) // Windows < 7 (Vista and XP)
typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX {
LOGICAL_PROCESSOR_RELATIONSHIP Relationship;
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index 7180e22e..15594cd3 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -717,7 +717,7 @@ class TestSystemCPUCountLogical(PsutilTestCase):
@unittest.skipIf(not LINUX, "LINUX only")
-class TestSystemCPUCountPhysical(PsutilTestCase):
+class TestSystemCPUCountCores(PsutilTestCase):
@unittest.skipIf(not which("lscpu"), "lscpu utility not available")
def test_against_lscpu(self):
@@ -730,9 +730,9 @@ class TestSystemCPUCountPhysical(PsutilTestCase):
self.assertEqual(psutil.cpu_count(logical=False), len(core_ids))
def test_method_2(self):
- meth_1 = psutil._pslinux.cpu_count_physical()
+ meth_1 = psutil._pslinux.cpu_count_cores()
with mock.patch('glob.glob', return_value=[]) as m:
- meth_2 = psutil._pslinux.cpu_count_physical()
+ meth_2 = psutil._pslinux.cpu_count_cores()
assert m.called
if meth_1 is not None:
self.assertEqual(meth_1, meth_2)
@@ -740,7 +740,7 @@ class TestSystemCPUCountPhysical(PsutilTestCase):
def test_emulate_none(self):
with mock.patch('glob.glob', return_value=[]) as m1:
with mock.patch('psutil._common.open', create=True) as m2:
- self.assertIsNone(psutil._pslinux.cpu_count_physical())
+ self.assertIsNone(psutil._pslinux.cpu_count_cores())
assert m1.called
assert m2.called
diff --git a/psutil/tests/test_memleaks.py b/psutil/tests/test_memleaks.py
index 7d724b91..3ec62c24 100755
--- a/psutil/tests/test_memleaks.py
+++ b/psutil/tests/test_memleaks.py
@@ -348,7 +348,7 @@ class TestModuleFunctionsLeaks(TestMemoryLeak):
self.execute(lambda: psutil.cpu_count(logical=True))
@fewtimes_if_linux()
- def test_cpu_count_physical(self):
+ def test_cpu_count_cores(self):
self.execute(lambda: psutil.cpu_count(logical=False))
@fewtimes_if_linux()
diff --git a/psutil/tests/test_osx.py b/psutil/tests/test_osx.py
index 348976f8..b7a0b088 100755
--- a/psutil/tests/test_osx.py
+++ b/psutil/tests/test_osx.py
@@ -137,7 +137,7 @@ class TestSystemAPIs(PsutilTestCase):
num = sysctl("sysctl hw.logicalcpu")
self.assertEqual(num, psutil.cpu_count(logical=True))
- def test_cpu_count_physical(self):
+ def test_cpu_count_cores(self):
num = sysctl("sysctl hw.physicalcpu")
self.assertEqual(num, psutil.cpu_count(logical=False))
diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py
index 90ecff94..4e3ac3e4 100755
--- a/psutil/tests/test_system.py
+++ b/psutil/tests/test_system.py
@@ -316,16 +316,16 @@ class TestCpuAPIs(PsutilTestCase):
if "physical id" not in cpuinfo_data:
raise unittest.SkipTest("cpuinfo doesn't include physical id")
- def test_cpu_count_physical(self):
+ def test_cpu_count_cores(self):
logical = psutil.cpu_count()
- physical = psutil.cpu_count(logical=False)
- if physical is None:
- raise self.skipTest("physical cpu_count() is None")
+ cores = psutil.cpu_count(logical=False)
+ if cores is None:
+ raise self.skipTest("cpu_count_cores() is None")
if WINDOWS and sys.getwindowsversion()[:2] <= (6, 1): # <= Vista
- self.assertIsNone(physical)
+ self.assertIsNone(cores)
else:
- self.assertGreaterEqual(physical, 1)
- self.assertGreaterEqual(logical, physical)
+ self.assertGreaterEqual(cores, 1)
+ self.assertGreaterEqual(logical, cores)
def test_cpu_count_none(self):
# https://github.com/giampaolo/psutil/issues/1085
@@ -334,7 +334,7 @@ class TestCpuAPIs(PsutilTestCase):
return_value=val) as m:
self.assertIsNone(psutil.cpu_count())
assert m.called
- with mock.patch('psutil._psplatform.cpu_count_physical',
+ with mock.patch('psutil._psplatform.cpu_count_cores',
return_value=val) as m:
self.assertIsNone(psutil.cpu_count(logical=False))
assert m.called
diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py
index a9254e2c..aeb282c8 100755
--- a/psutil/tests/test_windows.py
+++ b/psutil/tests/test_windows.py
@@ -100,7 +100,7 @@ class TestCpuAPIs(WindowsTestCase):
proc = w.Win32_Processor()[0]
self.assertEqual(psutil.cpu_count(), proc.NumberOfLogicalProcessors)
- def test_cpu_count_phys_vs_wmi(self):
+ def test_cpu_count_cores_vs_wmi(self):
w = wmi.WMI()
proc = w.Win32_Processor()[0]
self.assertEqual(psutil.cpu_count(logical=False), proc.NumberOfCores)
diff --git a/setup.py b/setup.py
index c64096e8..897ba2eb 100755
--- a/setup.py
+++ b/setup.py
@@ -190,6 +190,7 @@ elif MACOS:
sources=sources + [
'psutil/_psutil_osx.c',
'psutil/arch/osx/process_info.c',
+ 'psutil/arch/osx/cpu.c',
],
define_macros=macros,
extra_link_args=[
@@ -202,6 +203,7 @@ elif FREEBSD:
'psutil._psutil_bsd',
sources=sources + [
'psutil/_psutil_bsd.c',
+ 'psutil/arch/freebsd/cpu.c',
'psutil/arch/freebsd/specific.c',
'psutil/arch/freebsd/sys_socks.c',
'psutil/arch/freebsd/proc_socks.c',