To obtain the best trade-off between productivity and efficiency, programmers should not spend too much time optimizing their code until they know which parts of the code are really taking up most of the time. Only once the code has been profiled should the programmer consider making optimizations that would improve efficiency at the expense of readability or ease of maintenance. A good profiler is therefore a tool that should be part of every software engineer’s toolkit.
Mercury programs can be analyzed using two distinct profilers. The Mercury profiler ‘mprof’ is a conventional call-graph profiler (or graph profiler for short) in the style of ‘gprof’. The Mercury deep profiler ‘mdprof’ is a new kind of profiler that associates a lot more context with each measurement. ‘mprof’ can be used to profile either time or space, but not both at the same time; ‘mdprof’ can profile both time and space at the same time.
The parallel execution of Mercury programs can be analyzed with a third profiler called ‘threadscope’. ‘threadscope’ allows programmers to visualise CPU utilisation for work, garbage collection, and idle time. This enables programmers to see the effect of parallelization decisions such as task granularity. The ‘threadscope’ tool is not included with the Melbourne Mercury Compiler, See Threadscope: Performance Tuning Parallel Haskell Programs.