* added `periodic-renderer'
* set svn:ignore svn: r14345 original commit: 14f71a8531c0da1946ed0a5e2544fc0c765b1791
This commit is contained in:
parent
d538141610
commit
322f6a871e
|
@ -10,12 +10,22 @@
|
|||
#:delay [delay 0.05]
|
||||
#:repeat [rpt 1]
|
||||
#: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 sampler (create-sampler (if threads?
|
||||
(list cust (current-thread))
|
||||
(current-thread))
|
||||
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)))
|
||||
(with-handlers ([void (lambda (e)
|
||||
(fprintf (current-error-port)
|
||||
|
@ -26,6 +36,7 @@
|
|||
(if threads?
|
||||
(parameterize ([current-custodian cust]) (run))
|
||||
(run)))
|
||||
(when periodic-thread (kill-thread periodic-thread))
|
||||
(sampler 'stop)
|
||||
(renderer (analyze-samples (sampler 'get-snapshots))))
|
||||
|
||||
|
@ -61,13 +72,16 @@
|
|||
(define ch (make-channel))
|
||||
(define (bg-fib) (channel-put ch (fib1 n)))
|
||||
(thread bg-fib)
|
||||
(list (fib22 n) (channel-get ch)))
|
||||
(list (fibs n) (channel-get ch)))
|
||||
|
||||
(require "render-graphviz.ss")
|
||||
|
||||
(profile (fibs 35)
|
||||
(profile ;(fibs 40)
|
||||
;(dynamic-require '(lib "scribblings/reference/reference.scrbl") #f)
|
||||
;(foo 35)
|
||||
(foo 40)
|
||||
;#:render render
|
||||
#:threads #t)
|
||||
#:threads #t
|
||||
#:periodic-renderer
|
||||
(list 0.5 text:render)
|
||||
)
|
||||
|#
|
||||
|
|
|
@ -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
|
||||
intended as a convenient tool for profiling code.
|
||||
|
||||
@defproc[(profile-thunk [thunk (-> any/c)]
|
||||
[#:delay delay nonnegative-number? 0.05]
|
||||
[#:repeat iterations exact-nonnegative-integer? 1]
|
||||
[#:threads threads? any/c #f]
|
||||
[#:render renderer text:render])
|
||||
@defproc[(profile-thunk
|
||||
[thunk (-> any/c)]
|
||||
[#:delay delay nonnegative-number? 0.05]
|
||||
[#:repeat iterations exact-nonnegative-integer? 1]
|
||||
[#: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?]{
|
||||
|
||||
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
|
||||
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 ...)]{
|
||||
|
|
Loading…
Reference in New Issue
Block a user