Profiling Your Application’s Performance

If you suspect that CPU usage may be causing performance bottlenecks, use the Call Attributed Profiler (CAP) tool, which is part of the Windows NT Server Resource Kit. This tool requires a special build of applications, but performs a detailed trace of every function call and how much time that call requires. It identifies frequently called functions that are slow and need to be optimized or called less often.

You can also use the CAP tool to parse the data into a Microsoft Excel readable format, and to identify calling functions and called functions.

Example: Using the CAP Tool to Eliminate Duplicated Calls

A Microsoft Exchange Client application often opens multiple folders, but its performance is slow and you can see it redraw every message in the folder. This performance bottleneck can be identified by CAP profiling

In this case, CAP profiling results indicate that the application is asking for time-zone information on every call. Because time zone information does not often change, this information can be requested once, then saved for the entire session. This reduces the time spent making multiple calls, reduces CPU time, and improves performance significantly.

    To use CAP profiling
  1. Copy CAP.DLL from the Windows NT Server Resource Kit to your system directory.
  2. Compile your application for profiling. See the Microsoft Visual C++ Manual for instructions.
  3. Make any necessary changes to the CAP.INI file. See Optimizing Windows NT or CAP.TXT of the Windows NT Server Resource Kit for general information on preparing CAP.INI. Use the following table to customize your copy of CAP.INI.

For more information, see CAP FLAGS in the Windows NT Server CAP.INI file.

Setting Up CAP.INI

Section in CAP.INI
Usage Notes
[EXES] List the CAP-ready .EXE files to profile. The profiler automatically starts when you launch one of these .EXE files.
[PATCH CALLERS] List the DLLs called by the file names (not compiled for CAP) into %SystemRoot%\SYMBOLS\DLL. For example, if you put KERNEL32.DLL in this section, copy KERNEL32.DBG to %SystemRoot%\SYMBOLS\DLL.

List DLLs built for profiling if you want to profile internal calls. Note that all exported functions in this DLL are listed twice.

[OUTPUT FILE] CAP output is directed to the file specified in the following line:
FILENAME=C:\CAP.END
 
[CAP FLAGS]
profile=off
perthreadmem=8388608
 

If you set the profile flag to off, profiling will default to OFF (otherwise the default is ON). In this case, profiling will only start manually by using CAPDUMP.EXE. If you don't need to profile immediately after startup, set profile to OFF. As a result, the .EXE file will start much faster.

Note that the perthreadmem parameter is required. It represents the amount of memory CAP allocates per thread to collect data. This parameter is expressed in bytes (for example, 8 MB). If you experience problems such as running out of memory, try changing this value.


    To start and run CAP profiling
  1. Start your .EXE files.
  2. Run CAPDUMP.EXE. For more information, see the Windows NT Server Resource Kit.
  3. In CAPDUMP, choose Clear and Restart, then choose OK to begin profiling.
  4. Run your test.
  5. In CAPDUMP, choose Stop, then choose OK.
  6. In CAPDUMP, choose Dump and Stop, then choose OK. CAP will start writing to disk.

Refer to the Windows NT Server Resource Kit for CAP data analysis tools.