Gprof
   HOME

TheInfoList



OR:

Gprof is a performance analysis tool for
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and ot ...
applications. It used a hybrid of instrumentation and samplingSusan L. Graham, Peter B. Kessler, and Marshall K. Mckusick
''gprof: a Call Graph Execution Profiler''
// Proceedings of the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices, Vol. 17, No 6, pp. 120-126; doi: 10.1145/800230.806987
and was created as an extended version of the older "prof" tool. Unlike prof, gprof is capable of limited
call graph A call graph (also known as a call multigraph) is a control-flow graph, which represents calling relationships between subroutines in a computer program. Each node represents a procedure and each edge ''(f, g)'' indicates that procedure ''f'' cal ...
collecting and printing.


History

GPROF was originally written by a group led by Susan L. Graham at the
University of California, Berkeley The University of California, Berkeley (UC Berkeley, Berkeley, Cal, or California) is a public land-grant research university in Berkeley, California. Established in 1868 as the University of California, it is the state's first land-grant u ...
for
Berkeley Unix The Berkeley Software Distribution or Berkeley Standard Distribution (BSD) is a discontinued operating system based on Research Unix, developed and distributed by the Computer Systems Research Group (CSRG) at the University of California, Berk ...
(
4.2BSD The History of the Berkeley Software Distribution begins in the 1970s. 1BSD (PDP-11) The earliest distributions of Unix from Bell Labs in the 1970s included the source code to the operating system, allowing researchers at universities to modify a ...
). Another implementation was written as part of the
GNU project The GNU Project () is a free software, mass collaboration project announced by Richard Stallman on September 27, 1983. Its goal is to give computer users freedom and control in their use of their computers and computing devices by collaborati ...
for
GNU Binutils The GNU Binary Utilities, or , are a set of programming tools for creating and managing binary programs, object files, libraries, profile data, and assembly source code. Tools They were originally written by programmers at Cygnus Solutions. ...
in 1988 by Jay Fenlason.


Implementation

Instrumentation code is automatically inserted into the program code during compilation (for example, by using the '-pg' option of the gcc compiler), to gather caller-function data. A call to the monitor function 'mcount' is inserted before each function call.Justin Thiel
An Overview of Software Performance Analysis Tools and Techniques: From GProf to DTrace
(2006) "2.1.1 Overview of GProf"
Sampling data is saved in 'gmon.out' or in progname''.gmon' file just before the program exits, and can be analyzed with the 'gprof' command-line tool. Several gmon files can be combined with 'gprof -s' to accumulate data from several runs of a program. GPROF output consists of two parts: the flat profile and the call graph. The flat profile gives the total execution time spent in each function and its percentage of the total running time. Function call counts are also reported. Output is sorted by percentage, with hot spots at the top of the list. The second part of the output is the textual call graph, which shows for each function who called it (parent) and who it called (child subroutines). There is an external tool called gprof2dot capable of converting the call graph from gprof into graphical form.


Limitations and accuracy

At run-time, timing values are obtained by statistical sampling. Sampling is done by probing the target program's
program counter The program counter (PC), commonly called the instruction pointer (IP) in Intel x86 and Itanium microprocessors, and sometimes called the instruction address register (IAR), the instruction counter, or just part of the instruction sequencer, is ...
at regular intervals using
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
interrupt In digital computers, an interrupt (sometimes referred to as a trap) is a request for the processor to ''interrupt'' currently executing code (when permitted), so that the event can be processed in a timely manner. If the request is accepted, ...
s (programmed via profil(2) or setitimer(2)
syscall In computing, a system call (commonly abbreviated to syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, acc ...
s). The resulting data is not exact, rather a statistical approximation. The amount of error is usually more than one sampling period. If a value is n times the sampling period, the expected error in the value is the square root of n sampling periods.gprof Profiling Tools on BG/P Systems
, "Issues in Interpreting Profile Data", Argonne Leadership Computing Facility
A typical sampling period is 0.01 second (10 milliseconds) or 0.001 second (1 ms) or in other words 100 or 1000 samples per second of CPU running time. In some versions, such as BSD, profiling of shared libraries can be limited because of restrictions of the profil function, which may be implemented as library function or as system call. There were analogous utility in
glibc The GNU C Library, commonly known as glibc, is the GNU Project's implementation of the C standard library. Despite its name, it now also directly supports C++ (and, indirectly, other programming languages). It was started in the 1980s by ...
called 'sprof' to profile dynamic libraries. Gprof cannot measure time spent in kernel mode (syscalls, waiting for CPU or I/O waiting), and only user-space code is profiled. The mcount function may not be thread-safe in some implementations, so multi-threaded application profiles can be incorrect (typically it only profiles the main thread of application). Instrumentation overhead can be high (estimated as 30%-260%) for higher-order or object-oriented programs. Mutual recursion and non-trivial cycles are not resolvable by the gprof approach (context-insensitive call graph), because it only records arc traversal, not full call chains.Low-Overhead Call Path Profiling of Unmodified,Optimized Code
ACM 1-59593-167/8/06/2005 .
Gprof with call-graph collecting can be used only with compatible compilers, like GCC, clang/LLVM and some other.


Reception

In 2004 a GPROF paper appeared on the list of the 50 most influential
PLDI Programming Language Design and Implementation (PLDI) is one of the ACM SIGPLAN's most important conferences. The precursor of PLDI was the Symposium on Compiler Optimization, held July 27–28, 1970 at the University of Illinois at Urbana-Ch ...
papers of all time as one of four papers of 1982 year.20 Years of PLDI (1979–1999): A Selection, Kathryn S. McKinley, Editor
/ref> According to Thiel, "GPROF ... revolutionized the performance analysis field and quickly became the tool of choice for developers around the world ... the tool still maintains a large following ... the tool is still actively maintained and remains relevant in the modern world."


See also

*
List of performance analysis tools This is a list of performance analysis tools for use in software development. General purpose, language independent The following tools work based on log files that can be generated from various systems. * time (Unix) - can be used to determin ...
*
gcov Gcov is a source code coverage analysis and statement-by-statement profiling tool. Gcov generates exact counts of the number of times each statement in a program is executed and annotates source code to add instrumentation. Gcov comes as a stand ...


References

{{reflist, 33em


Further reading

* Susan L. Graham, Peter B. Kessler, and Marshall K. Mckusick
''gprof: a Call Graph Execution Profiler''
// Proceedings of the SIGPLAN '82 Symposium on Compiler Construction, SIGPLAN Notices, Vol. 17, No 6, pp. 120–126; doi: 10.1145/800230.806987 * Graham, S. L., Kessler, P. B. and McKusick, M. K. (1983), An execution profiler for modular programs. Softw: Pract. Exper., 13: 671–685. doi: 10.1002/spe.4380130803


External links

* Vinayak Hegd

Linux Gazette, 2004 * Martyn Honeyford

3 April 2006 // IBM DeveloperWorks, Technical library
GNU Gprof documentation
Profilers