[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: frames / stacks / source? was Re: coverage/profiling
From: |
Han-Wen Nienhuys |
Subject: |
Re: frames / stacks / source? was Re: coverage/profiling |
Date: |
Wed, 10 Jan 2007 13:59:56 +0100 |
User-agent: |
Thunderbird 1.5.0.9 (X11/20061219) |
Neil Jerram escreveu:
>>> Do you think you need to do this in C? (You might do, for reasonable
>>> performance - I genuinely don't know yet.) The evaluator already has
>>> hooks (see "Evaluator trap options" in the manual) that allow you to
>>> call out to arbitrary Scheme code at the entry and exit of every
>>> frame.
>> address@hidden info]$ guile
>> guile> (trap-enable 'enter-frame-handler)
>> throw from within critical section.
>> Abortado
>> address@hidden info]$
>
> Takes effect quickly, doesn't it? :-)
>
> What you need is something more like this:
>
> (trap-set! enter-frame-handler
> (lambda (key continuation . args)
> ...))
> (trap-enable 'enter-frame)
>
> And it's important to do them in this order.
Hi,
perhaps the documentation could be extended to include a small example,
such as
"The following example demonstrates the use of traps. The program
displays each source line as it is executed, by installing a handler
that examines the origin of each continuation. The handlers are
installed and enabled with @code{trap-set!} and @code{trap-enable},
but they only become active if traps are switched on with
@code{(trap-enable 'traps)}.
(define (test-add x y)
(+
x
(/
x
y)))
(define (record-coverage key continuation . args)
(let*
((stack (make-stack continuation))
(frame (stack-ref stack 0))
(source (frame-source frame))
(line (and source (source-property source 'line))))
(if (and line (< line 10))
(format #t "line ~a ~a ~a \n" (1+ line) key args))))
(trap-set! apply-frame-handler record-coverage)
(trap-set! enter-frame-handler record-coverage)
(trap-set! exit-frame-handler record-coverage)
(trap-enable 'apply-frame 'exit-frame 'enter-frame)
(trap-enable 'traps)
(define z (test-add 1 2))
(trap-disable 'traps)
when this is put in a file and executed with --debug, the following
is shown
line 2 enter-frame (#t (+ x (/ x y)))
line 4 enter-frame (#f (/ x y))
line 4 apply-frame (#f)
line 4 exit-frame (1/2)
line 2 apply-frame (#t)
line 2 exit-frame (3/2)
"
(I'm not sure what the #f / #t mean, though)
--
Han-Wen Nienhuys - address@hidden - http://www.xs4all.nl/~hanwen
- coverage/profiling, Han-Wen Nienhuys, 2007/01/02
- frames / stacks / source? was Re: coverage/profiling, Han-Wen Nienhuys, 2007/01/08
- Re: frames / stacks / source? was Re: coverage/profiling, Ludovic Courtès, 2007/01/09
- Re: frames / stacks / source? was Re: coverage/profiling, Kevin Ryde, 2007/01/09
- Re: frames / stacks / source? was Re: coverage/profiling, Neil Jerram, 2007/01/09
- Re: frames / stacks / source? was Re: coverage/profiling, Ludovic Courtès, 2007/01/10
- Re: frames / stacks / source? was Re: coverage/profiling, Han-Wen Nienhuys, 2007/01/10
- Re: frames / stacks / source? was Re: coverage/profiling, Kevin Ryde, 2007/01/17
- Re: frames / stacks / source? was Re: coverage/profiling, Han-Wen Nienhuys, 2007/01/10
- Re: frames / stacks / source? was Re: coverage/profiling, Ludovic Courtès, 2007/01/11
- Re: frames / stacks / source? was Re: coverage/profiling, Han-Wen Nienhuys, 2007/01/11
- Re: frames / stacks / source? was Re: coverage/profiling, Ludovic Courtès, 2007/01/11
- Re: frames / stacks / source? was Re: coverage/profiling, Neil Jerram, 2007/01/13
- Re: frames / stacks / source? was Re: coverage/profiling, Kevin Ryde, 2007/01/18
- Re: frames / stacks / source? was Re: coverage/profiling, Neil Jerram, 2007/01/27