Using CProf mini-HOWTO

Sean Langley,


System Requirements

Cprof Setup

Using Wine with Cprof

Analyzing Cprof output

Further Information

1. Introduction

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.

2. System requirements

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:

  1. linux kernel supporting sendfile (tested with 2.2.13)
  2. glibc 2 (tested with 2.1.3)
  3. pthreads 0.8 (tested with 0.8)
  4. libelf (tested with 0.70)
  5. a C++ runtime (tested with libstdc++ 2.95.2)
  6. gcc supporting -finstrument-funtions (tested with gcc 2.95.2)

Building this software requires:

  1. all of the above
  2. C and C++ compilers (tested with gcc 2.95.2)
  3. GNU make (tested with 3.77)

Maintaining this software requires:

  1. all of the above
  2. automake (tested with 1.4)
  3. autoconf (tested with 2.13)
  4. 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.

Cprof Setup

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 in order for your install to work properly.
  1. automake
  2. aclocal
  3. autoconf
  4. ./configure [configure options]
  5. make
  6. su -c "make install && ldconfig"

You are now ready to start building your application with cprof support, and begin speeding up your applications.

Compiling Wine for Use with Cprof

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.

Analyzing Cprof output

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 >

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.

Further Information

The following is a list of usefull 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.

Sean Langley
Last modified: Wed Jul 5 11:41:31 EDT 2000
$Id: cprof.html,v 2003/09/23 19:33:22 emile Exp $