diff options
author | Christopher Baines <mail@cbaines.net> | 2023-04-25 16:36:37 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2023-04-25 16:36:37 +0100 |
commit | a13b760f804ba0140285df45882621ecb8b29b16 (patch) | |
tree | 3a81392d2c6b5090dbc736bfeb84f831aaf631f7 /guix-build-coordinator/datastore/sqlite.scm | |
parent | c5be4f9ea1fe577db1e9634d38c78f4d581ce5bb (diff) | |
download | build-coordinator-a13b760f804ba0140285df45882621ecb8b29b16.tar build-coordinator-a13b760f804ba0140285df45882621ecb8b29b16.tar.gz |
Split call-with-time-tracking
So that you can observe a duration directly.
Diffstat (limited to 'guix-build-coordinator/datastore/sqlite.scm')
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm index 974f538..ec52cb4 100644 --- a/guix-build-coordinator/datastore/sqlite.scm +++ b/guix-build-coordinator/datastore/sqlite.scm @@ -453,24 +453,29 @@ PRAGMA optimize;") #t) (define (call-with-time-tracking datastore thing thunk) + (let* ((start-time (get-internal-real-time))) + (call-with-values + thunk + (lambda vals + (metric-observe-duration + datastore + thing + (/ (- (get-internal-real-time) start-time) + internal-time-units-per-second)) + (apply values vals))))) + +(define (metric-observe-duration datastore + thing + duration-seconds) (define registry (slot-ref datastore 'metrics-registry)) (define metric-name (string-append "datastore_" thing "_duration_seconds")) - (if registry - (let* ((metric - (or (metrics-registry-fetch-metric registry metric-name) - (make-histogram-metric registry - metric-name))) - (start-time (get-internal-real-time))) - (call-with-values - thunk - (lambda vals - (metric-observe metric - (/ (- (get-internal-real-time) start-time) - internal-time-units-per-second)) - (apply values vals)))) - (thunk))) + (let ((metric + (or (metrics-registry-fetch-metric registry metric-name) + (make-histogram-metric registry + metric-name)))) + (metric-observe metric duration-seconds))) (define (call-with-worker-thread/delay-logging channel proc) (call-with-worker-thread channel |