Previous Next Table of Contents

6. Profiling

Another useful technique is ``profiling,'' to find out where your program is spending most of its time. This can help you to make a program more efficient.

Here is how to profile a program:

  1. Remove all the .o files and the ``circle'' executable:
            rm src/*.o bin/circle
    
  2. Edit your Makefile, and change the PROFILE= line:
            PROFILE  = -p
    
  3. Remake circle:
            make
    
  4. Run circle as usual. Shutdown the game with the shutdown command when you have run long enough to get a good profiling base under normal usage conditions. If you crash the game, or kill the process externally, you won't get profiling information.
  5. Run the prof command:
            prof bin/circle > prof.out
    
  6. Read prof.out. Run ``man prof'' to understand the format of the output.

For advanced profiling, you can use ``PROFILE = -pg'' in step 2, and use the ``gprof'' command in step 5. The ``gprof'' form of profiling gives you a report which lists exactly how many times any function calls any other function. This information is valuable for debugging as well as performance analysis.

Availability of ``prof'' and ``gprof'' varies from system to system. Almost every Unix system has ``prof''. Only some systems have ``gprof''.


Previous Next Table of Contents