Index: common.scm ================================================================== --- common.scm +++ common.scm @@ -270,23 +270,10 @@ (else "FAIL"))) (define (common:logpro-exit-code->test-status exit-code) (status-sym->string (common:logpro-exit-code->status-sym exit-code))) -(defstruct remote - (hh-dat (common:get-homehost)) ;; homehost record ( addr . hhflag ) - (server-url (if *toppath* (server:check-if-running *toppath*))) ;; (server:check-if-running *toppath*) #f)) - (last-server-check 0) ;; last time we checked to see if the server was alive - (conndat #f) - (transport *transport-type*) - (server-timeout (server:expiration-timeout)) - (force-server #f) - (ro-mode #f) - (ro-mode-checked #f) ;; flag that indicates we have checked for ro-mode - (ulex:conn #f) ;; ulex db conn is not exactly a db connector, more like a network connector - ) - ;; launching and hosts (defstruct host (reachable #f) (last-update 0) (last-used 0) Index: common_records.scm ================================================================== --- common_records.scm +++ common_records.scm @@ -50,10 +50,27 @@ (define-syntax common:handle-exceptions (syntax-rules () ((_ exn errstmt body ...) (begin body ...)))) + +;;====================================================================== +;; records that are accessed or shared widely +;;====================================================================== + +(defstruct remote + (hh-dat (common:get-homehost)) ;; homehost record ( addr . hhflag ) + (server-url (if *toppath* (server:check-if-running *toppath*))) ;; (server:check-if-running *toppath*) #f)) + (last-server-check 0) ;; last time we checked to see if the server was alive + (conndat #f) + (transport *transport-type*) + (server-timeout (server:expiration-timeout)) + (force-server #f) + (ro-mode #f) + (ro-mode-checked #f) ;; flag that indicates we have checked for ro-mode + (ulex:conn #f) ;; ulex db conn is not exactly a db connector, more like a network connector + ) ;; (define handle-exceptions common:handle-exceptions) ;; iup callbacks are not dumping the stack, this is a work-around ;; @@ -75,10 +92,16 @@ (define-inline (with-mutex mtx accessor record . val) (mutex-lock! mtx) (let ((res (apply accessor record val))) (mutex-unlock! mtx) res)) + +;;====================================================================== +;; debug print stuff +;;====================================================================== + +(define *verbosity* 1) ;; this was cached based on results from profiling but it turned out the profiling ;; somehow went wrong - perhaps too many processes writing to it. Leaving the caching ;; in for now but can probably take it out later. ;; @@ -121,35 +144,38 @@ (not (null? (lset-intersection! eq? *verbosity* n)))) ((and (number? *verbosity*) (list? n)) (member *verbosity* n)))) -(define (debug:setup) - (let ((debugstr (or (args:get-arg "-debug") - (getenv "MT_DEBUG_MODE")))) - (set! *verbosity* (debug:calc-verbosity debugstr)) - (debug:check-verbosity *verbosity* debugstr) - ;; if we were handed a bad verbosity rule then we will override it with 1 and continue - (if (not *verbosity*)(set! *verbosity* 1)) - (if (or (args:get-arg "-debug") - (not (getenv "MT_DEBUG_MODE"))) - (setenv "MT_DEBUG_MODE" (if (list? *verbosity*) - (string-intersperse (map conc *verbosity*) ",") - (conc *verbosity*)))))) +;; (or (args:get-arg "-debug") +;; (getenv "MT_DEBUG_MODE"))) +(define (debug:setup debugstr) + (set! *verbosity* (debug:calc-verbosity debugstr)) + (debug:check-verbosity *verbosity* debugstr) + ;; if we were handed a bad verbosity rule then we will override it with 1 and continue + (if (not *verbosity*)(set! *verbosity* 1)) + (if (or debugstr + (not (get-environment-variable "MT_DEBUG_MODE"))) + (setenv "MT_DEBUG_MODE" (if (list? *verbosity*) + (string-intersperse (map conc *verbosity*) ",") + (conc *verbosity*))))) (define (debug:print n e . params) (if (debug:debug-mode n) (with-output-to-port (or e (current-error-port)) (lambda () - (if *logging* - (db:log-event (apply conc params)) - (apply print params) - ))))) + ;; (if *logging* + ;; (db:log-event (apply conc params)) + (apply print params) + )))) ;; Brandon's debug printer shortcut (indulge me :) -(define *BB-process-starttime* (current-milliseconds)) -(define (BB> . in-args) +;; Matt's note: This is good stuff - let's look at integrating it into the debug:print* routines +;; - for now I'm commenting out while trying to refactor. +;; +#;(define *BB-process-starttime* (current-milliseconds)) +#;(define (BB> . in-args) (let* ((stack (get-call-chain)) (location "??")) (for-each (lambda (frame) (let* ((this-loc (vector-ref frame 0)) @@ -165,20 +191,20 @@ (list 0 *default-log-port* (conc color-on location "@"(/ (- (current-milliseconds) *BB-process-starttime*) 1000) color-off " ") ) in-args))) (apply debug:print dp-args)))) -(define *BBpp_custom_expanders_list* (make-hash-table)) +#;(define *BBpp_custom_expanders_list* (make-hash-table)) ;; register hash tables with BBpp. -(hash-table-set! *BBpp_custom_expanders_list* HASH_TABLE: +#;(hash-table-set! *BBpp_custom_expanders_list* HASH_TABLE: (cons hash-table? hash-table->alist)) ;; test name converter -(define (BBpp_custom_converter arg) +#;(define (BBpp_custom_converter arg) (let ((res #f)) (for-each (lambda (custom-type-name) (let* ((custom-type-info (hash-table-ref *BBpp_custom_expanders_list* custom-type-name)) (custom-type-test (car custom-type-info)) @@ -186,11 +212,11 @@ (when (and (not res) (custom-type-test arg)) (set! res (custom-type-converter arg))))) (hash-table-keys *BBpp_custom_expanders_list*)) (if res (BBpp_ res) arg))) -(define (BBpp_ arg) +#;(define (BBpp_ arg) (cond ;;((SOMESTRUCT? arg) (cons SOMESTRUCT: (SOMESTRUCT->alist arg))) ;;((dboard:tabdat? arg) (cons dboard:tabdat: (dboard:tabdat->alist arg))) ((hash-table? arg) (let ((al (hash-table->alist arg))) @@ -199,15 +225,15 @@ ;;((list? arg) (cons (BBpp_ (car arg)) (BBpp_ (cdr arg)))) ((pair? arg) (cons (BBpp_ (car arg)) (BBpp_ (cdr arg)))) (else (BBpp_custom_converter arg)))) ;; Brandon's pretty printer. It expands hashes and custom types in addition to regular pp -(define (BBpp arg) +#;(define (BBpp arg) (pp (BBpp_ arg))) ;(use define-macro) -(define-syntax inspect +#;(define-syntax inspect (syntax-rules () [(_ x) ;; (with-output-to-port (current-error-port) (printf "~a is: ~a\n" 'x (with-output-to-string (lambda () (BBpp x)))) ;; ) @@ -217,15 +243,16 @@ (define (debug:print-error n e . params) ;; normal print (if (debug:debug-mode n) (with-output-to-port (if (port? e) e (current-error-port)) (lambda () - (if *logging* - (db:log-event (apply conc params)) - ;; (apply print "pid:" (current-process-id) " " params) - (apply print "ERROR: " params) - )))) + ;; (if *logging* + ;; (db:log-event (apply conc params)) + ;; (apply print "pid:" (current-process-id) " " params) + (apply print "ERROR: " params) + ))) + ;; pass important messages to stderr (if (and (eq? n 0)(not (eq? e (current-error-port)))) (with-output-to-port (current-error-port) (lambda () (apply print "ERROR: " params) @@ -233,19 +260,19 @@ (define (debug:print-info n e . params) (if (debug:debug-mode n) (with-output-to-port (if (port? e) e (current-error-port)) (lambda () - (if *logging* - (let ((res (format#format #f "INFO: (~a) ~a" n (apply conc params)))) - (db:log-event res)) + ;; (if *logging* + ;; (let ((res (format#format #f "INFO: (~a) ~a" n (apply conc params)))) + ;; (db:log-event res)) ;; (apply print "pid:" (current-process-id) " " "INFO: (" n ") " params) ;; res) - (apply print "INFO: (" n ") " params) ;; res) - ))))) + (apply print "INFO: (" n ") " params) ;; res) + )))) ;; if a value is printable (i.e. string or number) return the value ;; else return an empty string (define-inline (printable val) (if (or (number? val)(string? val)) val "")) Index: megatest.scm ================================================================== --- megatest.scm +++ megatest.scm @@ -608,11 +608,12 @@ ;;====================================================================== ;; Misc setup stuff ;;====================================================================== -(debug:setup) +(debug:setup (or (args:get-arg "-debug") + (getenv "MT_DEBUG_MODE"))) (if (args:get-arg "-logging")(set! *logging* #t)) (if (debug:debug-mode 3) ;; we are obviously debugging (set! open-run-close open-run-close-no-exception-handling)) Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -23,27 +23,22 @@ (module rmtmod * (import scheme chicken data-structures extras) -(import (prefix sqlite3 sqlite3:) posix typed-records srfi-18) -(import commonmod) +(import (prefix sqlite3 sqlite3:) posix typed-records srfi-18 srfi-1 srfi-69 format) +(import commonmod ports) (use (prefix ulex ulex:)) + +(include "common_records.scm") ;; Hack to make these functions visible to the refactored code, goal is to eliminate these over time. (define (rmt:send-receive . params) #f) (define (http-transport:close-connections . params) #f) ;; from remote defstruct in common.scm (define (remote-conndat-set! . params) #f) -(define (remote-server-url-set! . params) #f) -(define (remote-ro-mode . params) #f) -(define (remote-ro-mode-set! . params) #f) -(define (remote-ro-mode-checked-set! . params) #f) -(define (remote-ro-mode-checked . params) #f) -(define (debug:print . params) #f) -(define (debug:print-info . params) #f) -(define (debug:print-error . params) #f) + (define (db:dbfile-path . params) #f) (define (db:setup . params) #f) (define (api:execute-requests . params) #f) (define (set-functions send-receive rsus @@ -58,19 +53,11 @@ ) (set! rmt:send-receive send-receive) (set! remote-server-url-set! rsus) (set! http-transport:close-connections close-connections) (set! remote-conndat-set! rcs) - ;; print stuff - (set! debug:print dbgp) - (set! debug:print-info dbgpinfo) - (set! debug:print-error dbgperr) - ;; - (set! remote-ro-mode ro-mode) - (set! remote-ro-mode-set! ro-mode-set) - (set! remote-ro-mode-checked-set! ro-mode-checked-set) - (set! remote-ro-mode-checked ro-mode-checked) + ;; db stuff for local db access (set! db:dbfile-path dbfile-path) (set! db:setup dbsetup) (set! apt:execute-requests exec-req) )