|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (test-suite test-statprof) |
|
#:use-module (test-suite lib) |
|
#:use-module (system base compile) |
|
#:use-module (srfi srfi-1) |
|
#:use-module (statprof)) |
|
|
|
|
|
|
|
|
|
(define-syntax-rule (when-implemented body ...) |
|
(catch 'system-error |
|
(lambda () |
|
body ...) |
|
(lambda args |
|
(let ((errno (system-error-errno args))) |
|
(false-if-exception (statprof-stop)) |
|
(if (or (= errno ENOSYS) (= errno EINVAL)) |
|
(throw 'unresolved) |
|
(apply throw args)))))) |
|
|
|
(pass-if-equal "return values" |
|
'(42 77) |
|
(when-implemented |
|
(call-with-values |
|
(lambda () |
|
(with-output-to-port (%make-void-port "w") |
|
(lambda () |
|
(statprof |
|
(lambda () |
|
(let loop ((i 10000)) |
|
(if (zero? i) |
|
(values 42 77) |
|
(loop (1- i))))))))) |
|
list))) |
|
|
|
(pass-if "statistical sample counts within expected range" |
|
(when-implemented |
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (make-func) |
|
|
|
|
|
(compile '(lambda (n) |
|
(do ((i 0 (+ i 1))) ((= 200 i)) (+ i i))) |
|
#:opts '(#:partial-eval? #f))) |
|
(define run-test |
|
(compile '(lambda (num-calls funcs) |
|
(let loop ((x num-calls) (funcs funcs)) |
|
(cond |
|
((positive? x) |
|
((car funcs) x) |
|
(loop (- x 1) (cdr funcs)))))))) |
|
|
|
(let ((num-calls 200000) |
|
(funcs (circular-list (make-func) (make-func) (make-func)))) |
|
|
|
|
|
(statprof-reset 0 20000 #f #f) |
|
(statprof-start) |
|
(run-test num-calls funcs) |
|
(statprof-stop) |
|
|
|
(let ((a-data (statprof-proc-call-data (car funcs))) |
|
(b-data (statprof-proc-call-data (cadr funcs))) |
|
(c-data (statprof-proc-call-data (caddr funcs)))) |
|
(if (and a-data b-data c-data) |
|
(let* ((samples (map statprof-call-data-cum-samples |
|
(list a-data b-data c-data))) |
|
(expected (/ (apply + samples) 3.0)) |
|
(diffs (map (lambda (x) (abs (- x expected))) |
|
samples)) |
|
(max-diff (apply max diffs))) |
|
|
|
(or (< max-diff (sqrt expected)) |
|
|
|
|
|
(begin |
|
(format (current-warning-port) |
|
";;; warning: max diff ~a > (sqrt ~a)\n" |
|
max-diff expected) |
|
(throw 'unresolved)))) |
|
|
|
|
|
|
|
|
|
(throw 'unresolved (pk (list a-data b-data c-data)))))))) |
|
|
|
(pass-if "accurate call counting" |
|
(when-implemented |
|
|
|
|
|
(let ((num-calls 200)) |
|
|
|
(define do-nothing |
|
(compile '(lambda (n) |
|
(simple-format #f "FOO ~A\n" (+ n n))))) |
|
|
|
|
|
(statprof-reset 0 50000 #t #f) |
|
(statprof-start) |
|
(let loop ((x num-calls)) |
|
(cond |
|
((positive? x) |
|
(do-nothing x) |
|
(loop (- x 1)) |
|
#t))) |
|
(statprof-stop) |
|
|
|
|
|
(let ((proc-data (statprof-proc-call-data do-nothing))) |
|
(and proc-data |
|
(= (statprof-call-data-calls proc-data) |
|
num-calls)))))) |
|
|