ptrace for profiling?

Simon Marlow simonmar@microsoft.com
Wed, 2 Apr 2003 10:52:13 +0100


> this may be a totally absurd request, but would it be possible to use
> ptrace or some other mechanism for poking a running program to cause a
> program to start generating profiling data or change what type of
> profiling data it is producing?=20
>=20
> I tend to view the profiling graph in real-time as I run my Haskell
> program interactively. every now and again I notice my program is
> behaving oddly but I am unable to reproduce the events that led to the
> odd behavior. It would be nice to be able to poke the program=20
> in such a
> way to cause it to start writing profiling frames to the stack for a
> bit.=20

Hmmm.  It might be possible to turn on profiling (time or space) for a
running program, but that would doubtless require quite a few changes to
the runtime.  The program has to be compiled for profiling to begin
with, of course.

There are certain changes that it isn't possible to make in the middle
of a run (e.g. changing from retainer to biographical profiling sounds
highly implausible, if not impossible).

You can run the program in gdb, stop at a certain point (eg. before a
GC) and change the profiling flags (RtsFlags.ProfFlags.*) and see what
happens...  you'll need to compile up an RTS with debugging info (see
config.mk for details) and link to it (-L should do the trick).

Cheers,
	Simon