Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23b9a57
commit 3d58051
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters