Commit a47c2eae authored by Jelte Jansen's avatar Jelte Jansen

[2172] rearrange freebsd/osx hierarchy

parent 371d3158
...@@ -349,9 +349,9 @@ class SysInfoOpenBSD(SysInfoBSD): ...@@ -349,9 +349,9 @@ class SysInfoOpenBSD(SysInfoBSD):
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
self._net_routing_table = 'Warning: "route -n show" command failed.\n' self._net_routing_table = 'Warning: "route -n show" command failed.\n'
class SysInfoFreeBSD(SysInfoBSD): class SysInfoFreeBSDOSX(SysInfoBSD):
"""FreeBSD implementation of the SysInfo class. """Shared code for the FreeBSD and OS X implementations of the SysInfo
See the SysInfo class documentation for more information. class. See the SysInfo class documentation for more information.
""" """
def __init__(self): def __init__(self):
super().__init__() super().__init__()
...@@ -360,12 +360,6 @@ class SysInfoFreeBSD(SysInfoBSD): ...@@ -360,12 +360,6 @@ class SysInfoFreeBSD(SysInfoBSD):
self._mem_cached = -1 self._mem_cached = -1
self._mem_buffers = -1 self._mem_buffers = -1
try:
s = subprocess.check_output(['sysctl', '-n', 'kern.smp.active'])
self._platform_is_smp = int(s.decode('utf-8').strip()) > 0
except (subprocess.CalledProcessError, OSError):
pass
try: try:
s = subprocess.check_output(['sysctl', '-n', 'kern.boottime']) s = subprocess.check_output(['sysctl', '-n', 'kern.boottime'])
t = s.decode('utf-8').strip() t = s.decode('utf-8').strip()
...@@ -389,6 +383,25 @@ class SysInfoFreeBSD(SysInfoBSD): ...@@ -389,6 +383,25 @@ class SysInfoFreeBSD(SysInfoBSD):
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
pass pass
try:
s = subprocess.check_output(['netstat', '-nr'])
self._net_routing_table = s.decode('utf-8')
except (subprocess.CalledProcessError, OSError):
self._net_connections = 'Warning: "netstat -nr" command failed.\n'
class SysInfoFreeBSD(SysInfoFreeBSDOSX):
"""FreeBSD implementation of the SysInfo class.
See the SysInfo class documentation for more information.
"""
def __init__(self):
super().__init()
try:
s = subprocess.check_output(['sysctl', '-n', 'kern.smp.active'])
self._platform_is_smp = int(s.decode('utf-8').strip()) > 0
except (subprocess.CalledProcessError, OSError):
pass
try: try:
s = subprocess.check_output(['vmstat', '-H']) s = subprocess.check_output(['vmstat', '-H'])
lines = s.decode('utf-8').split('\n') lines = s.decode('utf-8').split('\n')
...@@ -408,49 +421,22 @@ class SysInfoFreeBSD(SysInfoBSD): ...@@ -408,49 +421,22 @@ class SysInfoFreeBSD(SysInfoBSD):
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
pass pass
try:
s = subprocess.check_output(['netstat', '-nr'])
self._net_routing_table = s.decode('utf-8')
except (subprocess.CalledProcessError, OSError):
self._net_connections = 'Warning: "netstat -nr" command failed.\n'
class SysInfoOSX(SysInfoBSD):
class SysInfoOSX(SysInfoFreeBSDOSX):
"""OS X (Darwin) implementation of the SysInfo class. """OS X (Darwin) implementation of the SysInfo class.
See the SysInfo class documentation for more information. See the SysInfo class documentation for more information.
""" """
def __init__(self): def __init__(self):
super().__init__() super().__init__()
# Don't know how to gather these # note; this call overrides the value already set when hw.physmem
self._mem_cached = -1 # was read. However, on OSX, physmem is not necessarily the correct
self._mem_buffers = -1 # value. But since it does not fail and does work on most BSD's, it's
# left in the base class and overwritten here
try:
s = subprocess.check_output(['sysctl', '-n', 'kern.smp.active'])
self._platform_is_smp = int(s.decode('utf-8').strip()) > 0
except (subprocess.CalledProcessError, OSError):
pass
try:
s = subprocess.check_output(['sysctl', '-n', 'kern.boottime'])
t = s.decode('utf-8').strip()
r = re.match('^\{\s+sec\s+\=\s+(\d+),.*', t)
if r:
sec = time.time() - int(r.group(1))
self._uptime = int(round(sec))
except (subprocess.CalledProcessError, OSError):
pass
try: try:
s = subprocess.check_output(['sysctl', '-n', 'vm.loadavg']) s = subprocess.check_output(['sysctl', '-n', 'hw.memsize'])
l = s.decode('utf-8').strip() self._mem_total = int(s.decode('utf-8').strip())
r = re.match('^\{(.*)\}$', l)
if r:
la = r.group(1).strip().split(' ')
else:
la = l.split(' ')
if len(la) >= 3:
self._loadavg = [float(la[0]), float(la[1]), float(la[2])]
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
pass pass
...@@ -459,7 +445,7 @@ class SysInfoOSX(SysInfoBSD): ...@@ -459,7 +445,7 @@ class SysInfoOSX(SysInfoBSD):
lines = s.decode('utf-8').split('\n') lines = s.decode('utf-8').split('\n')
# store all values in a dict # store all values in a dict
values = {} values = {}
page_size = 4096 page_size = None
page_size_re = re.compile('page size of [0-9]+ bytes') page_size_re = re.compile('page size of [0-9]+ bytes')
for line in lines: for line in lines:
page_size_m = page_size_re.match(line) page_size_m = page_size_re.match(line)
...@@ -468,7 +454,10 @@ class SysInfoOSX(SysInfoBSD): ...@@ -468,7 +454,10 @@ class SysInfoOSX(SysInfoBSD):
else: else:
key, _, value = line.partition(':') key, _, value = line.partition(':')
values[key] = value.strip()[:-1] values[key] = value.strip()[:-1]
self._mem_free = int(values['Pages free']) * page_size # Only calculate memory if page size is known
if page_size is not None:
self._mem_free = int(values['Pages free']) * page_size +
int(values['Pages speculative']) * page_size
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
pass pass
...@@ -482,13 +471,6 @@ class SysInfoOSX(SysInfoBSD): ...@@ -482,13 +471,6 @@ class SysInfoOSX(SysInfoBSD):
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
pass pass
try:
s = subprocess.check_output(['netstat', '-nr'])
self._net_routing_table = s.decode('utf-8')
except (subprocess.CalledProcessError, OSError):
self._net_connections = 'Warning: "netstat -nr" command failed.\n'
class SysInfoTestcase(SysInfo): class SysInfoTestcase(SysInfo):
def __init__(self): def __init__(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment