* added `periodic-renderer'

* set svn:ignore

svn: r14345

original commit: 14f71a8531c0da1946ed0a5e2544fc0c765b1791
This commit is contained in:
Eli Barzilay 2009-03-30 05:59:20 +00:00
parent d538141610
commit 322f6a871e
2 changed files with 34 additions and 10 deletions

View File

@ -10,12 +10,22 @@
#:delay [delay 0.05] #:delay [delay 0.05]
#:repeat [rpt 1] #:repeat [rpt 1]
#:threads [threads? #f] #:threads [threads? #f]
#:render [renderer text:render]) #:render [renderer text:render]
#:periodic-renderer [periodic-renderer #f])
(define cust (and threads? (make-custodian (current-custodian)))) (define cust (and threads? (make-custodian (current-custodian))))
(define sampler (create-sampler (if threads? (define sampler (create-sampler (if threads?
(list cust (current-thread)) (list cust (current-thread))
(current-thread)) (current-thread))
delay)) delay))
(define periodic-thread
(and periodic-renderer
(let ([delay (car periodic-renderer)]
[renderer (cadr periodic-renderer)])
(thread (lambda ()
(let loop ()
(sleep delay)
(renderer (analyze-samples (sampler 'get-snapshots)))
(loop)))))))
(define (run) (for ([i (in-range rpt)]) (thunk))) (define (run) (for ([i (in-range rpt)]) (thunk)))
(with-handlers ([void (lambda (e) (with-handlers ([void (lambda (e)
(fprintf (current-error-port) (fprintf (current-error-port)
@ -26,6 +36,7 @@
(if threads? (if threads?
(parameterize ([current-custodian cust]) (run)) (parameterize ([current-custodian cust]) (run))
(run))) (run)))
(when periodic-thread (kill-thread periodic-thread))
(sampler 'stop) (sampler 'stop)
(renderer (analyze-samples (sampler 'get-snapshots)))) (renderer (analyze-samples (sampler 'get-snapshots))))
@ -61,13 +72,16 @@
(define ch (make-channel)) (define ch (make-channel))
(define (bg-fib) (channel-put ch (fib1 n))) (define (bg-fib) (channel-put ch (fib1 n)))
(thread bg-fib) (thread bg-fib)
(list (fib22 n) (channel-get ch))) (list (fibs n) (channel-get ch)))
(require "render-graphviz.ss") (require "render-graphviz.ss")
(profile (fibs 35) (profile ;(fibs 40)
;(dynamic-require '(lib "scribblings/reference/reference.scrbl") #f) ;(dynamic-require '(lib "scribblings/reference/reference.scrbl") #f)
;(foo 35) (foo 40)
;#:render render ;#:render render
#:threads #t) #:threads #t
#:periodic-renderer
(list 0.5 text:render)
)
|# |#

View File

@ -14,11 +14,15 @@ high-level entry points for timing expressions. This hides the
details that are available through other parts of the library, and is details that are available through other parts of the library, and is
intended as a convenient tool for profiling code. intended as a convenient tool for profiling code.
@defproc[(profile-thunk [thunk (-> any/c)] @defproc[(profile-thunk
[#:delay delay nonnegative-number? 0.05] [thunk (-> any/c)]
[#:repeat iterations exact-nonnegative-integer? 1] [#:delay delay nonnegative-number? 0.05]
[#:threads threads? any/c #f] [#:repeat iterations exact-nonnegative-integer? 1]
[#:render renderer text:render]) [#:threads threads? any/c #f]
[#:render renderer (profile? . -> . any/c) text:render]
[#:periodic-renderer periodic-renderer
(or/c #f (list/c nonnegative-number? (profile? . -> . any/c)))
#f])
void?]{ void?]{
Executes the given thunk while collecting profiling data, and render Executes the given thunk while collecting profiling data, and render
@ -58,6 +62,12 @@ this data when done. Keyword arguments can customize the profiling:
analyzed result, and render it yourself, or use one of the existing analyzed result, and render it yourself, or use one of the existing
renderers (see @secref["renderers"]).} renderers (see @secref["renderers"]).}
@item{The @scheme[periodic-renderer] argument can be set to a list
holding a delay time and a renderer. In this case, the given
renderer will be called periodically. This is useful for cases
where you want a dynamically updated display of the results. This
delay should be larger than the sampler delay.}
]} ]}
@defform[(profile expr keyword-arguments ...)]{ @defform[(profile expr keyword-arguments ...)]{