Index: common.scm ================================================================== --- common.scm +++ common.scm @@ -50,10 +50,12 @@ (define *alt-log-file* #f) ;; used by -log (define *db-sync-mutex* (make-mutex)) ;; DATABASE (define *dbstruct-db* #f) +(define *db-stats* (make-hash-table)) ;; hash of vectors < count duration-total > +(define *db-stats-mutex* (make-mutex)) ;; SERVER (define *my-client-signature* #f) (define *transport-type* 'http) (define *megatest-db* #f) Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -346,10 +346,19 @@ (debug:print 0 "WARNING: -itempatt has been deprecated, please use -testpatt testpatt/itempatt method, new testpatt is "newval) (hash-table-set! args:arg-hash "-testpatt" newval) (hash-table-delete! args:arg-hash "-itempatt"))) (on-exit (lambda () + (debug:print 18 "DB Stats") + (debug:print 18 "Cmd\tCount\tTot time\tAvg") + (for-each (lambda (cmd) + (let ((cmd-dat (hash-table-ref *db-stats* cmd))) + (debug:print 18 cmd "\t" (vector-ref cmd-dat 0) "\t" (vector-ref cmd-dat 1) "\t" (/ (vector-ref cmd-dat 1) (vector-ref cmd-dat 0))))) + (sort (hash-table-keys *db-stats*) + (lambda (a b) + (> (vector-ref (hash-table-ref *db-stats* a) 0) + (vector-ref (hash-table-ref *db-stats* b) 0))))) (if *dbstruct-db* (db:close-all *dbstruct-db*)) (if *megatest-db* (sqlite3:finalize! *megatest-db*)))) ;;====================================================================== ;; Misc general calls Index: rmt.scm ================================================================== --- rmt.scm +++ rmt.scm @@ -82,22 +82,35 @@ (begin (debug:print-info 4 "no server and read-only query, bypassing normal channel") (if (rmt:write-frequency-over-limit? cmd run-id)(server:kind-run run-id)) (rmt:open-qry-close-locally cmd run-id params))))) +(define (rmt:update-db-stats cmd duration) + (mutex-lock! *db-stats-mutex*) + (let ((stat-vec (hash-table-ref/default *db-stats* cmd #f))) + (if (not stat-vec) + (let ((newvec (vector 0 0))) + (hash-table-set! *db-stats* cmd newvec) + (set! stat-vec newvec))) + (vector-set! stat-vec 0 (+ (vector-ref stat-vec 0) 1)) + (vector-set! stat-vec 1 (+ (vector-ref stat-vec 1) duration))) + (mutex-unlock! *db-stats-mutex*)) + (define (rmt:open-qry-close-locally cmd run-id params) (let* ((dbdir (conc (configf:lookup *configdat* "setup" "linktree") "/.db")) (dbstruct-local (if *dbstruct-db* *dbstruct-db* (let ((db (make-dbr:dbstruct path: dbdir local: #t))) (set! *dbstruct-db* db) db))) - (db-file-path (db:dbfile-path 0)) - ;; (read-only (not (file-read-access? db-file-path))) - (res (api:execute-requests dbstruct-local (symbol->string cmd) params))) - ;; (db:close-all dbstruct-local) - res)) + (db-file-path (db:dbfile-path 0))) + ;; (read-only (not (file-read-access? db-file-path))) + (let* ((start (current-milliseconds)) + (res (api:execute-requests dbstruct-local (symbol->string cmd) params)) + (duration (- (current-milliseconds) start))) + (rmt:update-db-stats cmd duration) + res))) (define (rmt:send-receive-no-auto-client-setup connection-info cmd run-id params) (let* ((run-id (if run-id run-id 0)) (jparams (db:obj->string params)) ;; (rmt:dat->json-str params)) (res (http-transport:client-api-send-receive run-id connection-info cmd jparams))) Index: runs.scm ================================================================== --- runs.scm +++ runs.scm @@ -1070,11 +1070,11 @@ ;; (debug:print 0 "Got here eh! num-running=" num-running " (> num-running 0) " (> num-running 0)) (if (> (current-seconds)(+ last-time-incomplete 900)) (begin (debug:print-info 0 "Marking stuck tests as INCOMPLETE while waiting for run " run-id ". Running as pid " (current-process-id) " on " (get-host-name)) (set! last-time-incomplete (current-seconds)) - (cdb:remote-run db:find-and-mark-incomplete #f))) + (rmt:find-and-mark-incomplete run-id))) (if (not (eq? num-running prev-num-running)) (debug:print-info 0 "run-wait specified, waiting on " num-running " tests in RUNNING, REMOTEHOSTSTART or LAUNCHED state at " (time->string (seconds->local-time (current-seconds))))) (thread-sleep! 15) ;; (wait-loop (rmt:get-count-tests-running-for-run-id run-id) num-running)))) (wait-loop (rmt:get-count-tests-running-for-run-id run-id) num-running))))