implementing profiling (mostly) in SML
Stephen Weeks
MLton@sourcelight.com
Fri, 23 Mar 2001 09:52:52 -0800 (PST)
I thought of a slight modification of my previous proposal to implement the
profile gathering code in SML. The problem with my previous proposal was that
it only ran in SML signal handlers, which missed C ticks and got the data only
at safe points. What if we instead gather the data in the C signal handler, but
process it in the SML code? That is, modify GC_handler so that if profiling is
happening it stashes the needed pc somewhere. Then, the SML code in the SIGRPOF
handler gets the pc using a new primitive and does all the needed processing.
This has the advantage that all of the portable stuff is in the SML code and
only the grungy stuff is in C.
The only problem I see is if multiple SIGPROFS come in before the SML signal
handler runs. But I think that could only happen if we're stuck in C code.
Maybe that's reason enough not to do it this way, but I at least thought I'd
mention it.