This chapter describes how the execution of Caml Special Light programs can be profiled, by recording how many times functions are called, branches of conditionals are taken, ...
Before profiling an execution, the program must be compiled in
profiling mode, using the cslcp front-end to the cslc compiler
(see chapter
). When compiling modules separately,
cslcp must be used when compiling the modules (production
of .cmo files), and can also be used (though this is not strictly
necessary) when linking them together.
The amount of profiling information can be controlled through the -p option to cslcp, followed by one or several letters indicating which parts of the program should be profiled:
For instance, compiling with cslcp -pfilm profiles function calls, if... then... else..., loops and pattern matching.
Calling cslcp without the -p option defaults to -p fm, meaning that only function calls and pattern matching are profiled.
Running a bytecode executable file that has been compiled with cslcp records the execution counts for the specified parts of the program and saves them in a file called cslprof.dump in the current directory.
The cslprof.dump file is written only if the program terminates normally (by calling exit or by falling through). It is not written if the program terminates with an uncaught exception.
If a compatible dump file already exists in the current directory, then the profiling information is accumulated in this dump file. This allows, for instance, the profiling of several executions of a program on different inputs.
The cslprof command produces a source listing of the program modules where execution counts have been inserted as comments. For instance,
cslprof foo.ml
prints the source code for the foo module, with comments indicating
how many times the functions in this module have been called. Naturally,
this information is accurate only if the source file has not been modified
since the profiling execution took place.The following options are recognized by cslprof:
Profiling with cslprof only records execution counts, not the actual time spent into each function. There is currently no way to perform time profiling on bytecode programs generated by cslc. On native-code programs generated by cslopt, the standard Unix profiler prof can be used; just add the -ccopt -p option when linking the program:
cslopt -o myprog -ccopt -p other-options files
./myprog
prof myprog
Function names in the output of prof have the following format:
Module-name_function-name_unique-number