[MLton] profiling question

Lukasz S Ziarek lziarek@cs.purdue.edu
Fri, 19 Mar 2004 13:04:02 -0500 (EST)

On Tue, 16 Mar 2004, Stephen Weeks wrote:

> > I decided to just use my own counters and create variables that I append
> > into the program. The only thing I am not sure about is how to send my
> > counters to stdout or a file.
> It may be easier to create a single array on the C side with one
> element for each coercion point, and have each coercion point
> increment the appropriate array element.  You can allocate the array
> with an FFI call that you insert somewhere near program startup.  You
> can also make an FFI call at each coercion point to bump the counter,
> by passing the array index to the C function.  Finally, you can add a
> line to the runtime function GC_done that writes out the counts to a
> file.
> You do need to be aware that with this approach, the inserted code may
> substantially affect subsequent optimization.  If you want to avoid
> that, you need to modify the profiling infrastructure.  To do that,
> you could add a new profile variant to the Control structure, say,

I am opting for this approach and have most of it implimented.

> ProfileFlatten.  You could then insert Profile Enter and Profile Leave
> statements around the points you want to count, with source info that
> somehow indicates the point in the SSA IL that you want to look at.
> You'll then need to modify backend/profile.fun to handle this new
> profile variant so that it inserts calls to C functions to increment
> the profile counts, very much like is done with ProfileAlloc, but
> presumably with increment of 1 rather than bytes allocated.

I did exactly this, added an extra if then else, that checks for the
profileFlatten flag passed on the command line. Instead of incrementing by
bytesallocated I increment by one. I have verified that this is the case
with print statements during the backend pass.

> Once you've done that, you get all the profiling infrastructure
> working for you.  That is, the runtime will allocate the array for the
> counts, maintain the dynamic counts, and spit out the mlmon.out file.

I get into trouble generating the mlmon.out file. Right now profileflatten
should work exactly like alloc, but increment by one instead of bytes
allocated. But when I run it on a test file I get no mlmon.out file. I am
using tak.sml from the profiling examples in the doc section.  It seems
like profile.sml in the basis library generates the mlmon file. It does
not look like it checks what type of profiling is being done to generate
the file. I have been looking through the other files that have to do with
profiling, but I am not sure if any of these need modification. Are there
any files I should be looking at besides profile.fun in the backend? I am not
completely familiar with the mlton back end.


> You can also use mlprof to look at the data.
> _______________________________________________
> MLton mailing list
> MLton@mlton.org
> http://www.mlton.org/mailman/listinfo/mlton