Optimizing Linux System Performance
Pages: 1, 2, 3
The following are the requirements to profile a program using gprof
- Profiling must be enabled when compiling and linking the program.
- A profiling data file is generated when the program is executed.
- Profiling data needs to be analyzed.
For you to use this gprof utility, the package must be installed on your system. In order to analyze the program with gprof, we need to compile the program with a special option. Assuming that we have a program sample_2007.c, the following can be used to compile i
$ gcc –a –p –pg –o sample_2007 sample_2007.c
Note here that –pg option enables the basic profiling support in gcc. The program will run somewhat slower when profiling is enabled. This is because of the fact that it needs to spend time in collecting data as well. The profiling support in the program creates a file named gmon.out in the current directory. This file is later used by gprof to analyze the code.
We can run the following command to get the output (which we have redirected to a file):
$ gprof sample_2007 gmon.out > output.txt
gprof is useful not only to determine how much time is spent in various routines, but it also tells you which routines invoke other routines. By using gprof, we will be able to know which sections of our code are causing the largest delays. Analyzing the source code with gprof is considered as an efficient way determining which function is using a large percentage of the overall time spent in executing the program.
A Few Things to Know About kprof
Kprof is a graphical tool that displays the execution profiling output generated by the gprof profiler. Kprof is very useful as it displays the information in list or tree view and it makes the information easy to understand.
Kprof has the following features
- Flat profile view displays all functions and methods as well as their profiling information.
- Hierarchical profile view displays a tree for each function and method with other functions and methods it calls as sub elements.
- Graph view is the graphical representation of the call tree.
References
- Optimizing Linux Performance: A Hands-On Guide to Linux performance tools, by Philip G. Ezolt, Prentice Hall PTR
- Linux Debugging and Performance Tuning: Tips and Techniques, by Steve Best, Prentice Hall PTR
- http://www.gnu.org/software/binutils/manual/
- http://www.yolinux.com/TUTORIALS/LinuxTutorialOptimization.html
- Performance Tuning for Linux Servers, by Badari Pulavarty, Gerrit Huizenga, Sandra K. Johnson, IBM Press
Swayam Prakasha has been working in information technology for several years, concentrating on areas such as operating systems, networking, network security, electronic commerce, Internet services, LDAP, and Web servers. Swayam has authored a number of articles for trade publications, and he presents his own papers at industry conferences. Currently he works at Unisys Bangalore in the Linux Systems Group.
Return to Linux DevCenter.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 5 of 5.
-
good one
2007-06-08 17:12:00 martin_12 [Reply | View]
I have seen many pieces on Optimization and this one looks neat (compared to many). I will give a rating of 8 out of 10 for this piece. May be there should have been an example on "gprof", but think length was the constraint.
-
PLEASE rename this thin article
2007-06-08 14:48:21 craig.knights [Reply | View]
This has little, if anything, to do with optimizing linux performance. Its mainly for application optimization and very light at that.
I dont mean to be a jerk, but this article is wrong is to many ways.




main:
push %ebp
movl %esp,%ebp
subl $12,%esp
push $100055
push $5
push $.L21
call printf
leave
ret
The loop is just not present there.
So leave the simple things for your compiler.
2. gprof wants you to recompile your code with an additional flag. collect and er_print (or analyzer instead of kprof) of sun studio can do the same without recompilation.