From b43b83beead92ff7cf28a5fe5a2710537268aae1 Mon Sep 17 00:00:00 2001 From: Jonathan Herman Date: Mon, 26 Nov 2012 17:06:27 -0500 Subject: Read locations of binary files from path instead of config.py. --- experiment/litmus_util.py | 79 ----------------------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 experiment/litmus_util.py (limited to 'experiment/litmus_util.py') diff --git a/experiment/litmus_util.py b/experiment/litmus_util.py deleted file mode 100644 index fb2b341..0000000 --- a/experiment/litmus_util.py +++ /dev/null @@ -1,79 +0,0 @@ -import re -import time -import subprocess -import os -import stat -import config.config as conf - -def num_cpus(): - '''Return the number of CPUs in the system.''' - - lnx_re = re.compile(r'^(processor|online)') - cpus = 0 - - with open('/proc/cpuinfo', 'r') as f: - for line in f: - if lnx_re.match(line): - cpus += 1 - return cpus - -def cpu_freq(): - ''' - The frequency (in MHz) of the CPU. - ''' - reg = re.compile(r'^cpu MHz\s*:\s*(\d+)', re.M) - with open('/proc/cpuinfo', 'r') as f: - data = f.read() - - match = re.search(reg, data) - if not match: - raise Exception("Cannot parse CPU frequency!") - return int(match.group(1)) - -def switch_scheduler(switch_to_in): - '''Switch the scheduler to whatever is passed in. - - This methods sleeps for two seconds to give Linux the chance to execute - schedule switching code. Raises an exception if the switch does not work. - - ''' - - switch_to = str(switch_to_in).strip() - - with open('/proc/litmus/active_plugin', 'w') as active_plugin: - subprocess.Popen(["echo", switch_to], stdout=active_plugin) - - # it takes a bit to do the switch, sleep an arbitrary amount of time - time.sleep(2) - - with open('/proc/litmus/active_plugin', 'r') as active_plugin: - cur_plugin = active_plugin.read().strip() - - if switch_to != cur_plugin: - raise Exception("Could not switch to plugin: %s" % switch_to) - -def uname_matches(reg): - data = subprocess.check_output(["uname", "-r"]) - return bool( re.match(reg, data) ) - -def is_executable(fname): - '''Return whether the file passed in is executable''' - mode = os.stat(fname)[stat.ST_MODE] - return mode & stat.S_IXUSR and mode & stat.S_IRUSR - -def is_device(dev): - if not os.path.exists(dev): - return False - mode = os.stat(dev)[stat.ST_MODE] - return not (not mode & stat.S_IFCHR) - -def release_tasks(): - - try: - data = subprocess.check_output([conf.BINS['release']]) - except subprocess.CalledProcessError: - raise Exception('Something went wrong in release_ts') - - released = re.findall(r"([0-9]+) real-time", data)[0] - - return int(released) -- cgit v1.2.2