This is the mail archive of the mailing list for the Guile project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Scheme profiler?

Keisuke Nishida <> writes:

> >   (trap-enable 'apply-frame)
> > 
> > The same handler is called also if you do (debug-enable 'trace).
> > Look at the implementation of `trace' in (ice-9 debug) to see how to
> > use the handler.
> Yes, I noticed it and tried to reimplement a profiler by using it,
> but I realized that it might be hard.  Since apply-frame-handler can
> be called several times for each procedure call if the procedure is
> recursive

Hmm... but there is no difference from the patch you posted---it has
the same problem, or have I missed something?

> recording the time for such a procedure could be tricky.

I think what we have here is a problem very similar to that of
`trace'.  The tracing algorithm also needs to know when the exit
corresponding to a particular exit happens.  As Harvey points out in
his message, this is handled by using apply-frame-handler together
with exit-frame-handler.

Please look at the implementation of trace in (ice-9 debug).  It is
pretty straightforward code.  And feel free to ask if there is
something unclear.

> BHW, there is another hook called enter-frame-handler.  When is it
> called?

It's called at the start of the evaluation of every form, which in the
Guile evaluator is equivalent to the creation of a new stack frame.

At this point in time, you only have access to the source expression
and the environment, not the procedure.  I don't think this hook is
useful for you here.

> When I tried using it, it was never called.

You need to enable it using

  (trap-enable 'enter-frame)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]