diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-08 13:25:44 -0400 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-08 13:25:44 -0400 |
| commit | 8864a4018c9b9088f330c3ef24ed7b5313ec36a2 (patch) | |
| tree | 2fe858d60c8c0a41b97002216949097887652f82 | |
| parent | 56a7f70965a17509898cf9e7eafb4e13208e5358 (diff) | |
Added -j option to send jabber update messages.
| -rw-r--r-- | run/experiment.py | 2 | ||||
| -rw-r--r-- | run/jabber.py | 40 | ||||
| -rwxr-xr-x | run_exps.py | 26 |
3 files changed, 65 insertions, 3 deletions
diff --git a/run/experiment.py b/run/experiment.py index ecb0241..03d6ab6 100644 --- a/run/experiment.py +++ b/run/experiment.py | |||
| @@ -52,7 +52,7 @@ class Experiment(object): | |||
| 52 | self.log("Enabling sched_trace") | 52 | self.log("Enabling sched_trace") |
| 53 | self.tracers.append( SchedTracer(working_dir) ) | 53 | self.tracers.append( SchedTracer(working_dir) ) |
| 54 | if LinuxTracer.enabled(): | 54 | if LinuxTracer.enabled(): |
| 55 | self.log("Enabling trace-cmd / ftrace / kernelshark") | 55 | self.log("Enabling trace-cmd") |
| 56 | self.tracers.append( LinuxTracer(working_dir) ) | 56 | self.tracers.append( LinuxTracer(working_dir) ) |
| 57 | if LogTracer.enabled(): | 57 | if LogTracer.enabled(): |
| 58 | self.log("Enabling logging") | 58 | self.log("Enabling logging") |
diff --git a/run/jabber.py b/run/jabber.py new file mode 100644 index 0000000..c9dd097 --- /dev/null +++ b/run/jabber.py | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #!/usr/bin/env python | ||
| 2 | import os | ||
| 3 | import sys | ||
| 4 | import xmpp | ||
| 5 | |||
| 6 | class Jabber(object): | ||
| 7 | def __init__(self, target): | ||
| 8 | self.target = target | ||
| 9 | self.client = self.__create_client() | ||
| 10 | |||
| 11 | def __create_client(self): | ||
| 12 | params = {} | ||
| 13 | conf_file = os.environ['HOME'] + '/.xsend' | ||
| 14 | |||
| 15 | if os.access(conf_file, os.R_OK): | ||
| 16 | for line in open(conf_file, 'r').readlines(): | ||
| 17 | key, val = line.strip().split('=', 1) | ||
| 18 | params[key.lower()] = val | ||
| 19 | |||
| 20 | for field in ['login', 'password']: | ||
| 21 | if field not in params.keys(): | ||
| 22 | with open(conf_file, 'wc') as f: | ||
| 23 | f.write('#LOGIN=romeo@montague.net\n#PASSWORD=juliet\n') | ||
| 24 | raise IOError("Please ensure the ~/.xsend file has valid "+\ | ||
| 25 | "credentials for sending messages.") | ||
| 26 | |||
| 27 | jid = xmpp.protocol.JID(params['login']) | ||
| 28 | client = xmpp.Client(jid.getDomain(), debug=[]) | ||
| 29 | |||
| 30 | client.connect(server=(jid.getDomain(), 5223)) | ||
| 31 | client.auth(jid.getNode(), params['password']) | ||
| 32 | |||
| 33 | sys.stderr.write(("Jabber client loaded. Add '%s' to your friends " + \ | ||
| 34 | "or Jabber messages will not send") % params['login']) | ||
| 35 | |||
| 36 | return client | ||
| 37 | |||
| 38 | def send(self, text): | ||
| 39 | message = xmpp.protocol.Message(to=self.target, body=text, typ='chat') | ||
| 40 | self.client.send(message) | ||
diff --git a/run_exps.py b/run_exps.py index dd75999..c51f4c6 100755 --- a/run_exps.py +++ b/run_exps.py | |||
| @@ -6,6 +6,7 @@ import config.config as conf | |||
| 6 | import os | 6 | import os |
| 7 | import re | 7 | import re |
| 8 | import shutil | 8 | import shutil |
| 9 | import sys | ||
| 9 | import traceback | 10 | import traceback |
| 10 | 11 | ||
| 11 | from collections import namedtuple | 12 | from collections import namedtuple |
| @@ -56,6 +57,9 @@ def parse_args(): | |||
| 56 | default=conf.DEFAULTS['sched_file']) | 57 | default=conf.DEFAULTS['sched_file']) |
| 57 | parser.add_option('-f', '--force', action='store_true', default=False, | 58 | parser.add_option('-f', '--force', action='store_true', default=False, |
| 58 | dest='force', help='overwrite existing data') | 59 | dest='force', help='overwrite existing data') |
| 60 | parser.add_option('-j', '--jabber', metavar='username@domain', | ||
| 61 | dest='jabber', default=None, | ||
| 62 | help='send a jabber message when an experiment completes') | ||
| 59 | 63 | ||
| 60 | return parser.parse_args() | 64 | return parser.parse_args() |
| 61 | 65 | ||
| @@ -120,7 +124,7 @@ def verify_environment(kernel, copts): | |||
| 120 | raise InvalidConfig(results) | 124 | raise InvalidConfig(results) |
| 121 | 125 | ||
| 122 | def load_experiment(sched_file, scheduler, duration, | 126 | def load_experiment(sched_file, scheduler, duration, |
| 123 | param_file, out_dir, ignore): | 127 | param_file, out_dir, ignore, jabber): |
| 124 | if not os.path.isfile(sched_file): | 128 | if not os.path.isfile(sched_file): |
| 125 | raise IOError("Cannot find schedule file: %s" % sched_file) | 129 | raise IOError("Cannot find schedule file: %s" % sched_file) |
| 126 | 130 | ||
| @@ -161,6 +165,9 @@ def load_experiment(sched_file, scheduler, duration, | |||
| 161 | 165 | ||
| 162 | run_exp(exp_name, schedule, scheduler, kernel, duration, work_dir, out_dir) | 166 | run_exp(exp_name, schedule, scheduler, kernel, duration, work_dir, out_dir) |
| 163 | 167 | ||
| 168 | if jabber: | ||
| 169 | jabber.send("Completed '%s'" % exp_name) | ||
| 170 | |||
| 164 | # Save parameters used to run experiment in out_dir | 171 | # Save parameters used to run experiment in out_dir |
| 165 | out_params = dict(params.items() + | 172 | out_params = dict(params.items() + |
| 166 | [(conf.PARAMS['sched'], scheduler), | 173 | [(conf.PARAMS['sched'], scheduler), |
| @@ -228,6 +235,16 @@ def run_exp(name, schedule, scheduler, kernel, duration, work_dir, out_dir): | |||
| 228 | 235 | ||
| 229 | exp.run_exp() | 236 | exp.run_exp() |
| 230 | 237 | ||
| 238 | def setup_jabber(target): | ||
| 239 | try: | ||
| 240 | from run.jabber import Jabber | ||
| 241 | |||
| 242 | return Jabber(target) | ||
| 243 | except ImportError: | ||
| 244 | sys.stderr.write("Failed to import jabber. Is python-xmpppy "+\ | ||
| 245 | "installed?\nDisabling Jabber messaging.\n") | ||
| 246 | return None | ||
| 247 | |||
| 231 | def main(): | 248 | def main(): |
| 232 | opts, args = parse_args() | 249 | opts, args = parse_args() |
| 233 | 250 | ||
| @@ -248,6 +265,11 @@ def main(): | |||
| 248 | failed = 0 | 265 | failed = 0 |
| 249 | invalid = 0 | 266 | invalid = 0 |
| 250 | 267 | ||
| 268 | if opts.jabber: | ||
| 269 | jabber = setup_jabber(opts.jabber) | ||
| 270 | else: | ||
| 271 | jabber = None | ||
| 272 | |||
| 251 | for exp in args: | 273 | for exp in args: |
| 252 | path = "%s/%s" % (os.getcwd(), exp) | 274 | path = "%s/%s" % (os.getcwd(), exp) |
| 253 | out_dir = "%s/%s" % (out_base, os.path.split(exp.strip('/'))[1]) | 275 | out_dir = "%s/%s" % (out_base, os.path.split(exp.strip('/'))[1]) |
| @@ -263,7 +285,7 @@ def main(): | |||
| 263 | 285 | ||
| 264 | try: | 286 | try: |
| 265 | load_experiment(path, scheduler, duration, param_file, | 287 | load_experiment(path, scheduler, duration, param_file, |
| 266 | out_dir, opts.ignore) | 288 | out_dir, opts.ignore, jabber) |
| 267 | succ += 1 | 289 | succ += 1 |
| 268 | except ExperimentDone: | 290 | except ExperimentDone: |
| 269 | done += 1 | 291 | done += 1 |
