summaryrefslogtreecommitdiff
path: root/psutil/_psbsd.py
diff options
context:
space:
mode:
Diffstat (limited to 'psutil/_psbsd.py')
-rw-r--r--psutil/_psbsd.py50
1 files changed, 21 insertions, 29 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index bdcfc1e6..19e636fd 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -248,36 +248,28 @@ def cpu_count_logical():
return cext.cpu_count_logical()
-if OPENBSD or NETBSD:
- def cpu_count_cores():
- # OpenBSD and NetBSD do not implement this.
- return 1 if cpu_count_logical() == 1 else None
-else:
+if FREEBSD:
+
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_topology()
- if s is not None:
- # get rid of padding chars appended at the end of the string
- index = s.rfind("</groups>")
- if index != -1:
- s = s[:index + 9]
- root = ET.fromstring(s)
- try:
- ret = len(root.findall('group/children/group/cpu')) or None
- finally:
- # needed otherwise it will memleak
- root.clear()
- if not ret:
- # If logical CPUs == 1 it's obvious we' have only 1 core.
- if cpu_count_logical() == 1:
- return 1
- return ret
+ # https://manpages.ubuntu.com/manpages/precise/man4/smp.4freebsd.html
+ xmlstr = cext.cpu_topology()
+ if xmlstr is not None:
+ root = ET.fromstring(xmlstr)
+ try:
+ count = len(root.findall('group/children/group/cpu'))
+ return count if count != 0 else None
+ finally:
+ root.clear()
+
+ def cpu_count_sockets():
+ xmlstr = cext.cpu_topology()
+ if xmlstr is not None:
+ root = ET.fromstring(xmlstr)
+ try:
+ count = len(root.findall('group'))
+ return count if count != 0 else None
+ finally:
+ root.clear()
def cpu_stats():