30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
(include "run_records.scm")
;; timestamp type (val1 val2 ...)
;; type: meta-info, step
(define *incoming-data* '())
(define *incoming-last-time* (current-seconds))
(define *incoming-mutex* (make-mutex))
(define (open-db) ;; (conc *toppath* "/megatest.db") (car *configinfo*)))
(let* ((dbpath (conc *toppath* "/megatest.db")) ;; fname)
(dbexists (file-exists? dbpath))
(db (sqlite3:open-database dbpath)) ;; (never-give-up-open-db dbpath))
(handler (make-busy-timeout 36000)))
(sqlite3:set-busy-handler! db handler)
|
>
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
(include "run_records.scm")
;; timestamp type (val1 val2 ...)
;; type: meta-info, step
(define *incoming-data* '())
(define *incoming-last-time* (current-seconds))
(define *incoming-mutex* (make-mutex))
(define *cache-on* #f)
(define (open-db) ;; (conc *toppath* "/megatest.db") (car *configinfo*)))
(let* ((dbpath (conc *toppath* "/megatest.db")) ;; fname)
(dbexists (file-exists? dbpath))
(db (sqlite3:open-database dbpath)) ;; (never-give-up-open-db dbpath))
(handler (make-busy-timeout 36000)))
(sqlite3:set-busy-handler! db handler)
|
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
|
(list cpuload
diskfree
minutes
run-id
test-name
item-path)) ;; run-id test-name item-path minutes cpuload diskfree tmpfree)
*incoming-data*))
(mutex-unlock! *incoming-mutex*))
(define (db:write-cached-data db)
(let ((meta-stmt (sqlite3:prepare db "UPDATE tests SET cpuload=?,diskfree=?,run_duration=?,state='RUNNING' WHERE run_id=? AND testname=? AND item_path=? AND state NOT IN ('COMPLETED','KILLREQ','KILLED');"))
(step-stmt (sqlite3:prepare db "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);")) ;; strftime('%s','now')#f)
(data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1))))))
(debug:print 0 "Writing cached data " data)
(mutex-lock! *incoming-mutex*)
(for-each (lambda (entry)
(case (vector-ref entry 0)
((meta-info)
(apply sqlite3:execute meta-stmt (vector-ref entry 2)))
((step-status)
(apply sqlite3:execute step-stmt (vector-ref entry 2)))
|
|
>
>
|
|
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
|
(list cpuload
diskfree
minutes
run-id
test-name
item-path)) ;; run-id test-name item-path minutes cpuload diskfree tmpfree)
*incoming-data*))
(mutex-unlock! *incoming-mutex*)
(if (not *cache-on*)(db:write-cached-data db)))
(define (db:write-cached-data db)
(let ((meta-stmt (sqlite3:prepare db "UPDATE tests SET cpuload=?,diskfree=?,run_duration=?,state='RUNNING' WHERE run_id=? AND testname=? AND item_path=? AND state NOT IN ('COMPLETED','KILLREQ','KILLED');"))
(step-stmt (sqlite3:prepare db "INSERT OR REPLACE into test_steps (test_id,stepname,state,status,event_time,comment,logfile) VALUES(?,?,?,?,?,?,?);")) ;; strftime('%s','now')#f)
(data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1))))))
;(if (> (length data) 0)
(debug:print 0 "Writing cached data " data);)
(mutex-lock! *incoming-mutex*)
(for-each (lambda (entry)
(case (vector-ref entry 0)
((meta-info)
(apply sqlite3:execute meta-stmt (vector-ref entry 2)))
((step-status)
(apply sqlite3:execute step-stmt (vector-ref entry 2)))
|
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
|
(or (not state)(not status)))
(debug:print 0 "WARNING: Invalid " (if status "status" "state")
" value \"" (if status state-in status-in) "\", update your validvalues section in megatest.config"))
(if testdat
(let ((test-id (test:get-id testdat)))
(mutex-lock! *incoming-mutex*)
(set! *incoming-data* (cons (vector 'step-status
(current-seconds)
;; FIXME - this should not update the logfile unless it is specified.
(list test-id teststep-name state-in status-in (current-seconds) (if comment comment "") (if logfile logfile "")))))
(mutex-unlock! *incoming-mutex*)
#t)
(debug:print 0 "ERROR: Can't update " test-name " for run " run-id " -> no such test in db"))))
;;======================================================================
;; Extract ods file from the db
;;======================================================================
|
|
|
|
>
|
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
|
(or (not state)(not status)))
(debug:print 0 "WARNING: Invalid " (if status "status" "state")
" value \"" (if status state-in status-in) "\", update your validvalues section in megatest.config"))
(if testdat
(let ((test-id (test:get-id testdat)))
(mutex-lock! *incoming-mutex*)
(set! *incoming-data* (cons (vector 'step-status
(current-seconds)
;; FIXME - this should not update the logfile unless it is specified.
(list test-id teststep-name state-in status-in (current-seconds) (if comment comment "") (if logfile logfile "")))
*incoming-data*))
(mutex-unlock! *incoming-mutex*)
#t)
(debug:print 0 "ERROR: Can't update " test-name " for run " run-id " -> no such test in db"))))
;;======================================================================
;; Extract ods file from the db
;;======================================================================
|