Megatest

Diff
Login

Differences From Artifact [bc19f724a5]:

To Artifact [39c3e50bc5]:


29
30
31
32
33
34
35

36
37
38
39
40
41
42
	
(import scheme
	chicken
	data-structures
	extras
	files


	(prefix sqlite3 sqlite3:)
	matchable
	posix
	typed-records
	srfi-1
	srfi-18
	srfi-69







>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	
(import scheme
	chicken
	data-structures
	extras
	files

	format
	(prefix sqlite3 sqlite3:)
	matchable
	posix
	typed-records
	srfi-1
	srfi-18
	srfi-69
825
826
827
828
829
830
831












































832
833
834
835
836
837
838
		   (sdb    (dbmod:safely-open-db src-db init-proc #t))
		   (ddb    (dbmod:safely-open-db dest-db init-proc d-wr))
		   (res    (dbmod:sync-gasket tables last-update sdb ddb dest-db 'todisk keys)))
	      (sqlite3:finalize! sdb)
	      (sqlite3:finalize! ddb)
	      res)))
      #f))












































)


;; ATTIC

					 #;(let* ((syncer-logfile    (conc areapath"/logs/"dbfname"-syncer.log"))
					      (sync-cmd          (if (eq? syncdir 'todisk)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
		   (sdb    (dbmod:safely-open-db src-db init-proc #t))
		   (ddb    (dbmod:safely-open-db dest-db init-proc d-wr))
		   (res    (dbmod:sync-gasket tables last-update sdb ddb dest-db 'todisk keys)))
	      (sqlite3:finalize! sdb)
	      (sqlite3:finalize! ddb)
	      res)))
      #f))

;; ======================================================================
;; dbstats
;;======================================================================

;; (define *dbstruct-dbs*         #f) ;; used to cache the dbstruct in db:setup. Goal is to remove this.
;; db stats
(define *db-stats*            (make-hash-table)) ;; hash of vectors < count duration-total >
(define *db-stats-mutex*      (make-mutex))

(define (rmt:print-db-stats)
  (let ((fmtstr "~40a~7-d~9-d~20,2-f")) ;; "~20,2-f"
    (debug:print 0 *default-log-port* "DB Stats\n========")
    (debug:print 0 *default-log-port* (format #f "~40a~8a~10a~10a" "Cmd" "Count" "TotTime" "Avg"))
    (for-each (lambda (cmd)
		(let* ((dat     (hash-table-ref *db-stats* cmd))
		       (count   (dbstat-cnt dat))
		       (tottime (dbstat-tottime dat)))
		  (debug:print 0 *default-log-port*
			       (format #f fmtstr cmd count tottime
				       (/ tottime count)))))
	      (sort (hash-table-keys *db-stats*)
		    (lambda (a b)
		      (> (dbstat-tottime (hash-table-ref *db-stats* a))
			 (dbstat-tottime (hash-table-ref *db-stats* b))))))))

(defstruct dbstat
  (cnt 0)
  (tottime 0))

(define (db:add-stats cmd run-id params delta)
  (let* ((modified-cmd (if (eq? cmd 'general-call)
			   (string->symbol (conc "general-call-" (car params)))
			   cmd))
	 (rec          (hash-table-ref/default *db-stats* modified-cmd #f)))
    (if (not rec)
	(let ((new-rec  (make-dbstat)))
	  (hash-table-set! *db-stats* modified-cmd new-rec)
	  (set! rec new-rec)))
    (dbstat-cnt-set! rec (+ (dbstat-cnt rec) 1))
    (dbstat-tottime-set! rec (+ (dbstat-tottime rec) delta))))
    


)


;; ATTIC

					 #;(let* ((syncer-logfile    (conc areapath"/logs/"dbfname"-syncer.log"))
					      (sync-cmd          (if (eq? syncdir 'todisk)