Blame gprof/README

Packit bbfece
		README for GPROF
Packit bbfece
Packit bbfece
This is the GNU profiler.  It is distributed with other "binary
Packit bbfece
utilities" which should be in ../binutils.  See ../binutils/README for
Packit bbfece
more general notes, including where to send bug reports.
Packit bbfece
Packit bbfece
This file documents the changes and new features available with this
Packit bbfece
version of GNU gprof.
Packit bbfece
Packit bbfece
* New Features
Packit bbfece
Packit bbfece
 o Long options
Packit bbfece
Packit bbfece
 o Supports generalized file format, without breaking backward compatibility:
Packit bbfece
   new file format supports basic-block execution counts and non-realtime
Packit bbfece
   histograms (see below)
Packit bbfece
Packit bbfece
 o Supports profiling at the line level: flat profiles, call-graph profiles,
Packit bbfece
   and execution-counts can all be displayed at a level that identifies
Packit bbfece
   individual lines rather than just functions
Packit bbfece
Packit bbfece
 o Test-coverage support (similar to Sun tcov program): source files
Packit bbfece
   can be annotated with the number of times a function was invoked
Packit bbfece
   or with the number of times each basic-block in a function was
Packit bbfece
   executed
Packit bbfece
Packit bbfece
 o Generalized histograms: not just execution-time, but arbitrary
Packit bbfece
   histograms are support (for example, performance counter based
Packit bbfece
   profiles)
Packit bbfece
Packit bbfece
 o Powerful mechanism to select data to be included/excluded from
Packit bbfece
   analysis and/or output
Packit bbfece
Packit bbfece
 o Support for DEC OSF/1 v3.0
Packit bbfece
Packit bbfece
 o Full cross-platform profiling support: gprof uses BFD to support
Packit bbfece
   arbitrary, non-native object file formats and non-native byte-orders
Packit bbfece
   (this feature has not been tested yet)
Packit bbfece
Packit bbfece
 o In the call-graph function index, static function names are now
Packit bbfece
   printed together with the filename in which the function was defined
Packit bbfece
   (required bfd_find_nearest_line() support and symbolic debugging
Packit bbfece
    information to be present in the executable file)
Packit bbfece
Packit bbfece
 o Major overhaul of source code (compiles cleanly with -Wall, etc.)
Packit bbfece
Packit bbfece
* Supported Platforms
Packit bbfece
Packit bbfece
The current version is known to work on:
Packit bbfece
Packit bbfece
 o DEC OSF/1 v3.0
Packit bbfece
	All features supported.
Packit bbfece
Packit bbfece
 o SunOS 4.1.x
Packit bbfece
	All features supported.
Packit bbfece
Packit bbfece
 o Solaris 2.3
Packit bbfece
	Line-level profiling unsupported because bfd_find_nearest_line()
Packit bbfece
	is not fully implemented for Elf binaries.
Packit bbfece
Packit bbfece
 o HP-UX 9.01
Packit bbfece
	Line-level profiling unsupported because bfd_find_nearest_line()
Packit bbfece
	is not fully implemented for SOM binaries.
Packit bbfece
Packit bbfece
* Detailed Description
Packit bbfece
Packit bbfece
** User Interface Changes
Packit bbfece
Packit bbfece
The command-line interface is backwards compatible with earlier
Packit bbfece
versions of GNU gprof and Berkeley gprof.  The only exception is
Packit bbfece
the option to delete arcs from the call graph.  The old syntax
Packit bbfece
was:
Packit bbfece
Packit bbfece
	-k fromname toname
Packit bbfece
Packit bbfece
while the new syntax is:
Packit bbfece
Packit bbfece
	-k fromname/toname
