Permalink
Browse files

Merge remote branch 'liraz/master'

  • Loading branch information...
2 parents 4763e72 + f8c5c9c commit 5dc71d26b6b91ea4616a398b7d926d753751abbd @alonswartz alonswartz committed Aug 21, 2013
Showing with 42 additions and 5 deletions.
  1. +30 −2 cloudtask/logalyzer.py
  2. +12 −3 cmd_logalyzer.py
View
@@ -11,6 +11,7 @@
import os
from os.path import *
from cloudtask.session import Session
+import paths
import re
@@ -191,9 +192,19 @@ def fmt_table(rows, title=[], groupby=None):
def indent(depth, buf):
return "\n".join([ " " * depth + line for line in buf.splitlines() ])
-def logalyzer(session_path):
+def mkdir(path):
+ if not exists(path):
+ os.makedirs(path)
+
+class OutputsPaths(paths.Paths):
+ files = ['failures', 'succeeded']
+
+def logalyzer(session_path, outputs_dir=None):
session_paths = Session.Paths(session_path)
+ if outputs_dir:
+ outputs_dir = OutputsPaths(outputs_dir)
+
conf = eval(file(session_paths.conf).read())
log = file(session_paths.log).read()
@@ -257,9 +268,14 @@ def header(level, s):
if attr in c and c[attr] ]))
fields = conf
+
+ fields['params'] = " ".join([ "%s=%s" % (k, c[k])
+ for k in ('timeout', 'retries', 'strikes')
+ if k in c ])
+
fields['workers'] = workers
- for field in ('command', 'backup_id', 'overlay', 'post', 'pre', 'timeout', 'report', '', 'workers'):
+ for field in ('command', 'backup_id', 'overlay', 'post', 'pre', '', 'params', '', 'report', '', 'workers'):
if not field:
print >> sio
elif field in fields and fields[field]:
@@ -306,6 +322,12 @@ def fN(v):
print >> sio, header(1, "Summary")
failures = [ job for job in jobs if job.result != 'exit 0' ]
+ if outputs_dir:
+ mkdir(outputs_dir.failures)
+ for job in failures:
+ fpath = join(outputs_dir.failures, job.name)
+ file(fpath, "w").write(job.output)
+
rows = [ (job.name, fmt_elapsed(job.elapsed), job.result, job.worker_id)
for job in failures ]
@@ -330,6 +352,12 @@ def fN(v):
print >> sio, header(0, "%d succeeded" % stats.succeeded)
completed = [ job for job in jobs if job.result == 'exit 0' ]
+ if outputs_dir:
+ mkdir(outputs_dir.succeeded)
+ for job in completed:
+ fpath = join(outputs_dir.succeeded, job.name)
+ file(fpath, "w").write(job.output)
+
rows = [ (job.name, fmt_elapsed(job.elapsed), job.worker_id)
for job in completed ]
fmted_table = fmt_table(rows, ["NAME", "ELAPSED", "WORKER"],
View
@@ -25,7 +25,7 @@ def usage(e=None):
if e:
print >> sys.stderr, "error: " + str(e)
- print >> sys.stderr, "Usage: %s path/to/session" % sys.argv[0]
+ print >> sys.stderr, "Usage: %s path/to/session [ path/to/outputs/ ]" % sys.argv[0]
print >> sys.stderr, __doc__.strip()
sys.exit(1)
@@ -45,14 +45,23 @@ def main():
if opt in ('-h', '--help'):
usage()
- if len(args) != 1:
+ if len(args) < 1:
usage()
session_path = args[0]
+
if not isdir(session_path):
fatal("not a directory '%s'" % session_path)
- print logalyzer.logalyzer(session_path)
+ if len(args) > 1:
+ outputs_dir = args[1]
+ if not isdir(outputs_dir):
+ fatal("not a directory '%s'" % outputs_dir)
+
+ else:
+ outputs_dir = None
+
+ print logalyzer.logalyzer(session_path, outputs_dir)
if __name__ == "__main__":
main()

0 comments on commit 5dc71d2

Please sign in to comment.