BIND 10 trac2062, updated. b2a7049b19584687962588cd5695748541ddfc32 [2062] Update showtech tool to start showing info

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Jun 27 03:57:36 UTC 2012


The branch, trac2062 has been updated
       via  b2a7049b19584687962588cd5695748541ddfc32 (commit)
      from  86b50d54a6e3eac0275314ddeb77eb8ad5fbab73 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b2a7049b19584687962588cd5695748541ddfc32
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jun 27 09:27:20 2012 +0530

    [2062] Update showtech tool to start showing info

-----------------------------------------------------------------------

Summary of changes:
 src/bin/showtech/showtech.py.in        |   43 ++++++++++--
 src/lib/python/isc/sysinfo/Makefile.am |    3 +-
 src/lib/python/isc/sysinfo/__init__.py |    2 +-
 src/lib/python/isc/sysinfo/cpu.py      |   33 ---------
 src/lib/python/isc/sysinfo/platform.py |   20 ------
 src/lib/python/isc/sysinfo/sysinfo.py  |  120 ++++++++++++++++++++++++++++++++
 6 files changed, 158 insertions(+), 63 deletions(-)
 delete mode 100644 src/lib/python/isc/sysinfo/cpu.py
 delete mode 100644 src/lib/python/isc/sysinfo/platform.py
 create mode 100644 src/lib/python/isc/sysinfo/sysinfo.py

