diff options
author | Christopher Baines <mail@cbaines.net> | 2020-05-09 19:03:17 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2020-05-09 19:03:43 +0100 |
commit | ef8ee1c38b294284f5b5ec4543e7a689b92df146 (patch) | |
tree | f73279d19b67fb47b2cd75a105df30c22a3ac9d9 | |
parent | 77b8aa13720de63ceae6d375c96fa85f0d90af96 (diff) | |
download | build-coordinator-ef8ee1c38b294284f5b5ec4543e7a689b92df146.tar build-coordinator-ef8ee1c38b294284f5b5ec4543e7a689b92df146.tar.gz |
Add some time tracking utilities
These are copied from the Guix Data Service.
-rw-r--r-- | guix-build-coordinator/utils.scm | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/guix-build-coordinator/utils.scm b/guix-build-coordinator/utils.scm index de64416..61db3b4 100644 --- a/guix-build-coordinator/utils.scm +++ b/guix-build-coordinator/utils.scm @@ -1,5 +1,6 @@ (define-module (guix-build-coordinator utils) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) #:use-module (srfi srfi-60) #:use-module (ice-9 ftw) @@ -48,7 +49,9 @@ retry-on-error s3-list-objects - s3-cp)) + s3-cp + + with-time-logging)) (define %worker-thread-args @@ -476,3 +479,19 @@ References: ~a~%" exit-code command)))) #t))) + +(define (call-with-time-logging name thunk) + (let* ((start (current-time time-utc)) + (result (thunk)) + (end (current-time time-utc)) + (elapsed (time-difference end start))) + (format (current-output-port) + "~a took ~a seconds~%" + name + (+ (time-second elapsed) + (/ (time-nanosecond elapsed) 1e9))) + result)) + +(define-syntax-rule (with-time-logging name exp ...) + "Log under NAME the time taken to evaluate EXP." + (call-with-time-logging name (lambda () exp ...))) |