Lately I've needed to do some profiling in PLT Scheme, and the usual process in DrScheme hasn't been working for me. If you don't know, here's the usual process:
- Language --> Choose Language
- Show Details
- Debugging and Profiling
- Run Program
- View --> Show Profile
First, get your program (or the parts of it you want to profile) in shape to be run easily from the REPL. I already have a run-tests.ss module which runs all my tests and exercises the code in a pretty realistic way, so I just entered (require "run-tests.ss"); you should do something similar. Then:
- Fire up mzscheme:
mzscheme -i -l errortrace
The -i tells mzscheme to start in interpreter mode; the -l errortrace says "load errortrace first thing". - Set a couple of parameters for errortrace:
(instrumenting-enabled #t) (profiling-enabled #t) (profiling-record-enabled #t)
- Run your program. For example:
(require "run-tests.ss")
- Output the profile information:
(output-profile-results #t #t)
Or:(with-output-to-file "profile.dat" (lambda () (output-profile-results #t #t)))
The two #ts tell errortrace to output the path-to-function-source information and to sort in terms of total time taken.