CS190
gprof assignment
April 17, 2001
Due Monday 4/30/01
This assignment is intended to give you a chance to demonstrate that you
know how to profile code and find performance bottlenecks.
Choose 5-10 methods from some component of your project. If you wrote
code, use your code. Otherwise, pick any component you want, preferably
aiming for one where performance will be important. Answer the
following questions and record your answers before profiling.
- 1.
- Before running gprof, make the following predictions:
- Rank the functions from most frequently called to
least frequently called
- Rank the functions in terms of time spent in that
function (``self'' time instead of cumulative time)
- 2.
- Predict where the hot spots will be in the code you've
chosen, and explain why.
- 3.
- Compile your code without any optimizations and profile
it with gprof. Save the output from gprof and answer the
questions below.
- 4.
- EXTRA CREDIT: Compile your code with optimizations
(either -O2 or -fast will work, but check the compiler man
page for the differences) and then profile it again. Do the same
tasks so that the results are comparable. Save the output from gprof
and answer the last question below
- 5.
- Analyze the output from both runs, and answer the
following questions
- What did you do with the application when you
ran your program with profiling? Your choice of
activities will likely affect what results you get, so
it's important to perform a representative set of
tasks.
- Where are the hot spots in your code? Were your
predictions correct? Include hot spots in routines
that you worked with as well as those that you did not.
- Which functions would
be good candidates for optimization changes? Why?
- EXTRA CREDIT QUESTION: Suppose someone made the
statement ``Having the
compiler optimize your code simply makes everything run
faster. All functions get called the same number of
times, and take the same amount of time to execute
relative to one another''. Is this statement accurate?
What evidence (from the gprof output) do you have to
support this? What evidence do you have to contradict
this?
Record the answers to the above questions (both pre- and post-gprof),
and include a subset of your gprof output. Include the sections of the
call graph profile and the lines from the flat profile which contain
the functions mentioned in both your predictions and your analysis.
If you did the optimized vs. unoptimized run, include excerpts from
both runs, labeled appropriately.
Specify which level of optimization you used.
Due Monday, April 30.
Here is a brief summary of how to use gprof.
- Recompile all your code for profiling. This means you
should specify the -xpg option on the compile and link lines.
- Run the program. Perform a carefully crafted set of
tasks that will exercise the parts of the program you want to
evaluate. Having this be repeatable will make it much easier to
evaluate any changes that you make to optimize the code. It must terminate
normally (either by returning from main or calling exit(3c))
- run gprof -C [executable] to extract the profile.
The O'Reilly book High Performance
Computing by Kevin Dowd and Charles Severance has a section on
interpreting the output from gprof. Or see a TA!
David Laidlaw, dhl@cs.brown.edu