Clean up some time logging code

This commit is contained in:
Christopher Baines 2020-02-24 22:03:09 +00:00
parent 2f41fe79be
commit 30dd62f000
2 changed files with 39 additions and 59 deletions

View file

@ -19,18 +19,10 @@
#:use-module (ice-9 match)
#:use-module (squee)
#:use-module (guix-data-service database)
#:use-module (guix-data-service utils)
#:export (update-package-derivations-table
rebuild-package-derivations-table))
(define (log-time action f)
(simple-format #t "debug: Starting ~A\n" action)
(let* ((start-time (current-time))
(result (f))
(time-taken (- (current-time) start-time)))
(simple-format #t "debug: Finished ~A, took ~A seconds\n"
action time-taken)
result))
(define (delete-guix-revision-package-derivation-entries conn
git-repository-id
guix-revision-id
@ -128,21 +120,21 @@ LOCK TABLE ONLY package_derivations_by_guix_revision_range
(for-each
(match-lambda
((branch-name)
(log-time
(simple-format #f "deleting package derivation entries for ~A" branch-name)
(lambda ()
(delete-guix-revision-package-derivation-entries conn
git-repository-id
guix-revision-id
branch-name)))
(log-time
(simple-format #f "inserting package derivation entries for ~A" branch-name)
(lambda ()
(insert-guix-revision-package-derivation-entries
conn
git-repository-id
branch-name
#:guix-revision-id guix-revision-id)))))
(with-time-logging
(simple-format #f "deleting package derivation entries for ~A"
branch-name)
(delete-guix-revision-package-derivation-entries conn
git-repository-id
guix-revision-id
branch-name))
(with-time-logging
(simple-format #f "inserting package derivation entries for ~A"
branch-name)
(insert-guix-revision-package-derivation-entries
conn
git-repository-id
branch-name
#:guix-revision-id guix-revision-id))))
(exec-query
conn
"SELECT name FROM git_branches WHERE commit = $1 AND git_repository_id = $2"
@ -162,10 +154,9 @@ LOCK TABLE ONLY package_derivations_by_guix_revision_range
LOCK TABLE ONLY package_derivations_by_guix_revision_range
IN SHARE ROW EXCLUSIVE MODE")
(log-time
(simple-format #f "deleting all package derivation entries")
(lambda ()
(exec-query conn "DELETE FROM package_derivations_by_guix_revision_range")))
(with-time-logging
(simple-format #f "deleting all package derivation entries")
(exec-query conn "DELETE FROM package_derivations_by_guix_revision_range"))
(let ((git-branches-and-repository-ids
(exec-query
@ -174,11 +165,11 @@ LOCK TABLE ONLY package_derivations_by_guix_revision_range
(for-each
(match-lambda
((branch-name git-repository-id)
(log-time
(simple-format #f "inserting package derivation entries for ~A" branch-name)
(lambda ()
(insert-guix-revision-package-derivation-entries
conn
git-repository-id
branch-name)))))
(with-time-logging
(simple-format #f "inserting package derivation entries for ~A"
branch-name)
(insert-guix-revision-package-derivation-entries
conn
git-repository-id
branch-name))))
git-branches-and-repository-ids)))))

View file

@ -22,6 +22,7 @@
#:use-module (ice-9 receive)
#:use-module (squee)
#:use-module (guix-data-service database)
#:use-module (guix-data-service utils)
#:export (NULL
quote-string
value->quoted-string-or-null
@ -248,15 +249,6 @@
(error (simple-format #f "normalise-values: error: ~A\n" unknown))))
data))
(define (log-time action f)
(simple-format #t "debug: Starting ~A\n" action)
(let* ((start-time (current-time))
(result (f))
(time-taken (- (current-time) start-time)))
(simple-format #t "debug: Finished ~A, took ~A seconds\n"
action time-taken)
result))
(let* ((existing-entries
(if use-temporary-table?
(let ((temp-table-name
@ -281,23 +273,20 @@
"ANALYZE " temp-table-name))
;; Populate the temporary table
(log-time
(string-append "populating " temp-table-name)
(lambda ()
(exec-query conn
(insert-sql data
#:table-name temp-table-name))))
(with-time-logging (string-append "populating " temp-table-name)
(exec-query conn
(insert-sql data
#:table-name temp-table-name)))
;; Use the temporary table to find the existing values
(let ((result
(log-time
(string-append "querying the " temp-table-name)
(lambda ()
(exec-query->vhash
conn
(temp-table-select-query temp-table-name)
cdr
(lambda (result)
(string->number (first result))))))))
(with-time-logging
(string-append "querying the " temp-table-name)
(exec-query->vhash
conn
(temp-table-select-query temp-table-name)
cdr
(lambda (result)
(string->number (first result)))))))
(exec-query conn (string-append "DROP TABLE " temp-table-name))
result))