Skip to content
Browse files

Added salmonella-log-merger

  • Loading branch information...
1 parent 23b9a57 commit 3d58051e71eeaa2fe3d642168119f2056dd746d0 @mario-goulart committed Oct 1, 2011
Showing with 67 additions and 0 deletions.
  1. +62 −0 salmonella-log-merger.scm
  2. +5 −0 salmonella.setup
View
62 salmonella-log-merger.scm
@@ -0,0 +1,62 @@
+(use salmonella salmonella-log-parser)
+(include "salmonella-common.scm")
+
+(define (merge-logs log-files)
+ (let* ((logs (map read-log-file log-files))
+ (first-started
+ (let loop ((logs logs)
+ (first-started (caar logs)))
+ (if (null? logs)
+ first-started
+ (let* ((log (car logs))
+ (log-start (start-time log)))
+ (loop (cdr logs)
+ (if (< log-start (report-duration first-started))
+ (car log)
+ first-started))))))
+ (last-finished
+ (let loop ((logs logs)
+ (last-finished (last (car logs))))
+ (if (null? logs)
+ last-finished
+ (let* ((log (car logs))
+ (log-end (end-time log)))
+ (loop (cdr logs)
+ (if (> log-end (report-duration last-finished))
+ (last log)
+ last-finished)))))))
+
+ (append
+ (list (report->list first-started))
+ (let loop ((logs logs))
+ (if (null? logs)
+ '()
+ (append (map report->list
+ (butlast (cdr (car logs))))
+ (loop (cdr logs)))))
+ (list (report->list last-finished)))))
+
+
+(define (usage #!optional exit-code)
+ (let ((this (pathname-strip-directory (program-name))))
+ (print this "--out-log=<log file> log1 log2 ... logn")
+ (when exit-code (exit exit-code))))
+
+
+
+(let ((args (command-line-arguments)))
+ (when (null? args)
+ (usage 1))
+ (let ((log-files
+ (remove (lambda (arg)
+ (string-prefix? "--" arg))
+ args))
+ (out-file (cmd-line-arg '--out-log args)))
+ (when (file-exists? out-file)
+ (die out-file " already exists. Aborting."))
+ (unless out-file
+ (usage 1))
+
+ (with-output-to-file out-file
+ (lambda ()
+ (for-each pp (merge-logs log-files))))))
View
5 salmonella.setup
@@ -10,6 +10,7 @@
;; Compile the applications
(compile -S -O3 -d1 salmonella-cmd.scm -o salmonella)
(compile -S -O3 -d1 salmonella-log-viewer.scm -o salmonella-log-viewer)
+(compile -S -O3 -d1 salmonella-log-merger.scm -o salmonella-log-merger)
(define salmonella-version "2.0")
@@ -29,3 +30,7 @@
(install-program 'salmonella-log-viewer
'("salmonella-log-viewer")
`((version ,salmonella-version)))
+
+(install-program 'salmonella-log-merger
+ '("salmonella-log-merger")
+ `((version ,salmonella-version)))

0 comments on commit 3d58051

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