GPROF-GNU Performance Analysis Tool

Source: Internet
Author: User
GPROF Introduction

GPROF is the GNU profiler tool. It can display the "flat profile" of the program running, including the number of calls to each function and the processor time consumed by each function. You can also display the "Call diagram", including the call relationship of the function, and the time consumed by each function call. You can also display the "annotated source code", which is a copy of the program source code, marking the number of executions of each line of code in the program.

Compile a program for GPROF

When compiling or linking source programsAdd the "-PG" option to the command line parameters.During compilation, the compiler automatically inserts code snippets for performance testing in the target code. These codes collect and record the call relationship and number of calls of the function during the program running, and collect and record the execution time of the function and the call time of the sub-function,After the program runs, A gmon. Out file is generated in the exit path of the program.. This file is the monitoring data recorded and saved. You can use GPROF in command line mode or kprof in graphical mode to interpret the data and analyze the program performance. In addition, if you want to view the profiling of the library function, you need to add "-lc_p" to compile the parameter in place of "-LC". In this way, the program will link to library libc_p.a, to generate the profiling information of the library function. If you want to execute the profiling of one row and one row, you also need to add the "-G" Compilation parameter.
For example, the command line gcc-wall-g-PG-lc_p example. C-o example

Basic GPROF usage:

1. Use-PG to compile and link your application.

2. Execute your application to generate data for GPROF analysis.

3. Use the GPROF program to analyze the data generated by your application.

$GPROF-B A. Out gmon. Out
Flat profile:

Each sample counts as 0.01 seconds.
No time accumulated

% Cumulative Self total
Time seconds cils ts/call name
0.00 0.00 0.00 1 0.00 0.00 Function

Call Graph

Granularity: each sample hit covers 2 byte (s) No time propagated

Index % time self children called name
0.00 0.00 1/1 main [8]
[1] 0.0 0.00 0.00 1 function [1]
-----------------------------------------------

Index by function name

[1] Function

Information generated by GPROF

% The percentage of the total running time of
Time program used by this function.
The percentage of time used by the function to all time.
Cumulative a running sum of the number of seconds accounted
Seconds for by this function and those listed abve it.
Cumulative execution time of functions and upper-column functions.
Self the number of seconds accounted for by this
Seconds function alone. This is the major sort for this
Listing.
The time when the function is executed.
Callthe number of times this function was invoked, if
This function is profiled, else blank.
Number of function calls
Self the average number of milliseconds spent in this
MS/call function per call, if this function is profiled,
Else blank.
Each call takes microseconds as the function time.
Total the average number of milliseconds spent in this
MS/call Function and Its descendents per call, if this
Function is profiled, else blank.
The average time of each call is microseconds.
Name the name of the function. This is the minor sort
For this listing. The index shows the location
The function in the GPROF listing. If the index is
In parenthesis it shows where it wowould appear in
The GPROF listing if it were to be printed.
Function Name

Command Format

GPROF [executable file] [gmon. Out file] [other parameters]

The content in square brackets can be omitted. If the "executable file" is omitted, GPROF searches for. the out file is an executable file. If gmon is omitted. out file, GPROF will also find gmon in the current directory. out. Other parameters can control the format and other information of GPROF output content. The most common parameters are as follows:

L-B no longer outputs detailed descriptions of each field in the Statistical Chart.

L-P only outputs the call graph of the function (the part of the Call Graph Information ).

L-Q only outputs the time consumption list of the function.

L-e name no longer outputs the call diagrams of the function name and its subfunctions (unless they have other parent functions that are not restricted ). Multiple-e flags can be specified. One-e flag can only specify one function.

L-e name no longer outputs the call diagram of the function name and its subfunctions. This flag is similar to the-e flag, however, in the calculation of the total time and percentage time, it excludes the time used by the function name and its subfunctions.

L-f name: The call diagram of the output function name and its subfunctions. Multiple-F flag can be specified. One-F flag can only specify one function.

L-f name: The call graph of the output function name and its subfunctions. It is similar to the-F sign, but it only uses the Time of the printed routine in the total time and percentage time calculation. Multiple-F flag can be specified. One-F flag can only specify one function. -F flag overwrites the-e flag.

L-Z shows a routine with zero usage (calculated based on the call count and accumulation time ).

However, GPROF cannot display the inheritance relationships between objects, which is also its weakness.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.