Fix bug when profiling with no samples.
This commit is contained in:
parent
4a13b8179e
commit
e7ec0b5d05
|
@ -119,22 +119,19 @@
|
||||||
s)))
|
s)))
|
||||||
(boundary contracted-function boundary-edges b time-spent)))
|
(boundary contracted-function boundary-edges b time-spent)))
|
||||||
|
|
||||||
(with-output-to-file boundary-graph-dot-file
|
(with-output-to-report-file boundary-graph-dot-file
|
||||||
#:exists 'replace
|
(render all-boundaries contracts->keys))
|
||||||
(lambda () (render all-boundaries contracts->keys)))
|
|
||||||
(render-dot boundary-graph-dot-file)
|
(render-dot boundary-graph-dot-file)
|
||||||
;; print contract key
|
;; print contract key
|
||||||
;; TODO find a way to add to pdf
|
;; TODO find a way to add to pdf
|
||||||
;; TODO also to add to pdf: show proportion of time spent in contracts
|
;; TODO also to add to pdf: show proportion of time spent in contracts
|
||||||
;; otherwise we have no idea if we're looking at a case where contracts are
|
;; otherwise we have no idea if we're looking at a case where contracts are
|
||||||
;; bottlenecks or not
|
;; bottlenecks or not
|
||||||
(with-output-to-file contract-key-file
|
(with-output-to-report-file contract-key-file
|
||||||
#:exists 'replace
|
|
||||||
(lambda ()
|
|
||||||
(for ([contract+key (in-list contracts->keys)])
|
(for ([contract+key (in-list contracts->keys)])
|
||||||
(printf "[~a] = ~a\n"
|
(printf "[~a] = ~a\n"
|
||||||
(cdr contract+key)
|
(cdr contract+key)
|
||||||
(car contract+key))))))
|
(car contract+key)))))
|
||||||
|
|
||||||
|
|
||||||
;; given a profile node, return all the boundaries centered there
|
;; given a profile node, return all the boundaries centered there
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
;; Graphviz support
|
;; Graphviz support
|
||||||
;; inspired by redex/private/dot.rkt (can't use directly because it uses GUI)
|
;; inspired by redex/private/dot.rkt (can't use directly because it uses GUI)
|
||||||
|
|
||||||
(require racket/system)
|
(require racket/system "utils.rkt")
|
||||||
|
|
||||||
(provide render-dot)
|
(provide render-dot)
|
||||||
|
|
||||||
|
@ -25,5 +25,5 @@
|
||||||
dot-paths)))
|
dot-paths)))
|
||||||
|
|
||||||
(define (render-dot input-file)
|
(define (render-dot input-file)
|
||||||
(when dot
|
(when (and dot (not (dry-run?)))
|
||||||
(system (format "~a -Tpdf -O ~a" (path->string dot) input-file))))
|
(system (format "~a -Tpdf -O ~a" (path->string dot) input-file))))
|
||||||
|
|
|
@ -33,9 +33,8 @@
|
||||||
|
|
||||||
(define (analyze-contract-samples contract-samples samples*)
|
(define (analyze-contract-samples contract-samples samples*)
|
||||||
(define correlated (correlate-contract-samples contract-samples samples*))
|
(define correlated (correlate-contract-samples contract-samples samples*))
|
||||||
(with-output-to-file cost-breakdown-file
|
(with-output-to-report-file cost-breakdown-file
|
||||||
#:exists 'replace
|
(print-breakdown correlated))
|
||||||
(lambda () (print-breakdown correlated)))
|
|
||||||
(module-graph-view correlated)
|
(module-graph-view correlated)
|
||||||
(boundary-view correlated))
|
(boundary-view correlated))
|
||||||
|
|
||||||
|
@ -53,7 +52,7 @@
|
||||||
live-contract-samples all-blames regular-profile)
|
live-contract-samples all-blames regular-profile)
|
||||||
correlated)
|
correlated)
|
||||||
|
|
||||||
(define contract-ratio (/ n-contract-samples n-samples 1.0))
|
(define contract-ratio (/ n-contract-samples (max n-samples 1) 1.0))
|
||||||
(printf "Running time is ~a% contracts\n"
|
(printf "Running time is ~a% contracts\n"
|
||||||
(~r (* 100 contract-ratio) #:precision 2))
|
(~r (* 100 contract-ratio) #:precision 2))
|
||||||
(printf "~a/~a samples\n" n-contract-samples n-samples)
|
(printf "~a/~a samples\n" n-contract-samples n-samples)
|
||||||
|
@ -171,9 +170,8 @@
|
||||||
(values n typed?)))
|
(values n typed?)))
|
||||||
|
|
||||||
;; graphviz output
|
;; graphviz output
|
||||||
(with-output-to-file module-graph-dot-file
|
(with-output-to-report-file
|
||||||
#:exists 'replace
|
module-graph-dot-file
|
||||||
(lambda ()
|
|
||||||
(printf "digraph {\n")
|
(printf "digraph {\n")
|
||||||
(define nodes->names (for/hash ([n nodes]) (values n (gensym))))
|
(define nodes->names (for/hash ([n nodes]) (values n (gensym))))
|
||||||
(for ([n nodes])
|
(for ([n nodes])
|
||||||
|
@ -187,7 +185,7 @@
|
||||||
(hash-ref nodes->names neg)
|
(hash-ref nodes->names neg)
|
||||||
(hash-ref nodes->names pos)
|
(hash-ref nodes->names pos)
|
||||||
(samples-time v)))
|
(samples-time v)))
|
||||||
(printf "}\n")))
|
(printf "}\n"))
|
||||||
;; render, if graphviz is installed
|
;; render, if graphviz is installed
|
||||||
(render-dot module-graph-dot-file))
|
(render-dot module-graph-dot-file))
|
||||||
|
|
||||||
|
|
20
pkgs/contract-profile/tests.rkt
Normal file
20
pkgs/contract-profile/tests.rkt
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(require contract-profile (only-in contract-profile/utils dry-run?))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(require rackunit)
|
||||||
|
|
||||||
|
(dry-run? #t) ; don't output to files
|
||||||
|
|
||||||
|
;; reported by Greg Hendershott
|
||||||
|
(check-true (contract-profile #t))
|
||||||
|
|
||||||
|
(require math)
|
||||||
|
(let ()
|
||||||
|
(define dim 200)
|
||||||
|
(define big1 (build-matrix dim dim (lambda (i j) (random))))
|
||||||
|
(define big2 (build-matrix dim dim (lambda (i j) (random))))
|
||||||
|
(define (main) (matrix* big1 big2))
|
||||||
|
(check-true (matrix? (contract-profile (main)))))
|
||||||
|
)
|
|
@ -19,3 +19,13 @@
|
||||||
(cadr s)))
|
(cadr s)))
|
||||||
|
|
||||||
(define output-file-prefix "tmp-contract-profile-")
|
(define output-file-prefix "tmp-contract-profile-")
|
||||||
|
|
||||||
|
|
||||||
|
;; for testing. don't generate output files
|
||||||
|
(define dry-run? (make-parameter #f))
|
||||||
|
|
||||||
|
(define-syntax-rule (with-output-to-report-file file body ...)
|
||||||
|
(unless (dry-run?)
|
||||||
|
(with-output-to-file file
|
||||||
|
#:exists 'replace
|
||||||
|
(lambda () body ...))))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user