Index: tcp-transportmod.scm ================================================================== --- tcp-transportmod.scm +++ tcp-transportmod.scm @@ -1134,24 +1134,65 @@ ;;====================================================================== ;; Other Utils ;;====================================================================== -;; 1.db => (10 . 9) ;; (total . hits) +(defstruct jstats + (count 0) + (jcount (make-hash-table)) ;; 1.db => journal_count + ) + +;; timeblk => jstats (define *journal-stats* (make-hash-table)) ;; monte-carlo-esque random sampling of journal files ;; for all the files: ;; if .journal ;; update stats +1 +1 ;; update stats +1 0 ;; (define (tt:write-load-tracking dbdir) - (let* ((cs (current-seconds)) - (key (inexact->exact (quotient cs 10)))) + (let* ((cs (current-seconds)) + (key (inexact->exact (quotient cs 10))) + (old (- key 4)) ;; 4 x 10 seconds ago + (jstat (if (hash-table-exists? *journal-stats* key) + (hash-table-ref *journal-stats* key ) + (let ((new (make-jstats))) + (hash-table-set! *journal-stats* key new) + new)))) + ;; clear out records over 30s old + (for-each + (lambda (key) + (if (< key old) + (hash-table-delete! *journal-stats* key))) + (hash-table-keys *journal-stats*)) + + ;; increment our count of observations + (jstats-count-set! jstat (+ (jstats-count jstat) 1)) + + ;; now find and increment journal file counts (directory-fold + (lambda (fname res) + ;; is it a journal file? + (let ((parts (string-match "^(.*\\.db)-journal.*" fname))) + (match parts + ((_ dbfname) + (hash-table-set! (jstats-jcount jstat) dbfname + (+ (hash-table-ref/default (jstats-jcount jstat) dbfname 0) 1) + )) + ))) + '() dbdir - (lambda (res fname) - (cons fname res)) - '()))) + ))) + +;; megatest> (import tcp-transportmod) +;; megatest> (tt:write-load-tracking ".mtdb") +;; megatest> (hash-table-keys *journal-stats*) +;; (172060297) +;; megatest> (jstats->alist (hash-table-ref *journal-stats* 172060297)) +;; ((count . 1) (jcount . #)) +;; megatest> (jstats-jcount (hash-table-ref *journal-stats* 172060297)) +;; # +;; megatest> (hash-table->alist (jstats-jcount (hash-table-ref *journal-stats* 172060297))) +;; (("1.db" . 4)) )