|
It is a truism that the most time-consuming and frequently used sections of a program should be optimized first. Profiling tools should be used before performance tuning begins, both to discover these areas and to provide a baseline for measuring the effectiveness of the tuning that is being performed later. When profiling the application, use (and be consistent in using) realistic sizes of workload and datasets. Although you need to use some variety later in the fine-tuning process or else risk tuning to one model at the expense of others, early iterations using the same initial loads as the baseline can offer insight into successful tuning attacks. The basic profiling tools in Linux are the p (profile) and pg (profile for gprof) options in gcc, and the prof and gprof utilities. Compiling using p or -pg causes gcc to insert instructions necessary to obtain profiling information into the object code. Running the prof command with the application allows you to then obtain the following:
Running the gprof command with the application gathers (among other information) the following:
Because gprof includes the descendents of a procedure in its timings, it is more useful for procedures calling library routines. Although other profiling tools are available to the developer, prof and gprof are mentioned here because they are the most commonly available. Some of these alternative tools can be specialized for a specific purpose, such as parallel programming or massively multithreaded applications. After successfully profiling for optimization, you are ready to begin tuning. Modern compilers offer many optional optimization features. gcc, for example, offers more than 60 options related to performance optimization. The next section discusses basic steps and compilers as tuning tools. |
|