LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Discuss Subscribe to Linux Subscribe to Newsletters

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.


What problems slow your system to a crawl? Any tips you can give for avoiding them?
You must be logged in to the O'Reilly Network to post a talkback.
Post Comment
Full Threads Oldest First

Showing messages 1 through 5 of 5.

  • the proper tool can do it for you
    2007-06-15 07:29:45  horsh [Reply | View]

    1. The suncc compiler of sunstudio 12 produces the follwoing assembly code for the first example:

    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.
  • 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.
  • A good piece
    2007-06-07 19:54:27  christ_li [Reply | View]

    I liked this piece very much. Hoping to see such nice articles in the days to come.

    Swayam - I need your help in resolving some of my problems on Linux. Will take this offline
  • An interesting one
    2007-06-07 19:45:05  techie19 [Reply | View]

    This is an excellent piece. Learnt a lot on performance optimization. Thanks to O'Reilly for putting this up.


Tagged Articles

Be the first to post this article to del.icio.us

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
O'Reilly FYI
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com