Linux "gprof" Command Line Options and Examples
display call graph profile data

"gprof" produces an execution profile of C, Pascal, or Fortran77 programs. 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.


Usage:

gprof [ -[abcDhilLrsTvwxyz] ] [ -[ACeEfFJnNOpPqQZ][name] ]
[ -I dirs ] [ -d[num] ] [ -k from/to ]
[ -m min-count ] [ -R map_file ] [ -t table-length ]
[ --[no-]annotated-source[=name] ]
[ --[no-]exec-counts[=name] ]
[ --[no-]flat-profile[=name] ] [ --[no-]graph[=name] ]
[ --[no-]time=name] [ --all-lines ] [ --brief ]
[ --debug[=level] ] [ --function-ordering ]
[ --file-ordering map_file ] [ --directory-path=dirs ]
[ --display-unused-functions ] [ --file-format=name ]
[ --file-info ] [ --help ] [ --line ] [ --inline-file-names ]
[ --min-count=n ] [ --no-static ] [ --print-path ]
[ --separate-files ] [ --static-call-graph ] [ --sum ]
[ --table-length=len ] [ --traditional ] [ --version ]
[ --width=n ] [ --ignore-non-functions ]
[ --demangle[=STYLE] ] [ --no-demangle ]
[--external-symbol-table=name]
[ image-file ] [ profile-file ... ]






Command Line Options:

