diff options
author | Christopher Baines <mail@cbaines.net> | 2021-10-12 19:42:33 +0100 |
---|---|---|
committer | Christopher Baines <mail@cbaines.net> | 2021-10-12 19:46:55 +0100 |
commit | fda913d7a912bd810ef860c12b65166b863acb7a (patch) | |
tree | 7a554f1d03a463f7ada2d1a61e37f2b037e1cd1b | |
parent | e2422e358850f455100d8927483dbc35543fe706 (diff) | |
download | build-coordinator-fda913d7a912bd810ef860c12b65166b863acb7a.tar build-coordinator-fda913d7a912bd810ef860c12b65166b863acb7a.tar.gz |
Log procedures if they take more than 2 seconds within a transaction
To better understand what's taking a while when writing to the database.
-rw-r--r-- | guix-build-coordinator/datastore/sqlite.scm | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm index b3ffdd4..1eeac2b 100644 --- a/guix-build-coordinator/datastore/sqlite.scm +++ b/guix-build-coordinator/datastore/sqlite.scm @@ -391,13 +391,31 @@ PRAGMA optimize;"))))) 'worker-reader-thread-channel 'worker-writer-thread-channel)) (lambda (db) - (if duration-metric-name - (call-with-time-tracking - datastore - duration-metric-name - (lambda () - (run-proc-within-transaction db))) - (run-proc-within-transaction db))))) + (let ((start-time (get-internal-real-time))) + (call-with-values + (lambda () + (if duration-metric-name + (call-with-time-tracking + datastore + duration-metric-name + (lambda () + (run-proc-within-transaction db))) + (run-proc-within-transaction db))) + (lambda vals + (let ((duration-seconds + (/ (- (get-internal-real-time) start-time) + internal-time-units-per-second))) + (when (and (not readonly?) + (> duration-seconds 2)) + (display + (format + #f + "warning: ~a:\n took ~4f seconds in transaction\n" + proc + duration-seconds) + (current-error-port)))) + + (apply values vals))))))) (define-method (datastore-find-agent (datastore <sqlite-datastore>) |