Render module graph.

This commit is contained in:
Vincent St-Amour 2013-05-30 17:28:15 -04:00
parent 693c88ff54
commit a5f47f86e5

View File

@ -3,7 +3,9 @@
(require racket/list unstable/list racket/match racket/set racket/format
racket/contract
(only-in racket/contract/private/guts contract-continuation-mark-key)
"sampler.rkt" "utils.rkt")
"sampler.rkt" "utils.rkt"
;; for grphviz rendering
redex/private/dot racket/system)
(struct contract-profile
(total-time n-samples n-contract-samples
@ -121,6 +123,9 @@
;; boundary.
;; Typed modules are in green, untyped modules are in red.
(define dot-exe (find-dot))
(define module-graph-dot-file "tmp-contract-profile-module-graph.dot")
(define (module-graph-view correlated)
(match-define (contract-profile total-time n-samples n-contract-samples
live-contract-samples all-blames)
@ -161,6 +166,9 @@
(values n typed?)))
;; graphviz output
(with-output-to-file module-graph-dot-file
#:exists 'replace
(lambda ()
(printf "digraph {\n")
(define nodes->names (for/hash ([n nodes]) (values n (gensym))))
(for ([n nodes])
@ -174,7 +182,12 @@
(hash-ref nodes->names neg)
(hash-ref nodes->names pos)
(samples-time v)))
(printf "}\n"))
(printf "}\n")))
;; render, if graphviz is installed
(when dot-exe
(system (format "~a -Tpdf -O ~a"
(path->string dot-exe)
module-graph-dot-file))))
;;---------------------------------------------------------------------------