This preview shows page 1. Sign up to view the full content.
Unformatted text preview: g. With GCC (and other C compilers) this involves simply including the run-time ﬂag ‘-pg’ on the command line:
unix> gcc -O2 -pg prog.c -o prog 2. The program is then executed as usual:
unix> ./prog file.txt It runs slightly (up to a factor of two) slower than normal, but otherwise the only difference is that it generates a ﬁle gmon.out. 262 CHAPTER 5. OPTIMIZING PROGRAM PERFORMANCE 3. G PROF is invoked to analyze the data in gmon.out.
unix> gprof prog The ﬁrst part of the proﬁle report lists the times spent executing the different functions, sorted in descending order. As an example, the following shows this part of the report for the ﬁrst three functions in a program:
% cumulative time seconds 85.62 7.80 6.59 8.40 4.50 8.81 self seconds 7.80 0.60 0.41 self ms/call 7800.00 0.00 0.00 total ms/call 7800.00 0.00 0.00 calls 1 946596 946596 name sort_words find_ele_rec lower1 Each row represents the time spent for all calls to some function. The ﬁrst column indicates the percentage of the overall time spent on the function. The second shows the cumulative time spent by the function...
View Full Document
- Spring '10
- The American