kprof is a graphical tool that displays the execution profiling output generated by the gprof profiler. kprof presents the information in list or tree view, which makes the information easy to understand.
kprof has the following features:
- Flat profile view displays all functions and methods and their profiling information. (See Figure 1.22 for a view of this functionality.)
- Hierarchical profile view displays a tree for each function and method with the other functions and methods it calls as subelements. (See Figure 1.23 for a view of this functionality.)
- Graph view is a graphical representation of the call tree. It requires Graphviz to work. (See Figure 1.24 for a view of this functionality.)
- Right-clicking a function or method displays a pop-up with the list of callers and called functions. You can go to one of these functions directly by selecting it in the pop-up menu. (See Figure 1.22 for a view of this functionality.)
We’ve nstalled the kprof-1.4.2-196.i586.rpm that comes with the distribution. The following rpm command displays the version of the kprof application:
% rpm -qf /opt/kde3/bin/kprof kprof-1.4.2-196
Building Graphviz, the Graph Feature
kprof supports a graph feature, but before it can be used, the Graphviz program must be built. See the Graphviz URL in the section "Web Resources for Profiling" at the end of this chapter to download the source code for Graphviz.
The version of source code for Graphviz that will be built for this section is version 1.12. The tar file graphviz-1.12.tar.gz can be downloaded.
The next steps expand the source tree. Then, using the make and make install commands, the program is built and installed to the proper location on your system, as shown in Figure 1.20.
Figure 1.20 Building and installing Graphviz.
After Graphviz is installed, kprof uses it to create the Graph View that can be seen in Figure 1.24.
To use kprof, the -b option is needed. The following command uses gprof with the -b option on the sample3 program. gprof’s output is saved to the sample3.prof1 file:
% gprof -b sample3 >sample3.prof1
The next step is to start kprof:
Figure 1.21 The open dialog box.
After kprof loads, select File, Open to bring the sample3 gprof output into kprof. Figure 1.21 shows the open dialog box.
Figure 1.22 shows the flat profile view of the sample3 program. This screen shot also shows that function1 is called by function2, function3, and main.
Figure 1.22 The flat profile view.
Figure 1.23 shows the hierarchical profile view of the sample3 program.
Figure 1.23 The hierarchical profile view.
Figure 1.24 shows the graph view of the sample3 program. The graph view uses Graphviz. This view shows that function1 is called by main, function2, and function3. It also shows that function2 is called by main and function3 and that function3 is called only by main.
Figure 1.24 The graph view.