Skip to content
Browse files

added optional output_dir to logalyzer

rational: Alon said separating job output to files would make logalyzer more useful
  • Loading branch information...
1 parent e19071a commit f8c5c9c3c6310a9833bb438a12c6c1e1f423880f @lirazsiri lirazsiri committed with lirazsiri Aug 16, 2013
Showing with 36 additions and 4 deletions.
  1. +24 −1 cloudtask/logalyzer.py
  2. +12 −3 cmd_logalyzer.py
View
25 cloudtask/logalyzer.py
@@ -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()
@@ -311,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 ]
@@ -335,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
15 cmd_logalyzer.py
@@ -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 f8c5c9c

Please sign in to comment.
Something went wrong with that request. Please try again.