Re: Scheme profiling

Mikael Djurfeldt (mdj@nada.kth.se)
23 Jun 1998 21:55:20 +0200

"ccf::satchell"@hermes.dra.hmg.gb writes:

> For guile, you might say send signals at some suitable interval; the handler
> would note the current source line (at least when that is meaningful), and
> then execution would continue. The information obviously exists, as error
> messages are nicely labeled with it. Is this possible,

Yes.

> desirable

Yes!

> and/or easy?

It isn't hard at all in principle, but due to the total lack of
documentation for these parts of Guile, it might be a bit difficult
(if you're not accustomed to use the source as documentation, that is
;-).

Maybe you can get something out of this:

(define (sample secs)
(sigaction SIGALRM alarm-handler)
(alarm secs))

(define sinfo #f)

(define (alarm-handler sig)
(let ((s (frame-source (stack-ref (make-stack #t %deliver-signals 0) 0))))
(set! sinfo (and s (source-properties s)))))

`sample' takes a "snapshot" of the source code information on the
lower-most stack frame SECS seconds after the call to `sample' and
stores it into sinfo. Since source code information isn't always
available, sinfo may become #f.

When you're doing profiling there are (at least) two points more to
make:

1. Use a faster timer than the alarm timer. I'd suggest the virtual
timer.

2. The call to `make-stack' will be slow unless you set the `maxdepth'
debug option to a small value. (Try to make it as small as
possible. Start with a value around 10.)

(Great idea!)

/mdj