-----------------------------------------------------------------------
diff --git a/src/bin/showtech/showtech.py.in b/src/bin/showtech/showtech.py.in
index 0f60ecc..abcebfe 100755
--- a/src/bin/showtech/showtech.py.in
+++ b/src/bin/showtech/showtech.py.in
@@ -21,14 +21,43 @@ BIND 10 showtech program.
 """
 
 import sys; sys.path.append ('@@PYTHONPATH@@')
-from isc.sysinfo import CPU
-
-def show_cpu():
-    print("Number of processors (hyperthreads):")
-    print(CPU.get_num_processors())
+from isc.sysinfo import *
 
 def main():
-    show_cpu()
+    s = SysInfo()
+
+    print('BIND 10 ShowTech tool')
+    print('---------------------')
+
+    print('\nCPU');
+    print(' + Number of processors: ' + str(s.get_num_processors()))
+    print(' + Endianness: ' + s.get_endianness())
+
+    print('\nPlatform');
+    print(' + Operating system: ' + s.get_platform_name())
+    print(' + Kernel version: ' + s.get_platform_version())
+    if s.get_platform_is_smp():
+        print(' + SMP kernel: yes')
+    else:
+        print(' + SMP kernel: no')
+    print(' + Machine name: ' + s.get_platform_machine())
+    print(' + Uptime: %d seconds' % (s.get_uptime()))
+
+    l = s.get_loadavg()
+    print(' + Loadavg: %f %f %f' % (l[0], l[1], l[2]))
+
+    print('\nMemory');
+    print(' + Total: %d bytes' % (s.get_mem_total()))
+    print(' + Free: %d bytes' % (s.get_mem_free()))
+    print(' + Cached: %d bytes' % (s.get_mem_cached()))
+    print(' + Buffers: %d bytes' % (s.get_mem_buffers()))
+    print(' + Swap total: %d bytes' % (s.get_mem_swap_total()))
+    print(' + Swap free: %d bytes' % (s.get_mem_swap_free()))
+
+    print('\nNetwork');
+    print(' + Hostname: ' + s.get_hostname())
+
+    print('')
 
-if __name__ == "__main__":
+if __name__ == '__main__':
     main()
diff --git a/src/lib/python/isc/sysinfo/Makefile.am b/src/lib/python/isc/sysinfo/Makefile.am
index 4028b39..970fbed 100644
--- a/src/lib/python/isc/sysinfo/Makefile.am
+++ b/src/lib/python/isc/sysinfo/Makefile.am
@@ -1,6 +1,5 @@
 python_PYTHON = __init__.py
-python_PYTHON += cpu.py
-python_PYTHON += platform.py
+python_PYTHON += sysinfo.py
 
 pythondir = $(pyexecdir)/isc/sysinfo
 
diff --git a/src/lib/python/isc/sysinfo/__init__.py b/src/lib/python/isc/sysinfo/__init__.py
index 3dcf84c..c632b30 100644
--- a/src/lib/python/isc/sysinfo/__init__.py
+++ b/src/lib/python/isc/sysinfo/__init__.py
@@ -1 +1 @@
-from isc.sysinfo.cpu import *
+from isc.sysinfo.sysinfo import *
diff --git a/src/lib/python/isc/sysinfo/cpu.py b/src/lib/python/isc/sysinfo/cpu.py
deleted file mode 100644
index d126b66..0000000
--- a/src/lib/python/isc/sysinfo/cpu.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
-# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
-# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
-# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
-# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-'''This module returns CPU information.'''
-
-import os
-import sys
-
-class CPU:
-    def get_num_cores():
-        # Not implemented
-        return -1
-
-    def get_num_processors():
-        # This is the number of hyperthreads when hyper-threading is
-        # used. This is not entirely portable, so we'll have to handle
-        # the case when it's not available.
-        return os.sysconf('SC_NPROCESSORS_CONF')
-
-    def get_endianness():
-        return sys.byteorder
diff --git a/src/lib/python/isc/sysinfo/platform.py b/src/lib/python/isc/sysinfo/platform.py
deleted file mode 100644
index f0646f3..0000000
--- a/src/lib/python/isc/sysinfo/platform.py
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
-# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
-# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
-# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
-# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
-# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-'''This module returns platform information (about the distro).'''
-
-class Platform:
-    def get_arch():
-        return ""
diff --git a/src/lib/python/isc/sysinfo/sysinfo.py b/src/lib/python/isc/sysinfo/sysinfo.py
new file mode 100644
index 0000000..f718e48
--- /dev/null
+++ b/src/lib/python/isc/sysinfo/sysinfo.py
@@ -0,0 +1,120 @@
+# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
+# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+'''This module returns CPU information.'''
+
+import os
+import sys
+import re
+
+class SysInfo:
+    def __init__(self):
+        self._num_processors = os.sysconf('SC_NPROCESSORS_CONF')
+        self._endianness = sys.byteorder
+
+        with open('/proc/sys/kernel/hostname') as f:
+            self._hostname = f.read().strip()
+
+        u = os.uname()
+        self._platform_name = u[0]
+        self._platform_version = u[2]
+        self._platform_machine = u[4]
+
+        with open('/proc/version') as f:
+            self._platform_is_smp = ' SMP ' in f.read().strip()
+
+        with open('/proc/uptime') as f:
+            u = f.read().strip().split(' ')
+            self._uptime = int(round(float(u[0])))
+
+        with open('/proc/loadavg') as f:
+            l = f.read().strip().split(' ')
+            self._loadavg = [float(l[0]), float(l[1]), float(l[2])]
+
+        with open('/proc/meminfo') as f:
+            m = f.readlines()
+            for line in m:
+                r = re.match('^MemTotal:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_total = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^MemFree:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_free = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^Cached:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_cached = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^Buffers:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_buffers = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^SwapTotal:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_swap_total = int(r.group(1).strip()) * 1024
+                    continue
+                r = re.match('^SwapFree:\s+(.*)\s*kB', line)
+                if r:
+                    self._mem_swap_free = int(r.group(1).strip()) * 1024
+                    continue
+
+    def get_num_processors(self):
+        # This is the number of hyperthreads when hyper-threading is
+        # used. This is not entirely portable, so we'll have to handle
+        # the case when it's not available.
+        return self._num_processors
+
+    def get_endianness(self):
+        return self._endianness
+
+    def get_hostname(self):
+        return self._hostname
+
+    def get_platform_name(self):
+        return self._platform_name
+
+    def get_platform_version(self):
+        return self._platform_version
+
+    def get_platform_machine(self):
+        return self._platform_machine
+
+    def get_platform_is_smp(self):
+        return self._platform_is_smp
+
+    def get_uptime(self):
+        return self._uptime
+
+    def get_loadavg(self):
+        return self._loadavg
+
+    def get_mem_total(self):
+        return self._mem_total
+
+    def get_mem_free(self):
+        return self._mem_free
+
+    def get_mem_cached(self):
+        return self._mem_cached
+
+    def get_mem_buffers(self):
+        return self._mem_buffers
+
+    def get_mem_swap_total(self):
+        return self._mem_swap_total
+
+    def get_mem_swap_free(self):
+        return self._mem_swap_free



More information about the bind10-changes mailing list