- "Profiling" redirects here. For the science of criminal psychological analysis, see offender profiling.
In software engineering, performance analysis (also known as dynamic program analysis) is the investigation of a program's behavior using information gathered as the program runs, as opposed to static code analysis. The usual goal of performance analysis is to determine which parts of a program to optimize for speed or memory usage.
A profiler is a performance analysis tool that measures the behavior of a program as it runs, particularly the frequency and duration of function calls. The output is a stream of recorded events (a trace) or a statistical summary of the events observed (a profile). Profilers use a wide variety of techniques to collect data, including hardware interrupts, code instrumentation, operating system hooks, and performance counters.
As the summation in a profile often is done related to the source code positions where the events happen, the size of measurement data is linear to the code size of the program. In contrast, the size of a trace is linear to the program's runtime, making it somewhat impractical. For sequential programs, a profile is usually enough, but performance problems in parallel programs (waiting for messages or synchronisation issues) often depend on the time relationship of events, thus requiring the full trace to get an understanding of the problem.
- Program analysis tools are extremely important for understanding program behavior. Computer architects need such tools to evaluate how well programs will perform on new architectures. Software writers need tools to analyze their programs and identify critical pieces of code. Compiler writers often use such tools to find out how well their instruction scheduling or branch prediction algorithm is performing... (ATOM, PLDI, '94)
History
Profiler-driven program analysis dates back to 1982, with the publication of Gprof: a Call Graph Execution Profiler [1]. The paper outlined a system which later became the GNU profiler, also known as gprof.
In 1994, Amitabh Srivastava and Alan Eustace of Digital Equipment Corporation published a paper describing ATOM [2]. ATOM is a platform for converting a program into its own profiler. That is, at compile time, it inserts code into the program to be analyzed. That inserted code outputs analysis data. This technique, modifying a program to analyze itself, is known as "instrumentation".
In 2004, both the Gprof and ATOM papers appeared on the list of the 20 most influental PLDI papers of all time. [3]
Methods of data gathering
Statistical profilers
Some profilers operate by sampling. A sampling profiler probes the target program's program counter at regular intervals using operating system interrupts. Sampling profiles are typically less accurate and specific, but allow the target program to run at near full speed.
Some profilers instrument the target program with additional instructions to collect the required information. Instrumenting the program can cause changes in the performance of the program, causing inaccurate results and heisenbugs. Instrumenting can potentially be very specific but slows down the target program as more specific information is collected.
The resulting data are not exact, but a statistical approximation. The actual amount of error is usually more than one sampling period. In fact, if a value is n times the sampling period, the expected error in it is the square-root of n sampling periods. [4]
Two of the most commonly used statistical profilers are GNU's gprof and SGI's Pixie.
Instrumentation
- Manual. Done by the programmer, e.g. by adding instructions to explicitly calculate runtimes.
- Compiler assisted. Example: "gcc -pg ..." for gprof.
- Binary translation; the tool adds instrumentation to a compiled binary. Example: ATOM
- Runtime instrumentation: Directly before execution the code is instrumented. The program run is fully supervised and controlled by the tool. Examples: PIN, Valgrind
- Runtime injection: More lightweight than runtime instrumentation. Code is modified at runtime to have jumps to helper functions. Example: DynInst
External links
- gprof The GNU Profiler, part of GNU Binutils (which are part of the GNU project); you can use some visualisation tools called VCG tools and combine both of them using Call Graph Drawing Interface (CGDI); a second solution is kprof. More for C/C++ but works well for other languages.
- FunctionCheck, @ sourceforge.net is a profiler that was created "because the well known profiler gprof have some limitations". using GCC -finstrument-functions option. kprof is a front-end. For C++/C.
- Valgrind is a GPL'd system for debugging and profiling x86-Linux programs. You can automatically detect many memory management and threading bugs. alleyoop is a front-end for valgrind. It works for any language and the assembler.
- VTune is Intel's family of commercial performance analyzers for Windows and Linux executables on Intel CPUs. It has command-line tools, a standalone environment and plugins for Microsoft Visual Studio and Eclipse.
- Shark is Apple's free performance analyzer for Macintosh executables.
- PurifyPlus is a commercial family of performance analysis tools from IBM's Rational unit. For Linux, UNIX and Windows.
- CodeAnalyst is AMD's free performance analyzer for Windows programs on AMD hardware. AMD also has a Linux version of CodeAnalyst.
- OProfile statistical, kernel based GPL profiler for Linux
- Profiler for use with Digital Mars C, C++ and D compilers.
- JRat Java Runtime Analysis Toolkit a LGPL profiler
- CLR Profiler is a free CLR profiler provided by Microsoft for CLR applications.
- Performance Analyzer included with Sun Studio (now free!)
- YourKit a profiler for Java and .NET framework.
- JProbe, a profiler by Quest Software that is now part of the JProbe suite which also includes tools such as a memory debugger.
- Article "Need for speed -- Eliminating performance bottlenecks" on doing execution time analysis of Java applications using IBM Rational Application Developer.
- Tutorial on the use of Oprofile