Cprof is a multi-threaded profile for applications written in the C programming language. This document explains how to use Cprof to improve performance of your application.
Editor's Note: This document is provided for reference and has not been edited by Sine Nomine Associates except for formatting and for correction of minor typographical errors. It is generically applicable to the CProf software and does not contain specific instructions with regard to the S/390 port.
Author: Sean Langley, seanl@Corel.ca
- System Requirements
- Cprof Setup
- Using WINE with Cprof
- Analyzing Cprof output
- Further Information
In attempting to optimize and speed up our WINE applications, we ran into a relatively large problem. There is a very large hole in the open source tools community with respect to multi-threaded profiler support. So we employed one of our co-operative education students to write one for us. Cprof is the result of this effort.
This document leads you through the steps required to build cprof, and use it with your applications, including your winelib and wine loader applications.
The following is a list of system requirements. Cprof can be built, maintained and used on a stock Debian GNU/Linux 2.2 (Potato) system. It will not work with version 1.0 or 1.1 of CorelLINUX as they are glibc 2.0 based. It will work on CorelLINUX 1.2 if you install all of the required packages.
Running this software requires:
- linux kernel supporting sendfile (tested with 2.2.13)
- glibc 2 (tested with 2.1.3)
- pthreads 0.8 (tested with 0.8)
- libelf (tested with 0.70)
- a C++ runtime (tested with libstdc++ 2.95.2)
- gcc supporting -finstrument-funtions (tested with gcc 2.95.2)
Building this software requires:
- all of the above
- C and C++ compilers (tested with gcc 2.95.2)
- GNU make (tested with 3.77)
Maintaining this software requires:
- all of the above
- automake (tested with 1.4)
- autoconf (tested with 2.13)
- libtool (tested with 1.3.3)
Note: Corel Linux 1.2 includes older versions of most of these packages and will require upgrading. You can get binary packages by pointing Corel Update to the Debian potato release.
You may receive Cprof in a number of forms. However regardless of the form (tarball, CVS, etc.) You must run the following commands in order from the root of your cprof source folder. If you are build cprof for use with WINE, you must add the configure option --with-wine=/path/to/root/of/WINE/tree/CorelWINE. Please note that the default install location is /usr/local/lib. This path must be in your ld.so.conf in order for your install to work properly.
- ./configure [configure options]
- su -c "make install && ldconfig"
You are now ready to start building your application with cprof support, and begin speeding up your applications.
There are a few changes to WINE which are required in order to use Cprof. If you are using CorelWINE, you can do a ./configure (or ./Corel-configure if that is how you normally invoke configure) with the command line options --enable-cprof and --disable-dll. eg. ./configure --enable-cprof --disable-dll
If you are not using the CorelWINE tree, you must apply the wine-support-for-cprof.diff patch to your WINE tree. This patch contains the necessary support for cprof. Now you must run ./configure --disable-dll from the root or your WINE tree.
After you have run configure (in either configuration method), you can make and install your WINE normally.
The first step to analyzing the output of your code is to actually run the code. So run the application you just built for cprof. When you exit, you should see a file called cmon.out in the current directory. This file contains all the timing and call stack information. In order to use this information, you must pass it through cprof, a program which takes the cmon.out file, as well as the original application as parameters, and gives you timing information.
eg. if you just ran your WINE loader application from the CorelWINE folder, you would execute the following command
cprof wine cmon.out > wine.profiled.prof
This would output a text file called wine.profiled.out which contains summary information sorted by function and children time.
There are a number of options you can pass to cprof. Most notably are the --calltrace and --sort=STYLE where style is one of f, fc, or c (function, function+children, calls to function ). --calltrace outputs a full calltrace for every function call made during the execution of your application. This results in a lot of data. The --sort=STYLE option allows you to sort the summary data based on the parameters above. You will probably get the most use out of the function + children time sort style.
The following is a list of useful links regarding code optimization:
Delphi Optimization An in depth look at optimization guidelines
gprof manual The gprof manual. Gprof is what cprof is conceptually based off of.
Tau. An excellent set of cross platform profiling tools which unfortunately require changes to your code for instrumentation
Taking Extreme Advantage of PowerPC An excellent read on code profiling and optimization. A little bit PowerPC specific, but the concepts are there.