diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 14:35:37 -0400 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 14:35:37 -0400 |
| commit | 4162cc0c57de22566efa6e2dab224909279f2a47 (patch) | |
| tree | a8628096c4161e658c385b07b026371a2ef5e3c4 | |
| parent | 37a410ab7d4ba991a075a3b2f4d24a656f4544ca (diff) | |
run_exps will run any command whose last argument is the duration.
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | common.py | 47 | ||||
| -rw-r--r-- | config/config.py | 20 | ||||
| -rw-r--r-- | run/proc_entry.py | 5 | ||||
| -rwxr-xr-x | run_exps.py | 71 |
5 files changed, 69 insertions, 76 deletions
| @@ -99,7 +99,7 @@ Schedule files have one of the following two formats: | |||
| 99 | ..., | 99 | ..., |
| 100 | ('path/to/proc','proc_value') | 100 | ('path/to/proc','proc_value') |
| 101 | ], | 101 | ], |
| 102 | 'spin':[ | 102 | 'task':[ |
| 103 | ('real_time_task', 'task_arguments'), | 103 | ('real_time_task', 'task_arguments'), |
| 104 | ... | 104 | ... |
| 105 | ('real_time_task', 'task_arguments') | 105 | ('real_time_task', 'task_arguments') |
| @@ -7,29 +7,34 @@ import sys | |||
| 7 | from collections import defaultdict | 7 | from collections import defaultdict |
| 8 | from textwrap import dedent | 8 | from textwrap import dedent |
| 9 | 9 | ||
| 10 | def get_executable(prog, hint='unknown', optional=False): | 10 | def get_executable(prog, cwd="."): |
| 11 | '''Search for @prog in system PATH. Print @hint if no binary is found.''' | 11 | '''Search for @prog in system PATH and @cwd.''' |
| 12 | 12 | ||
| 13 | def is_exe(fpath): | 13 | cwd_path = "%s/%s" % (cwd, prog) |
| 14 | return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | 14 | if is_executable(cwd_path): |
| 15 | 15 | return cwd_path | |
| 16 | fpath, fname = os.path.split(prog) | ||
| 17 | if fpath: | ||
| 18 | if is_exe(prog): | ||
| 19 | return prog | ||
| 20 | else: | 16 | else: |
| 21 | for path in os.environ["PATH"].split(os.pathsep): | 17 | for path in os.environ["PATH"].split(os.pathsep): |
| 22 | exe_file = os.path.join(path, prog) | 18 | exe_file = os.path.join(path, prog) |
| 23 | if is_exe(exe_file): | 19 | if is_executable(exe_file): |
| 24 | return exe_file | 20 | return exe_file |
| 25 | 21 | ||
| 26 | if not optional: | 22 | full_cwd = os.path.abspath(cwd) |
| 27 | sys.stderr.write("Cannot find executable '%s' in PATH. This is a part " | 23 | raise IOError("Cannot find executable '%s'! (cwd='%s')" % (prog, full_cwd)) |
| 28 | "of '%s' which should be added to PATH to run.\n" % | 24 | |
| 29 | (prog, hint)) | 25 | def get_executable_hint(prog, hint, optional=False): |
| 30 | sys.exit(1) | 26 | '''Search for @prog in system PATH. Print @hint if no binary is found. |
| 31 | else: | 27 | Die if not @optional.''' |
| 32 | return None | 28 | try: |
| 29 | prog = get_executable(prog) | ||
| 30 | except IOError: | ||
| 31 | if not optional: | ||
| 32 | sys.stderr.write(("Cannot find executable '%s' in PATH. This is " +\ | ||
| 33 | "a part of '%s' which should be added to PATH.\n")\ | ||
| 34 | % (prog, hint)) | ||
| 35 | sys.exit(1) | ||
| 36 | |||
| 37 | return prog | ||
| 33 | 38 | ||
| 34 | def get_config_option(option): | 39 | def get_config_option(option): |
| 35 | '''Search for @option in installed kernel config (if present). | 40 | '''Search for @option in installed kernel config (if present). |
| @@ -174,14 +179,12 @@ def ft_freq(): | |||
| 174 | return freq | 179 | return freq |
| 175 | 180 | ||
| 176 | 181 | ||
| 177 | def uname_matches(reg): | 182 | def kernel(): |
| 178 | data = subprocess.check_output(["uname", "-r"]) | 183 | return subprocess.check_output(["uname", "-r"]) |
| 179 | return bool( re.match(reg, data) ) | ||
| 180 | 184 | ||
| 181 | def is_executable(fname): | 185 | def is_executable(fname): |
| 182 | '''Return whether the file passed in is executable''' | 186 | '''Return whether the file passed in is executable''' |
| 183 | mode = os.stat(fname)[stat.ST_MODE] | 187 | return os.path.isfile(fname) and os.access(fname, os.X_OK) |
| 184 | return mode & stat.S_IXUSR and mode & stat.S_IRUSR | ||
| 185 | 188 | ||
| 186 | def is_device(dev): | 189 | def is_device(dev): |
| 187 | if not os.path.exists(dev): | 190 | if not os.path.exists(dev): |
diff --git a/config/config.py b/config/config.py index 3486a40..cbac6b2 100644 --- a/config/config.py +++ b/config/config.py | |||
| @@ -1,18 +1,18 @@ | |||
| 1 | from __future__ import print_function | 1 | from __future__ import print_function |
| 2 | import itertools | 2 | import itertools |
| 3 | from common import get_executable,ft_freq | 3 | from common import get_executable_hint,ft_freq |
| 4 | 4 | ||
| 5 | '''Paths to binaries.''' | 5 | '''Paths to binaries.''' |
| 6 | BINS = {'rtspin' : get_executable('rtspin', 'liblitmus'), | 6 | BINS = {'rtspin' : get_executable_hint('rtspin', 'liblitmus'), |
| 7 | 'release' : get_executable('release_ts', 'liblitmus'), | 7 | 'release' : get_executable_hint('release_ts', 'liblitmus'), |
| 8 | 'ftcat' : get_executable('ftcat', 'feather-trace-tools'), | 8 | 'ftcat' : get_executable_hint('ftcat', 'feather-trace-tools'), |
| 9 | 'ftsplit' : get_executable('ft2csv', 'feather-trace-tools'), | 9 | 'ftsplit' : get_executable_hint('ft2csv', 'feather-trace-tools'), |
| 10 | 'ftsort' : get_executable('ftsort', 'feather-trace-tools'), | 10 | 'ftsort' : get_executable_hint('ftsort', 'feather-trace-tools'), |
| 11 | 'st_trace' : get_executable('st_trace', 'feather-trace-tools'), | 11 | 'st_trace' : get_executable_hint('st_trace', 'feather-trace-tools'), |
| 12 | # Option, as not everyone uses kernelshark yet | 12 | # Option, as not everyone uses kernelshark yet |
| 13 | 'trace-cmd' : get_executable('trace-cmd', 'rt-kernelshark', True), | 13 | 'trace-cmd' : get_executable_hint('trace-cmd', 'rt-kernelshark', True), |
| 14 | # Optional, as sched_trace is not a publically supported repository | 14 | # Optional, as sched_trace is not a publically supported repository |
| 15 | 'st_show' : get_executable('st_show', 'sched_trace', True)} | 15 | 'st_show' : get_executable_hint('st_show', 'sched_trace', True)} |
| 16 | 16 | ||
| 17 | '''Names of output files.''' | 17 | '''Names of output files.''' |
| 18 | FILES = {'ft_data' : 'ft.bin', | 18 | FILES = {'ft_data' : 'ft.bin', |
| @@ -38,7 +38,7 @@ PARAMS = {'sched' : 'scheduler', # Scheduler used by run_exps | |||
| 38 | DEFAULTS = {'params_file' : 'params.py', | 38 | DEFAULTS = {'params_file' : 'params.py', |
| 39 | 'sched_file' : 'sched.py', | 39 | 'sched_file' : 'sched.py', |
| 40 | 'duration' : 10, | 40 | 'duration' : 10, |
| 41 | 'spin' : 'rtspin', | 41 | 'prog' : 'rtspin', |
| 42 | 'cycles' : ft_freq() or 2000} | 42 | 'cycles' : ft_freq() or 2000} |
| 43 | 43 | ||
| 44 | '''Default sched_trace events (this is all of them).''' | 44 | '''Default sched_trace events (this is all of them).''' |
diff --git a/run/proc_entry.py b/run/proc_entry.py index 4ac2c51..56f7c24 100644 --- a/run/proc_entry.py +++ b/run/proc_entry.py | |||
| @@ -5,9 +5,10 @@ class ProcEntry(object): | |||
| 5 | self.proc = proc | 5 | self.proc = proc |
| 6 | self.data = data | 6 | self.data = data |
| 7 | 7 | ||
| 8 | def write_proc(self): | ||
| 9 | if not os.path.exists(self.proc): | 8 | if not os.path.exists(self.proc): |
| 10 | raise Exception("Invalid proc entry %s" % self.proc) | 9 | raise ValueError("Invalid proc entry %s" % self.proc) |
| 10 | |||
| 11 | def write_proc(self): | ||
| 11 | try: | 12 | try: |
| 12 | with open(self.proc, 'w') as entry: | 13 | with open(self.proc, 'w') as entry: |
| 13 | entry.write(self.data) | 14 | entry.write(self.data) |
diff --git a/run_exps.py b/run_exps.py index 6043931..77c9631 100755 --- a/run_exps.py +++ b/run_exps.py | |||
| @@ -79,13 +79,13 @@ def convert_data(data): | |||
| 79 | r"(?P<HEADER>/proc/[\w\-]+?/)?" | 79 | r"(?P<HEADER>/proc/[\w\-]+?/)?" |
| 80 | r"(?P<ENTRY>[\w\-\/]+)" | 80 | r"(?P<ENTRY>[\w\-\/]+)" |
| 81 | r"\s*{\s*(?P<CONTENT>.*?)\s*?}$)|" | 81 | r"\s*{\s*(?P<CONTENT>.*?)\s*?}$)|" |
| 82 | r"(?P<SPIN>^" | 82 | r"(?P<TASK>^" |
| 83 | r"(?:(?P<TYPE>[^\d\-\s]\w*?) )?\s*" | 83 | r"(?:(?P<PROG>[^\d\-\s][\w\.]*?) )?\s*" |
| 84 | r"(?P<ARGS>[\w\-_\d\. \=]+)\s*$)", | 84 | r"(?P<ARGS>[\w\-_\d\. \=]+)\s*$)", |
| 85 | re.S|re.I|re.M) | 85 | re.S|re.I|re.M) |
| 86 | 86 | ||
| 87 | procs = [] | 87 | procs = [] |
| 88 | spins = [] | 88 | tasks = [] |
| 89 | 89 | ||
| 90 | for match in regex.finditer(data): | 90 | for match in regex.finditer(data): |
| 91 | if match.group("PROC"): | 91 | if match.group("PROC"): |
| @@ -94,16 +94,16 @@ def convert_data(data): | |||
| 94 | proc = (loc, match.group("CONTENT")) | 94 | proc = (loc, match.group("CONTENT")) |
| 95 | procs.append(proc) | 95 | procs.append(proc) |
| 96 | else: | 96 | else: |
| 97 | prog = match.group("TYPE") or "rtspin" | 97 | prog = match.group("PROG") or conf.DEFAULTS['prog'] |
| 98 | spin = (prog, match.group("ARGS")) | 98 | spin = (prog, match.group("ARGS")) |
| 99 | spins.append(spin) | 99 | tasks.append(spin) |
| 100 | 100 | ||
| 101 | return {'proc' : procs, 'spin' : spins} | 101 | return {'proc' : procs, 'task' : tasks} |
| 102 | 102 | ||
| 103 | 103 | ||
| 104 | def fix_paths(schedule, exp_dir, sched_file): | 104 | def fix_paths(schedule, exp_dir, sched_file): |
| 105 | '''Replace relative paths of command line arguments with absolute ones.''' | 105 | '''Replace relative paths of command line arguments with absolute ones.''' |
| 106 | for (idx, (spin, args)) in enumerate(schedule['spin']): | 106 | for (idx, (task, args)) in enumerate(schedule['task']): |
| 107 | for arg in re.split(" +", args): | 107 | for arg in re.split(" +", args): |
| 108 | abspath = "%s/%s" % (exp_dir, arg) | 108 | abspath = "%s/%s" % (exp_dir, arg) |
| 109 | if os.path.exists(abspath): | 109 | if os.path.exists(abspath): |
| @@ -113,7 +113,7 @@ def fix_paths(schedule, exp_dir, sched_file): | |||
| 113 | print("WARNING: non-existent file '%s' may be referenced:\n\t%s" | 113 | print("WARNING: non-existent file '%s' may be referenced:\n\t%s" |
| 114 | % (arg, sched_file)) | 114 | % (arg, sched_file)) |
| 115 | 115 | ||
| 116 | schedule['spin'][idx] = (spin, args) | 116 | schedule['task'][idx] = (task, args) |
| 117 | 117 | ||
| 118 | 118 | ||
| 119 | def load_schedule(name, fname, duration): | 119 | def load_schedule(name, fname, duration): |
| @@ -126,48 +126,43 @@ def load_schedule(name, fname, duration): | |||
| 126 | except: | ||