--annotated-source[
The -A option causes "gprof" to print annotated source code. If symspec is specified, print output only for matching symbols.
gprof --annotated-source[ ...
--brief"
If the -b option is given, "gprof" doesn't print the verbose blurbs that try to explain the meaning of all of the fields in thetables. This is useful if you intend to print out the output, or are tired of seeing the blurbs.
gprof --brief" ...
--exec-counts[
The -C option causes "gprof" to print a tally of functions and the number of times each was called. If symspec is specified,print tally only for matching symbols.If the profile data file contains basic-block count records, specifying the -l option, along with -C, will cause basic-blockexecution counts to be tallied and displayed.
gprof --exec-counts[ ...
--file-info"
The -i option causes "gprof" to display summary information about the profile data file(s) and then exit. The number ofhistogram, call graph, and basic-block count records is displayed.
gprof --file-info" ...
--directory-path
The -I option specifies a list of search directories in which to find source files. Environment variable GPROF_PATH can also beused to convey this information. Used mostly for annotated source output.
gprof --directory-path ...
--no-annotated-source[
The -J option causes "gprof" not to print annotated source code. If symspec is specified, "gprof" prints annotated source, butexcludes matching symbols.
gprof --no-annotated-source[ ...
--print-path"
Normally, source filenames are printed with the path component suppressed. The -L option causes "gprof" to print the fullpathname of source filenames, which is determined from symbolic debugging information in the image file and is relative to thedirectory in which the compiler was invoked.
gprof --print-path" ...
--flat-profile[
The -p option causes "gprof" to print a flat profile. If symspec is specified, print flat profile only for matching symbols.
gprof --flat-profile[ ...
--no-flat-profile[
The -P option causes "gprof" to suppress printing a flat profile. If symspec is specified, "gprof" prints a flat profile, butexcludes matching symbols.
gprof --no-flat-profile[ ...
--graph[
The -q option causes "gprof" to print the call graph analysis. If symspec is specified, print call graph only for matchingsymbols and their children.
gprof --graph[ ...
--no-graph[
The -Q option causes "gprof" to suppress printing the call graph. If symspec is specified, "gprof" prints a call graph, butexcludes matching symbols.
gprof --no-graph[ ...
--table-length
The -t option causes the num most active source lines in each source file to be listed when source annotation is enabled. Thedefault is 10.
gprof --table-length ...
--separate-files"
This option affects annotated source output only. Normally, "gprof" prints annotated source files to standard-output. If thisoption is specified, annotated source for a file named path/filename is generated in the file filename-ann. If the underlyingfile system would truncate filename-ann so that it overwrites the original filename, "gprof" generates annotated source in thefile filename.ann instead (if the original file name has an extension, that extension is replaced with .ann).
gprof --separate-files" ...
--no-exec-counts[
The -Z option causes "gprof" not to print a tally of functions and the number of times each was called. If symspec is specified,print tally, but exclude matching symbols.
gprof --no-exec-counts[ ...
--function-ordering"
The --function-ordering option causes "gprof" to print a suggested function ordering for the program based on profiling data.This option suggests an ordering which may improve paging, tlb and cache behavior for the program on systems which supportarbitrary ordering of functions in an executable.The exact details of how to force the linker to place functions in a particular order is system dependent and out of the scope ofthis manual.
gprof --function-ordering" ...
--file-ordering
The --file-ordering option causes "gprof" to print a suggested .o link line ordering for the program based on profiling data.This option suggests an ordering which may improve paging, tlb and cache behavior for the program on systems which do not supportarbitrary ordering of functions in an executable.Use of the -a argument is highly recommended with this option.The map_file argument is a pathname to a file which provides function name to object file mappings. The format of the file issimilar to the output of the program "nm".
gprof --file-ordering ...
-lang.o:00000000
T maybe_objc_method_name
gprof -lang.o:00000000 ...
-decl.o:00000000
T print_lang_identifier
gprof -decl.o:00000000 ...
--traditional"
The -T option causes "gprof" to print its output in "traditional" BSD style.
gprof --traditional" ...
--width
Sets width of output lines to width. Currently only used when printing the function index at the bottom of the call graph.
gprof --width ...
--all-lines"
This option affects annotated source output only. By default, only the lines at the beginning of a basic-block are annotated.If this option is specified, every line in a basic-block is annotated by repeating the annotation for the first line. Thisbehavior is similar to "tcov"'s -a.
gprof --all-lines" ...
--no-demangle"
These options control whether C++ symbol names should be demangled when printing output. The default is to demangle symbols.The "--no-demangle" option may be used to turn off demangling. Different compilers have different mangling styles. The optionaldemangling style argument can be used to choose an appropriate demangling style for your compiler.Analysis Options
gprof --no-demangle" ...
--no-static"
The -a option causes "gprof" to suppress the printing of statically declared (private) functions. (These are functions whosenames are not listed as global, and which are not visible outside the file/function/block where they were defined.) Time spentin these functions, calls to/from them, etc., will all be attributed to the function that was loaded directly before it in theexecutable file. This option affects both the flat profile and the call graph.
gprof --no-static" ...
--static-call-graph"
The -c option causes the call graph of the program to be augmented by a heuristic which examines the text space of the objectfile and identifies function calls in the binary machine code. Since normal call graph records are only generated when functionsare entered, this option identifies children that could have been called, but never were. Calls to functions that were notcompiled with profiling enabled are also identified, but only if symbol table entries are present for them. Calls to dynamiclibrary routines are typically not found by this option. Parents or children identified via this heuristic are indicated in thecall graph with call counts of 0.
gprof --static-call-graph" ...
--ignore-non-functions"
The -D option causes "gprof" to ignore symbols which are not known to be functions. This option will give more accurate profiledata on systems where it is supported (Solaris and HPUX for example).
gprof --ignore-non-functions" ...
-k
The -k option allows you to delete from the call graph any arcs from symbols matching symspec from to those matching symspec to.
gprof -k ...
--line"
The -l option enables line-by-line profiling, which causes histogram hits to be charged to individual source code lines, insteadof functions. This feature only works with programs compiled by older versions of the "gcc" compiler. Newer versions of "gcc"are designed to work with the "gcov" tool instead.If the program was compiled with basic-block counting enabled, this option will also identify how many times each line of codewas executed. While line-by-line profiling can help isolate where in a large function a program is spending its time, it alsosignificantly increases the running time of "gprof", and magnifies statistical inaccuracies.
gprof --line" ...
--inline-file-names"
This option causes "gprof" to print the source file after each symbol in both the flat profile and the call graph. The full pathto the file is printed if used with the -L option.
gprof --inline-file-names" ...
--min-count
This option affects execution count output only. Symbols that are executed less than num times are suppressed.
gprof --min-count ...
--time
The -n option causes "gprof", in its call graph analysis, to only propagate times for symbols matching symspec.
gprof --time ...
--no-time
The -n option causes "gprof", in its call graph analysis, not to propagate times for symbols matching symspec.
gprof --no-time ...
--external-symbol-table
The -S option causes "gprof" to read an external symbol table file, such as /proc/kallsyms, rather than read the symbol tablefrom the given object file (the default is "a.out"). This is useful for profiling kernel modules.
gprof --external-symbol-table ...
--display-unused-functions"
If you give the -z option, "gprof" will mention all functions in the flat profile, even those that were never called, and thathad no time spent in them. This is useful in conjunction with the -c option for discovering which routines were never called.Miscellaneous Options
gprof --display-unused-functions" ...
--debug[
The -d num option specifies debugging options. If num is not specified, enable all debugging.
gprof --debug[ ...
--help"
The -h option prints command line usage.
gprof --help" ...
--file-format
Selects the format of the profile data files. Recognized formats are auto (the default), bsd, 4.4bsd, magic, and prof (not yetsupported).
gprof --file-format ...
--sum"
The -s option causes "gprof" to summarize the information in the profile data files it read in, and write out a profile data filecalled gmon.sum, which contains all the information from the profile data files that "gprof" read in. The file gmon.sum may beone of the specified input files; the effect of this is to merge the data in the other input files into gmon.sum.Eventually you can run "gprof" again without -s to analyze the cumulative data in the file gmon.sum.
gprof --sum" ...
--version"
The -v flag causes "gprof" to print the current version number, and then exit.Deprecated OptionsThese options have been replaced with newer versions that use symspecs.
gprof --version" ...
-e
The -e function option tells "gprof" to not print information about the function function_name (and its children...) in the callgraph. The function will still be listed as a child of any functions that call it, but its index number will be shown as [notprinted]. More than one -e option may be given; only one function_name may be indicated with each -e option.
gprof -e ...
-E
The "-E function" option works like the "-e" option, but time spent in the function (and children who were not called fromanywhere else), will not be used to compute the percentages-of-time for the call graph. More than one -E option may be given;only one function_name may be indicated with each -E option.
gprof -E ...
-f
The -f function option causes "gprof" to limit the call graph to the function function_name and its children (and theirchildren...). More than one -f option may be given; only one function_name may be indicated with each -f option.
gprof -f ...
-F
The -F function option works like the "-f" option, but only time spent in the function and its children (and their children...)will be used to determine total-time and percentages-of-time for the call graph. More than one -F option may be given; only onefunction_name may be indicated with each -F option. The -F option overrides the -E option.FILES"a.out"the namelist and text space."gmon.out"dynamic call graph and profile."gmon.sum"summarized dynamic call graph and profile.BUGSThe granularity of the sampling is shown, but remains statistical at best. We assume that the time for each execution of a functioncan be expressed by the total time for the function divided by the number of times the function is called. Thus the time propagatedalong the call graph arcs to the function's parents is directly proportional to the number of times that arc is traversed.Parents that are not themselves profiled will have the time of their profiled children propagated to them, but they will appear to bespontaneously invoked in the call graph listing, and will not have their time propagated further. Similarly, signal catchers, eventhough profiled, will appear to be spontaneous (although for more obscure reasons). Any profiled children of signal catchers shouldhave their times propagated properly, unless the signal catcher was invoked during the execution of the profiling routine, in whichcase all is lost.The profiled program must call "exit"(2) or return normally for the profiling information to be saved in the gmon.out file.
gprof -F ...