GPROF TUTORIAL PDF

Run your program again, the same as before. Analyze the cumulative data using this command: gprof executable-file gmon. There is no direct information about these measurements in the profile data itself. Instead, gprof estimates them by making an assumption about your program that might or might not be true.

Author:Kagatilar Malakinos
Country:Argentina
Language:English (Spanish)
Genre:Sex
Published (Last):5 February 2005
Pages:398
PDF File Size:17.46 Mb
ePub File Size:4.43 Mb
ISBN:297-1-37942-708-5
Downloads:87585
Price:Free* [*Free Regsitration Required]
Uploader:Kajisho



Through profiling one can determine the parts in program code that are time consuming and need to be re-written. This helps make your program execution faster which is always desired. In very large projects, profiling can save your day by not only determining the parts in your program which are slower in execution than expected but also can help you find many other statistics through which many potential bugs can be spotted and sorted out. How to use gprof Using the gprof tool is not at all complex.

You just need to do the following on a high-level: Have profiling enabled while compiling the code Execute the program code to produce the profiling data Run the gprof tool on the profiling data file generated in the step above.

The last step above produces an analysis file which is in human readable form. This file contains a couple of tables flat profile and call graph in addition to some other information. While flat profile gives an overview of the timing information of the functions like time consumption for the execution of a particular function, how many times it was called etc. On the other hand, call graph focuses on each function like the functions through which a particular function was called, what all functions were called from within this particular function etc So this way one can get idea of the execution time spent in the sub-routines too.

Lets try and understand the three steps listed above through a practical example. Step-1 : Profiling enabled while compilation In this first step, we need to make sure that the profiling is enabled when the compilation of the code is done.

From the man page of gcc : -pg : Generate extra code to write profile information suitable for the analysis program gprof. You must use this option when compiling the source files you want data about, and you must also use it when linking. Step-2 : Execute the code In the second step, the binary file produced as a result of step-1 above is executed so that profiling information can be generated.

Note that while execution if the program changes the current working directory using chdir then gmon. Also, your program needs to have sufficient permissions for gmon. This produces an analysis file which contains all the desired profiling information.

On a related note, you should also understand how to debug your C program using gdb. Lets have a look at this text file : Flat profile: Each sample counts as 0. This is the major sort for this listing. This is the minor sort for this listing. The index shows the location of the function in the gprof listing. If the index is in parenthesis it shows where it would appear in the gprof listing if it were to be printed. Call graph explanation follows granularity: each sample hit covers 2 byte s for 0.

Each entry in this table consists of several lines. The line with the index number at the left hand margin lists the current function. The lines above it list the functions that called this function, and the lines below it list the functions this one called.

This line lists: index A unique number given to each element of the table. Index numbers are sorted numerically. The index number is printed next to every function name so it is easier to look up where the function in the table. The index number is printed after it. If the parent is a member of a cycle, the cycle number is printed between the name and the index number.

If the child is a member of a cycle, the cycle number is printed between the name and the index number. If there are any cycles circles in the call graph, there is an entry for the cycle-as-a-whole. This entry shows who called the cycle as parents and the members of the cycle as children. Flat profile 2. Call graph The individual columns for the flat profile as well as call graph are very well explained in the output itself.

Customize gprof output using flags There are various flags available to customize the output of the gprof tool. Some of them are discussed below: 1. So we see that there is no information related to func2 which is defined static 2. Suppress verbose blurbs using -b As you would have already seen that gprof produces output with lot of verbose information so in case this information is not required then this can be achieved using the -b flag.

Now if we see that analysis output: Flat profile: Each sample counts as 0. Also, if there is a requirement to print flat profile but excluding a particular function then this is also possible using -P flag by passing the function name to exclude along with it.

Now lets see the analysis output: Flat profile: Each sample counts as 0. Lets see what effect it casts on analysis output: Call graph granularity: each sample hit covers 2 byte s for 0. Print only specific function information in call graph. This is possible by passing the function name along with the -q option. Suppress call graph using -Q If the call graph information is not required in the analysis output then -Q option can be used.

The whole call graph got suppressed. Also, if it is desired to suppress a specific function from call graph then this can be achieved by passing the desired function name along with the -Q option to the gprof tool. Now if we see the analysis output: Call graph granularity: each sample hit covers 2 byte s for 0.

CANON MP220 MANUAL PDF

gprof - Unix, Linux Command

Quick Start Using Gprof is a simple three or four step process, as shown below. Note that if you compile and link as separate steps in your application build, you will need to include -pg in both steps. Run your application as usual. The example below shows a 16 task MPI application running in the pdebug partition on a Linux cluster. View the results: use the gprof command to convert the output file s into a human-readable report.

YAHUDI MENGGENGGAM DUNIA PDF

What is gprof?

The effect of called routines is incorporated in the profile of each caller. The profile data is taken from the call graph profile file gmon. The -pg option also links in versions of the library routines that are compiled for profiling. Gprof reads the given object file the default is a. If more than one profile file is specified, the gprof output shows the sum of the profile information in the given profile files. Gprof calculates the amount of time spent in each routine.

Related Articles