Intended audience: all readers.

Profilers are tools that allow the programmer to identify the section of codes that are acting as performance bottlenecks and thus help the programmer identify where effort should be expended in order to improve overall program speed. There is a school of thought that says that programmers should not worry about optimization until the end of the software development cycle. I recommend skipping classes at that school.

A poorly designed solution to a problem may not be salvageable in the final weeks of a project, but at the same time, programmer optimization does sometimes get abused by taking readable code that is perfectly fine performance wise and hand optimizing it in an ugly way without either proof that it requires optimization or proof that the resulting ugly code is any faster is indeed a danger. An interesting paper on this topic is available here.

In any case, when the time comes to optimize, it is nice if you can make use of tools to help you know where to focus your efforts. This page will focus on several tools that are compatible with the compilers produced by the GNU Ada project.


gprof is generally available for every platform for which there is a GNU Ada compiler. It requires that you compile your program with some special flags to enable the collection of the profile data. Once compiled, you run the program normally and when the program is complete, there will be a file called gmon.out present in the directory that contains some binary data about the execution of the program. To actually view this data, you need to run it through gprof by entering gprof name_of_your_program.

The output of gprof is plain text. At some point this write-up should be extended to include how to interpret the gprof output however, google around for help. Everything that applies to general C/C++ gprof usage applies to the use of this for Ada as well.

When running under Linux, there is a well known (yet still not fixed!) problem with gprof and multi-threaded programs. This problem also applies to Ada programs that use tasks. gprof will only collect profile data for the main task. Luckily, there is also a fairly well known and simple workaround that works for multi-threaded/tasking applications. This page has a very simple writeup on the approach and it has been verified to work for Ada.

The downside to gprof is that it requires you to recompile your application to instrument it for profiling but it has a fairly small impact on overall program runtime.


valgrind is an extremely useful program (currently only supports x86/Linux, AMD64/Linux and PPC32/Linux) that is capable of helping developers find memory management, some threading/tasking bugs and in performing several types of profiling. When combined with kcachegrind (A KDE GUI front-end) it is arguably the best tool available for the job.

First, your program is run under the supervision of valgrind (no special profiling flags are required however you really need to compile with debugging enabled to get the best results). Once your program completes, you can explore the results with kcachegrind.

The biggest downside to this combination is that valgrind works be executing the program under a virtual CPU type environment. Depending on what you ask it to do, the program can end up executing many many times slower than a normal run.



Ada programming, © 2005,2006 the Authors, Content is available under GNU Free Documentation License.