Packit bbfece
Packit bbfece
This change was necessary to be compatible with long-option parsing.
Packit bbfece
Also, "fromname" and "toname" can now be arbitrary symspecs rather
Packit bbfece
than just function names (see below for an explanation of symspecs).
Packit bbfece
For example, option "-k gprof.c/" suppresses all arcs due to calls out
Packit bbfece
of file "gprof.c".
Packit bbfece
Packit bbfece
*** Sym Specs
Packit bbfece
Packit bbfece
It is often necessary to apply gprof only to specific parts of a
Packit bbfece
program.  GNU gprof has a simple but powerful mechanism to achieve
Packit bbfece
this.  So called {\em symspecs\/} provide the foundation for this
Packit bbfece
mechanism.  A symspec selects the parts of a profiled program to which
Packit bbfece
an operation should be applied to.  The syntax of a symspec is
Packit bbfece
simple:
Packit bbfece
Packit bbfece
	  filename_containing_a_dot
Packit bbfece
	| funcname_not_containing_a_dot
Packit bbfece
	| linenumber
Packit bbfece
	| ( [ any_filename ] `:' ( any_funcname | linenumber ) )
Packit bbfece
Packit bbfece
Here are some examples:
Packit bbfece
Packit bbfece
	main.c			Selects everything in file "main.c"---the
Packit bbfece
				dot in the string tells gprof to interpret
Packit bbfece
				the string as a filename, rather than as
Packit bbfece
				a function name.  To select a file whose
Packit bbfece
				name does contain a dot, a trailing colon
Packit bbfece
				should be specified.  For example, "odd:" is
Packit bbfece
				interpreted as the file named "odd".
Packit bbfece
Packit bbfece
	main			Selects all functions named "main".  Notice
Packit bbfece
				that there may be multiple instances of the
Packit bbfece
				same function name because some of the
Packit bbfece
				definitions may be local (i.e., static).
Packit bbfece
				Unless a function name is unique in a program,
Packit bbfece
				you must use the colon notation explained
Packit bbfece
				below to specify a function from a specific
Packit bbfece
				source file.  Sometimes, functionnames contain
Packit bbfece
				dots.  In such cases, it is necessary to
Packit bbfece
				add a leading colon to the name.  For example,
Packit bbfece
				":.mul" selects function ".mul".
Packit bbfece
Packit bbfece
	main.c:main		Selects function "main" in file "main.c".
Packit bbfece
Packit bbfece
	main.c:134		Selects line 134 in file "main.c".
Packit bbfece
Packit bbfece
IMPLEMENTATION NOTE: The source code uses the type sym_id for symspecs.
Packit bbfece
At some point, this probably ought to be changed to "sym_spec" to make
Packit bbfece
reading the code easier.
Packit bbfece
Packit bbfece
*** Long options
Packit bbfece
Packit bbfece
GNU gprof now supports long options.  The following is a list of all
Packit bbfece
supported options.  Options that are listed without description
Packit bbfece
operate in the same manner as the corresponding option in older
Packit bbfece
versions of gprof.
Packit bbfece
Packit bbfece
Short Form:	Long Form:
Packit bbfece
-----------	----------
Packit bbfece
-l		--line
Packit bbfece
			Request profiling at the line-level rather
Packit bbfece
			than just at the function level.  Source
Packit bbfece
			lines are identified by symbols of the form:
Packit bbfece
Packit bbfece
				func (file:line)
Packit bbfece
Packit bbfece
			where "func" is the function name, "file" is the
Packit bbfece
			file name and "line" is the line-number that
Packit bbfece
			corresponds to the line.
Packit bbfece
Packit bbfece
			To work properly, the binary must contain symbolic
Packit bbfece
			debugging information.  This means that the source
Packit bbfece
			have to be translated with option "-g" specified.
Packit bbfece
			Functions for which there is no symbolic debugging
Packit bbfece
			information available are treated as if "--line"
Packit bbfece
			had not been specified.  However, the line number
Packit bbfece
			printed with such symbols is usually incorrect
Packit bbfece
			and should be ignored.
Packit bbfece
Packit bbfece
-a		--no-static
Packit bbfece
-A[symspec]	--annotated-source[=symspec]
Packit bbfece
			Request output in the form of annotated source
Packit bbfece
			files.  If "symspec" is specified, print output only
Packit bbfece
			for symbols selected by "symspec".  If the option
Packit bbfece
			is specified multiple times, annotated output is
Packit bbfece
			generated for the union of all symspecs.
Packit bbfece
Packit bbfece
			Examples:
Packit bbfece
Packit bbfece
			  -A		Prints annotated source for all
Packit bbfece
					source files.
Packit bbfece
			  -Agprof.c	Prints annotated source for file
Packit bbfece
					gprof.c.
Packit bbfece
			  -Afoobar	Prints annotated source for files
Packit bbfece
					containing a function named "foobar".
Packit bbfece
					The entire file will be printed, but
Packit bbfece
					only the function itself will be
Packit bbfece
					annotated with profile data.
Packit bbfece
Packit bbfece
-J[symspec]	--no-annotated-source[=symspec]
Packit bbfece
			Suppress annotated source output.  If specified
Packit bbfece
			without argument, annotated output is suppressed
Packit bbfece
			completely.  With an argument, annotated output
Packit bbfece
			is suppressed only for the symbols selected by
Packit bbfece
			"symspec".  If the option is specified multiple
Packit bbfece
			times, annotated output is suppressed for the
Packit bbfece
			union of all symspecs.  This option has lower
Packit bbfece
			precedence than --annotated-source
Packit bbfece
Packit bbfece
-p[symspec]	--flat-profile[=symspec]
Packit bbfece
			Request output in the form of a flat profile
Packit bbfece
			(unless any other output-style option is specified,
Packit bbfece
			 this option is turned on by default).  If
Packit bbfece
			"symspec" is specified, include only symbols
Packit bbfece
			selected by "symspec" in flat profile.  If the
Packit bbfece
			option is specified multiple times, the flat
Packit bbfece
			profile includes symbols selected by the union
Packit bbfece
			of all symspecs.
Packit bbfece
Packit bbfece
-P[symspec]	--no-flat-profile[=symspec]
Packit bbfece
			Suppress output in the flat profile.  If given
Packit bbfece
			without an argument, the flat profile is suppressed
Packit bbfece
			completely.  If "symspec" is specified, suppress
Packit bbfece
			the selected symbols in the flat profile.  If the
Packit bbfece
			option is specified multiple times, the union of
Packit bbfece
			the selected symbols is suppressed.  This option
Packit bbfece
			has lower precedence than --flat-profile.
Packit bbfece
Packit bbfece
-q[symspec]	--graph[=symspec]
Packit bbfece
			Request output in the form of a call-graph
Packit bbfece
			(unless any other output-style option is specified,
Packit bbfece
			 this option is turned on by default).  If "symspec"
Packit bbfece
			is specified, include only symbols selected by
Packit bbfece
			"symspec" in the call-graph.  If the option is
Packit bbfece
			specified multiple times, the call-graph includes
Packit bbfece
			symbols selected by the union of all symspecs.
Packit bbfece
Packit bbfece
-Q[symspec]	--no-graph[=symspec]
Packit bbfece
			Suppress output in the call-graph.  If given without
Packit bbfece
			an argument, the call-graph is suppressed completely.
Packit bbfece
			With a "symspec", suppress the selected symbols
Packit bbfece
			from the call-graph.  If the option is specified
Packit bbfece
			multiple times, the union of the selected symbols
Packit bbfece
			is suppressed.  This option has lower precedence
Packit bbfece
			than --graph.
Packit bbfece
Packit bbfece
-C[symspec]	--exec-counts[=symspec]
Packit bbfece
			Request output in the form of execution counts.
Packit bbfece
			If "symspec" is present, include only symbols
Packit bbfece
			selected by "symspec" in the execution count
Packit bbfece
			listing.  If the option is specified multiple
Packit bbfece
			times, the execution count listing includes
Packit bbfece
			symbols selected by the union of all symspecs.
Packit bbfece
Packit bbfece
-Z[symspec]	--no-exec-counts[=symspec]
Packit bbfece
			Suppress output in the execution count listing.
Packit bbfece
			If given without an argument, the listing is
Packit bbfece
			suppressed completely.  With a "symspec", suppress
Packit bbfece
			the selected symbols from the call-graph.  If the
Packit bbfece
			option is specified multiple times, the union of
Packit bbfece
			the selected symbols is suppressed.  This option
Packit bbfece
			has lower precedence than --exec-counts.
Packit bbfece
Packit bbfece
-i		--file-info
Packit bbfece
			Print information about the profile files that
Packit bbfece
			are read.  The information consists of the
Packit bbfece
			number and types of records present in the
Packit bbfece
			profile file.  Currently, a profile file can
Packit bbfece
			contain any number and any combination of histogram,
Packit bbfece
			call-graph, or basic-block count records.
Packit bbfece
Packit bbfece
-s		--sum
Packit bbfece
Packit bbfece
-x		--all-lines
Packit bbfece
			This option affects annotated source output only.
Packit bbfece
			By default, only the lines at the beginning of
Packit bbfece
			a basic-block are annotated.  If this option is
Packit bbfece
			specified, every line in a basic-block is annotated
Packit bbfece
			by repeating the annotation for the first line.
Packit bbfece
			This option is identical to tcov's "-a".
Packit bbfece
Packit bbfece
-I dirs		--directory-path=dirs
Packit bbfece
			This option affects annotated source output only.
Packit bbfece
			Specifies the list of directories to be searched
Packit bbfece
			for source files.  The argument "dirs" is a colon
Packit bbfece
			separated list of directories.  By default, gprof
Packit bbfece
			searches for source files relative to the current
Packit bbfece
			working directory only.
Packit bbfece
Packit bbfece
-z		--display-unused-functions
Packit bbfece
Packit bbfece
-m num		--min-count=num
Packit bbfece
			This option affects annotated source and execution
Packit bbfece
			count output only.  Symbols that are executed
Packit bbfece
			less than "num" times are suppressed.  For annotated
Packit bbfece
			source output, suppressed symbols are marked
Packit bbfece
			by five hash-marks (#####).  In an execution count
Packit bbfece
			output, suppressed symbols do not appear at all.
Packit bbfece
Packit bbfece
-L		--print-path
Packit bbfece
			Normally, source filenames are printed with the path
Packit bbfece
			component suppressed.  With this option, gprof
Packit bbfece
			can be forced to print the full pathname of
Packit bbfece
			source filenames.  The full pathname is determined
Packit bbfece
			from symbolic debugging information in the image file
Packit bbfece
			and is relative to the directory in which the compiler
Packit bbfece
			was invoked.
Packit bbfece
Packit bbfece
-y		--separate-files
Packit bbfece
			This option affects annotated source output only.
Packit bbfece
			Normally, gprof prints annotated source files
Packit bbfece
			to standard-output.  If this option is specified,
Packit bbfece
			annotated source for a file named "path/filename"
Packit bbfece
			is generated in the file "filename-ann".  That is,
Packit bbfece
			annotated output is {\em always\/} generated in
Packit bbfece
			gprof's current working directory.  Care has to
Packit bbfece
			be taken if a program consists of files that have
Packit bbfece
			identical filenames, but distinct paths.
Packit bbfece
Packit bbfece
-c		--static-call-graph
Packit bbfece
Packit bbfece
-t num		--table-length=num
Packit bbfece
			This option affects annotated source output only.
Packit bbfece
			After annotating a source file, gprof generates
Packit bbfece
			an execution count summary consisting of a table
Packit bbfece
			of lines with the top execution counts.  By
Packit bbfece
			default, this table is ten entries long.
Packit bbfece
			This option can be used to change the table length
Packit bbfece
			or, by specifying an argument value of 0, it can be
Packit bbfece
			suppressed completely.
Packit bbfece
Packit bbfece
-n symspec	--time=symspec
Packit bbfece
			Only symbols selected by "symspec" are considered
Packit bbfece
			in total and percentage time computations.
Packit bbfece
			However, this option does not affect percentage time
Packit bbfece
			computation for the flat profile.
Packit bbfece
			If the option is specified multiple times, the union
Packit bbfece
			of all selected symbols is used in time computations.
Packit bbfece
Packit bbfece
-N		--no-time=symspec
Packit bbfece
			Exclude the symbols selected by "symspec" from
Packit bbfece
			total and percentage time computations.
Packit bbfece
			However, this option does not affect percentage time
Packit bbfece
			computation for the flat profile.
Packit bbfece
			This option is ignored if any --time options are
Packit bbfece
			specified.
Packit bbfece
Packit bbfece
-w num		--width=num
Packit bbfece
			Sets the output line width.  Currently, this option
Packit bbfece
			affects the printing of the call-graph function index
Packit bbfece
			only.
Packit bbfece
Packit bbfece
-e		<no long form---for backwards compatibility only>
Packit bbfece
-E		<no long form---for backwards compatibility only>
Packit bbfece
-f		<no long form---for backwards compatibility only>
Packit bbfece
-F		<no long form---for backwards compatibility only>
Packit bbfece
-k		<no long form---for backwards compatibility only>
Packit bbfece
-b		--brief
Packit bbfece
-dnum		--debug[=num]
Packit bbfece
Packit bbfece
-h		--help
Packit bbfece
			Prints a usage message.
Packit bbfece
Packit bbfece
-O name		--file-format=name
Packit bbfece
			Selects the format of the profile data files.
Packit bbfece
			Recognized formats are "auto", "bsd", "magic",
Packit bbfece
			and "prof".  The last one is not yet supported.
Packit bbfece
			Format "auto" attempts to detect the file format
Packit bbfece
			automatically (this is the default behavior).
Packit bbfece
			It attempts to read the profile data files as
Packit bbfece
			"magic" files and if this fails, falls back to
Packit bbfece
			the "bsd" format.  "bsd" forces gprof to read
Packit bbfece
			the data files in the BSD format.  "magic" forces
Packit bbfece
			gprof to read the data files in the "magic" format.
Packit bbfece
Packit bbfece
-T		--traditional
Packit bbfece
-v		--version
Packit bbfece
Packit bbfece
** File Format Changes
Packit bbfece
Packit bbfece
The old BSD-derived format used for profile data does not contain a
Packit bbfece
magic cookie that allows to check whether a data file really is a
Packit bbfece
gprof file.  Furthermore, it does not provide a version number, thus
Packit bbfece
rendering changes to the file format almost impossible.  GNU gprof
Packit bbfece
uses a new file format that provides these features.  For backward
Packit bbfece
compatibility, GNU gprof continues to support the old BSD-derived
Packit bbfece
format, but not all features are supported with it.  For example,
Packit bbfece
basic-block execution counts cannot be accommodated by the old file
Packit bbfece
format.
Packit bbfece
Packit bbfece
The new file format is defined in header file \file{gmon_out.h}.  It
Packit bbfece
consists of a header containing the magic cookie and a version number,
Packit bbfece
as well as some spare bytes available for future extensions.  All data
Packit bbfece
in a profile data file is in the native format of the host on which
Packit bbfece
the profile was collected.  GNU gprof adapts automatically to the
Packit bbfece
byte-order in use.
Packit bbfece
Packit bbfece
In the new file format, the header is followed by a sequence of
Packit bbfece
records.  Currently, there are three different record types: histogram
Packit bbfece
records, call-graph arc records, and basic-block execution count
Packit bbfece
records.  Each file can contain any number of each record type.  When
Packit bbfece
reading a file, GNU gprof will ensure records of the same type are
Packit bbfece
compatible with each other and compute the union of all records.  For
Packit bbfece
example, for basic-block execution counts, the union is simply the sum
Packit bbfece
of all execution counts for each basic-block.
Packit bbfece
Packit bbfece
*** Histogram Records
Packit bbfece
Packit bbfece
Histogram records consist of a header that is followed by an array of
Packit bbfece
bins.  The header contains the text-segment range that the histogram
Packit bbfece
spans, the size of the histogram in bytes (unlike in the old BSD
Packit bbfece
format, this does not include the size of the header), the rate of the
Packit bbfece
profiling clock, and the physical dimension that the bin counts
Packit bbfece
represent after being scaled by the profiling clock rate.  The
Packit bbfece
physical dimension is specified in two parts: a long name of up to 15
Packit bbfece
characters and a single character abbreviation.  For example, a
Packit bbfece
histogram representing real-time would specify the long name as
Packit bbfece
"seconds" and the abbreviation as "s".  This feature is useful for
Packit bbfece
architectures that support performance monitor hardware (which,
Packit bbfece
fortunately, is becoming increasingly common).  For example, under DEC
Packit bbfece
OSF/1, the "uprofile" command can be used to produce a histogram of,
Packit bbfece
say, instruction cache misses.  In this case, the dimension in the
Packit bbfece
histogram header could be set to "i-cache misses" and the abbreviation
Packit bbfece
could be set to "1" (because it is simply a count, not a physical
Packit bbfece
dimension).  Also, the profiling rate would have to be set to 1 in
Packit bbfece
this case.
Packit bbfece
Packit bbfece
Histogram bins are 16-bit numbers and each bin represent an equal
Packit bbfece
amount of text-space.  For example, if the text-segment is one
Packit bbfece
thousand bytes long and if there are ten bins in the histogram, each
Packit bbfece
bin represents one hundred bytes.
Packit bbfece
Packit bbfece
Packit bbfece
*** Call-Graph Records
Packit bbfece
Packit bbfece
Call-graph records have a format that is identical to the one used in
Packit bbfece
the BSD-derived file format.  It consists of an arc in the call graph
Packit bbfece
and a count indicating the number of times the arc was traversed
Packit bbfece
during program execution.  Arcs are specified by a pair of addresses:
Packit bbfece
the first must be within caller's function and the second must be
Packit bbfece
within the callee's function.  When performing profiling at the
Packit bbfece
function level, these addresses can point anywhere within the
Packit bbfece
respective function.  However, when profiling at the line-level, it is
Packit bbfece
better if the addresses are as close to the call-site/entry-point as
Packit bbfece
possible.  This will ensure that the line-level call-graph is able to
Packit bbfece
identify exactly which line of source code performed calls to a
Packit bbfece
function.
Packit bbfece
Packit bbfece
*** Basic-Block Execution Count Records
Packit bbfece
Packit bbfece
Basic-block execution count records consist of a header followed by a
Packit bbfece
sequence of address/count pairs.  The header simply specifies the
Packit bbfece
length of the sequence.  In an address/count pair, the address
Packit bbfece
identifies a basic-block and the count specifies the number of times
Packit bbfece
that basic-block was executed.  Any address within the basic-address can
Packit bbfece
be used.
Packit bbfece
Packit bbfece
IMPLEMENTATION NOTE: gcc -a can be used to instrument a program to
Packit bbfece
record basic-block execution counts.  However, the __bb_exit_func()
Packit bbfece
that is currently present in libgcc2.c does not generate a gmon.out
Packit bbfece
file in a suitable format.  This should be fixed for future releases
Packit bbfece
of gcc.  In the meantime, contact davidm@cs.arizona.edu for a version
Packit bbfece
of __bb_exit_func() to is appropriate.
Packit bbfece

Packit bbfece
Copyright (C) 2012-2018 Free Software Foundation, Inc.
Packit bbfece
Packit bbfece
Copying and distribution of this file, with or without modification,
Packit bbfece
are permitted in any medium without royalty provided the copyright
Packit bbfece
notice and this notice are preserved.