diff options
author | Clark Williams <williams@redhat.com> | 2010-08-23 13:09:53 -0500 |
---|---|---|
committer | Clark Williams <williams@redhat.com> | 2010-08-23 13:09:53 -0500 |
commit | e1ce277b4a681e22e1bf6c7b724c63ea82971cb9 (patch) | |
tree | 4e5622cc37f04ac46e7bf9fde233262a4196831e /rteval | |
parent | 85ae9abb14d9bd684e3e8cfa376e29b39ac294d5 (diff) | |
download | rteval-e1ce277b4a681e22e1bf6c7b724c63ea82971cb9.tar.gz rteval-e1ce277b4a681e22e1bf6c7b724c63ea82971cb9.tar.xz rteval-e1ce277b4a681e22e1bf6c7b724c63ea82971cb9.zip |
create utility module with common system tasks
refactor some methods from rteval into a commmon utility module
for use by loads and cyclictest.
Signed-off-by: Clark Williams <williams@redhat.com>
Diffstat (limited to 'rteval')
-rw-r--r-- | rteval/util.py | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/rteval/util.py b/rteval/util.py new file mode 100644 index 0000000..79834a8 --- /dev/null +++ b/rteval/util.py @@ -0,0 +1,96 @@ +#!/usr/bin/python -tt +# +# platform utility functions used by various parts of rteval +# + +import sys +import os +import os.path +import subprocess + +def get_base_os(): + '''record what userspace we're running on''' + distro = "unknown" + for f in ('redhat-release', 'fedora-release'): + p = os.path.join('/etc', f) + if os.path.exists(p): + f = open(p, 'r') + distro = f.readline().strip() + f.close() + break + return distro + +def get_num_nodes(): + from glob import glob + nodes = len(glob('/sys/devices/system/node/node*')) + return nodes + +def get_memory_size(): + '''find out how much memory is installed''' + f = open('/proc/meminfo') + rawsize = 0 + for l in f: + if l.startswith('MemTotal:'): + parts = l.split() + if parts[2].lower() != 'kb': + raise RuntimeError, "Units changed from kB! (%s)" % parts[2] + rawsize = int(parts[1]) + f.close() + break + if rawsize == 0: + raise RuntimeError, "can't find memtotal in /proc/meminfo!" + + # Get a more readable result + # Note that this depends on /proc/meminfo starting in Kb + units = ('KB', 'MB','GB','TB') + size = rawsize + for unit in units: + if size < 1024: + break + size = float(size) / 1024 + return (size, unit) + + +def get_clocksources(): + '''get the available and curent clocksources for this kernel''' + path = '/sys/devices/system/clocksource/clocksource0' + if not os.path.exists(path): + raise RuntimeError, "Can't find clocksource path in /sys" + f = open (os.path.join (path, "current_clocksource")) + current_clocksource = f.readline().strip() + f = open (os.path.join (path, "available_clocksource")) + available_clocksource = f.readline().strip() + f.close() + return (current_clocksource, available_clocksource) + + +def get_modules(): + modlist = [] + try: + fp = open('/proc/modules', 'r') + line = fp.readline() + while line: + mod = line.split() + modlist.append({"modname": mod[0], + "modsize": mod[1], + "numusers": mod[2], + "usedby": mod[3], + "modstate": mod[4]}) + line = fp.readline() + fp.close() + except Exception, err: + raise err + return modlist + + +if __name__ == "__main__": + print "\tRunning on %s" % get_base_os() + print "\tNUMA nodes: %d" % get_num_nodes() + print "\tMemory available: %03.2f %s" % get_memory_size() + (curr, avail) = get_clocksources() + print "\tCurrent clocksource: %s" % curr + print "\tAvailable clocksources: %s" % avail + print "\tModules:" + for m in get_modules(): + print "\t\t%s: %s" % (m['modname'], m['modstate']) + |