ADDED docs/csirc Index: docs/csirc ================================================================== --- /dev/null +++ docs/csirc @@ -0,0 +1,33 @@ +(cond-expand + (chicken-4 + ;; chicken 4 stuff here + (use readline) + (current-input-port (make-readline-port)) + (install-history-file #f "/.csi.history") + ) + (chicken-5 + (import (chicken load)) + (import (chicken format)) + (import (chicken process-context)) + (import (chicken process signal)) + (load-verbose #f) + (let () + (unless (get-environment-variable "INSIDE_EMACS") + (import breadline) + (import breadline-scheme-completion) + (history-file (format "~a/.csi_history" (get-environment-variable "HOME"))) + (stifle-history! 10000) + (completer-word-break-characters-set! "\"\'`;|(") + (completer-set! scheme-completer) + (basic-quote-characters-set! "\"|") + (variable-bind! "blink-matching-paren" "on") + (paren-blink-timeout-set! 200000) + (let ((handler (signal-handler signal/int))) + (set-signal-handler! signal/int + (lambda (s) + (cleanup-after-signal!) + (reset-after-signal!) + (handler s)))) + (on-exit reset-terminal!) + (current-input-port (make-readline-port)))) + )) Index: tcp-transportmod.scm ================================================================== --- tcp-transportmod.scm +++ tcp-transportmod.scm @@ -41,10 +41,11 @@ ports posix files data-structures + directory-utils tcp )) (chicken-5 (import chicken.base chicken.condition @@ -1128,7 +1129,70 @@ (define (get-all-ips) (map address-info-host (filter (lambda (x) (equal? (address-info-type x) "tcp")) (address-infos (get-host-name))))) + +;;====================================================================== +;; Other Utils +;;====================================================================== + +(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))) + (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 + ))) + +;; 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)) )