[Template-haskell] Profiling with Template Haskell

Simon Peyton-Jones [email protected]
Wed, 3 Sep 2003 09:39:35 +0100


| | Now I know that profiling splicing doesn't make too much sense.
That
| | is not what I wish to do though. I wish to profile the final
| | executable.

I've thought more about the question of profiling and TH.

The issue is this:

	how can one compile a program that uses TH
	so that the resulting executable is profiled

I'll call
 	C-code		is code that runs at compile time
	R-code		is code that runs at runtime

We aren't trying to profile C-code, only R-code.

It is possible in TH for a particular function to be both C-code and
R-code, but that's unusual.  Indeed, if you mix C-code and R-code in a
particular module, then the R-code will be linked but not run when TH
loads the module; and the C-code will be linked but not run in the final
executable.

So in practice, I expect that most modules will consist *either* of
C-code *or* R-code.  Let's assume that's the case.

Then, all you need do is
	compile C-code without -prof
	compile R-code with -prof

And Bob's your uncle.


If a module Foo contains both C-code and R-code, then you need to
compile it both ways.  Make sure that the non -prof way generates Foo.o.
For the -prof way, generate Foo.p_o (using -o).   TH will look for
Foo.o, and that'll be fine.  Your final link step must link Foo.p_o.
You can't do this with --make.



As far as I can see, that closes the issue. Right?   If so, would
someone (Ian?) like to update the manual to include a section that
explains this issue?

Many thanks

Simon