Gprof Profiling via Binary Instrumentation


Home
Members
Methodology
Results
References
Contact Information

Introduction
 

Background
A programmer's goal is to write correct, efficient code. Code must initially be written with the goal of being correct. Once correctness has been established, programmers generally strive to make their code as efficient as possible. This project focuses on
creating more efficient code through the use of profiling tools. Execution profiling tools are a great asset to programmers creating efficient code. Profiling tools can give programmers insight into what functions are being called and how much time is spent in
each during a program's execution. This information can be used to identify bottlenecks in a program that may be a good candidate for reexamination to improve efficiency. One such tool in common use is Gprof.
 

Problem Statement
Currently, Gprof instruments source code at compile time and tracks what functions were called, how many times each function was called, how long was spent in each function, and a call graph (what function called the function in question). Profiling with Gprof
entails the following steps:
1. Compile your source code with the -pg option
2. Run your binary file (during this stage a gmon.out file will be generated containing profiling information)
3. Examine the profile information by running Gprof on the gmon.out file
The current framework that Gprof uses may be too restrictive for certain profiling activities. Gprof requires that the source code be recompiled with the -pg option specified in order for profiling instrumentation to take place. This can be too restrictive in the event that (1) only the binary is available (the source code is not accessible), (2) compilation time is prohibitively long, or (3) the programmer wishes to instrument dynamic libraries for profiling that the program calls during execution. We propose creating a tool for binary instrumentation of Gprof profiling.
 

Design
We set out to create a tool that inserts instrumentation for Gprof profiling into arbitrary binaries. Dyninst provided the means for adding additional code to an already compiled binary. We extracted the code used by the Gnu C Compiler when the -pg option was
specified and inserted it into arbitrary binaries. When source code compiled with the -pg is run, we discovered that “mcount” is called at the beginning of each function in the program. At the end of execution, the final call to mcount generates the gmon.out file that contains Gprof profiling data. In order to reproduce the gmon.out file for code compiled without the -pg option, we used Dyninst to insert calls to mcount at the beginning of each function. See the Methodology section for more information.


 


For problems or questions regarding this Web site contact [jsvarma@ncsu.edu]