Analyzing run-time behavior

Profiling utilities

Profilers are tools that analyze the dynamic behavior of your program: how fast, how often and, sometimes, when the parts of its code are executed when the program is run. First, the profilers gather data at run time. Then, they interpret this data, for one of two purposes:

There are four types of profiling:

Time and line profiling display information to the programmer. Flow and block profiling information can be read by either the programmer or by the compilation system.

Complementary utilities are available for profiling C and C++ source programs:

There is a good deal of overlap in functionality between time profiling and flow profiling.

fprof has all of the functionality of prof and more, but this extra functionality comes with a cost. This cost is manifested in 3 ways: fprof experiments require a good deal of disk space, often require root privilege to run and generate more overhead in the experiment. If none of these issues matters to you, use fprof. If all you want is the kind of information that prof provides, use prof.

There seems to be overlap between line profiling and block profiling as well. However, line profiling is used for display to programmers while block profiling is intended for consumption by automated tools. (Block profile logs can be printed, but they are difficult to read).

Line profiling is complementary to time and flow profiling in this sense. You can use prof or fprof to identify the most time-consuming (or, for other reasons, critical) parts of a program. You can then use lprof to obtain line-specific information only about those parts. In that way, you can avoid generating uninformative output while targeting the lines of code whose performance needs to be improved. You may then be able to rewrite those lines to execute more efficiently. See ``Improving program performance by programmer analysis'' for more information.

The tuning performed using flow and block profiles is also complementary. Flow profiling determines the best order to lay out functions in the program. Block profiling determines the best order to lay out blocks within each function. (Actually, block profiling can also choose an order for the functions but does not do as well as flow profiling.)

The automated tools are very powerful, but only if you already have efficient programs. If you are just beginning to look into why your program is running slowly, the automated tools will have little effect. The automated tools have an effect similar to optimization: they make code run more efficiently, but neither can overcome inefficient program design.

Next topic: How to use the profilers
Previous topic: Analyzing run-time behavior

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004