|
|
1.1 root 1: Execution Profiling
2:
3: You can use the built-in ML execution profiler to find out where the
4: bottlenecks in your programs are. The profiler will tell how much
5: time is spent in each function and how many calls were made to each
6: function. In order to profile a set of functions, those functions must
7: be compiled in "profiling mode".
8:
9: Here's how to use the profiler:
10:
11: (1) System.Control.Profile.profiling := true;
12:
13: This tells the compiler to insert profiling hooks in the compiled code
14: for any ML declarations that are compiled from now on, or until this
15: flag is set back to false.
16:
17: (2) compile some ML code, either by typing it in to the interactive
18: system, or by means of the "use" function.
19:
20: (3) System.Control.Profile.profileOn();
21:
22: This starts the timer interrupts that are used for statistical profiling.
23:
24: (4) execute your program
25:
26: (5) System.Control.Profile.profileOff();
27:
28: This turns off the timer interrupts.
29:
30: (6) System.Control.Profile.report std_out;
31:
32: This prints a report of profiling information on your screen. For
33: each function you will be told what percentage of the time was spent
34: in that function, how many calls were made, etc. Instead of std_out
35: you can call "report" with any outstream as an argument if, for
36: instance, you want the report sent to a file.
37:
38: Other commands:
39:
40: System.Control.Profile.reset: unit -> unit
41:
42: The "reset" command sets all timing and call-count information to
43: zero, but remembers which functions have been profiled.
44:
45: System.Control.Profile.clear: unit -> unit
46:
47: The "clear" command tells the system to forget about profiling any
48: functions that have been compiled so far, but allows you to compile
49: and profile further functions.
50:
51: Of course, the long names can be avoided by first opening the structure
52: System.Control.Profile.
53:
54: A slightly simpler way to use the profiler is as follows (after having
55: opened System.Control.Profile):
56:
57: (1) profiling := true;
58: (2) profileOn();
59: (3) compile and execute some ML code
60: (4) report std_out;
61: (5) repeat from step (3)
62: (6) when finished profiling, execute profileOff() and profiling := false
63:
64: The batch compiler can also be made to generate object files with
65: profiling code by toggling the flag "profiling" to true, using the
66: command "^profiling". We use this method to profile the compiler
67: itself.
68:
69: For more details about the profiler, and to learn more tricks you can
70: make it do, read the paper "Profiling in the presence of optimization
71: and garbage collection" provided in the doc/papers directory. Details
72: of the implemention have changed since that paper was written, but it
73: is still basically accurate.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.