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.
|Published (Last):||21 June 2017|
|PDF File Size:||17.58 Mb|
|ePub File Size:||17.11 Mb|
|Price:||Free* [*Free Regsitration Required]|
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.
By default the report is written to stdout, which can always be redirected to a file with a name of your choosing. For parallel programs, the report is a summation of the files used to produce it. Flat Profile The Flat Profile section shows the total amount of time your program spent executing each function, sorted by decreasing run-time.
Unless the -z option is used, functions with no apparent time spent in them, and no apparent calls to them, are not mentioned. An example Flat Profile section is shown below. Note that the report includes an explanation of what each column means. 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 granularity: each sample hit covers 2 byte s for 0. FormatControl . GetMyLocalContext .
GetUnit . IOSetRecordOffset . For applications where compiling and linking are separate steps, -pg must be included in both steps. It is used to produce a unique sampling data file for each process in a parallel application. See step 2 under the Quick Start section above. Searching the Web will turn up Gprof tutorials and more.
gprof - Unix, Linux Command
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.
GPROF Tutorial – How to use Linux GNU GCC Profiling Tool
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.
How to profile C/C++ code using gprof