Purpose

This tool mentor describes the use of the Rational PurifyPlus tools (Rational Purify, Rational PureCoverage, and Rational Quantify) to achieve code that is free of memory errors and leaks, uses memory efficiently, and provides optimum performance . This tool mentor is applicable for use both with Microsoft Windows systems and with UNIX systems.

The PurifyPlus tools include Rational Purify, Rational PureCoverage, and Rational Quantify.

To learn more about PurifyPlus tools, read the Getting Started manual for PurifyPlus (Windows version or UNIX version).

For step-by-step information about using PurifyPlus tools, see the online Help for the tool.

This section offer links to additional RUP information related to this tool mentor:


Overview

Analysis of runtime performance includes the following:

  • Detecting memory errors and leaks (C/C++ programs on Windows and UNIX).
    • Use Purify to pinpoint these problems, both in your own code and in the components your software uses, even when you don't have the source.
    • Use PureCoverage to ensure all code has been covered. (You can also use PureCoverage independently of Purify to collect coverage data for C/C++, Java, and .NET managed code.)
  • Profiling memory usage (Java and .NET managed code on Windows). Use Purify to show where you are using memory inefficiently.
  • Profiling performance (Windows and UNIX). Use Quantify to show where your program is spending the most time so that you can eliminate major performance bottlenecks.

Runtime analysis with PurifyPlus tools results in error-free code that runs at maximum efficiency.

Tool Steps

To perform runtime analysis using the PurifyPlus tools:

    1. Run your program under Purify to collect error, leak, and coverage data (C/C++ programs on Windows and UNIX)
    2. Run your program under Purify to detect inefficient memory usage (Java and .NET managed code on Windows)
    3. Run your program under Quantify to find performance bottlenecks (Windows and UNIX)

1. Run your program under Purify to collect error, leak, and coverage data (C/C++ programs on Windows and UNIX) 

Purify detects hard-to-find runtime errors, including memory leaks in your own code and in the components your software uses. It reports memory errors such as array bounds errors, access through dangling pointers, uninitialized memory reads, memory allocation errors, and memory leaks, so that you can resolve them before they do any damage. If you have Rational PureCoverage on your system, you can also see the parts of your code that you have, and have not, tested. 

Begin by running your program under Purify:

  • On a Windows system:
    • If you are working in Microsoft Visual Studio 6, first select the Visual Studio menu item Purify > Engage Purify Integration . If you have PureCoverage on your system, select Purify > Collect Coverage Data as well, instructing Purify to monitor code coverage. Then run your program in Visual Studio as usual.
    • If you are using Purify as a standalone program, not integrated with Visual Studio, select File > Run . In the Run Program dialog, select Collect error, leak, and coverage data (or Collect error and leak data if you do not have PureCoverage on your system) and run your program.
  • On a UNIX system, add the word purify to the beginning of your compile/link line. If you have PureCoverage on your system, add purecov as well. For example:
    % purify purecov cc -g hello_world.c
    Then run the program as usual.
As you exercise the program, Purify lists runtime errors in the Purify Viewer. When you exit the program, Purify reports memory leaks.

Scan the message headers to identify critical errors. Expand messages to see more detailed diagnostic information, including the code that generated the error. From the Viewer, you can open the source code in your editor, at the line where the error occurred, and make your correction directly.

After you correct errors and rebuild the program, verify your corrections by rerunning the updated program and comparing the new results to the previous run. Repeat the cycle of instrumenting and running, analyzing, and correcting until your program runs clean.

If you collected coverage data for the program runs, you can also see the parts of your code that you have not checked for errors. Use this information to adjust the scope of your runtime analysis so that you find all of the errors in your program, wherever they occur.

For more information, look up the following topics in the Purify online Help index:

  • running programs
  • Purify messages
  • source code
  • coverage data

2. Run your program under Purify to detect inefficient memory usage (Java and .NET managed code on Windows) 

Purify helps you identify Java and .NET managed code memory problems. Using Purify, you can determine:

  • how much memory your program is using
  • how much new memory your program consumes for a specific set of actions 
  • what methods and objects in your program are consuming so much memory 
  • which objects may be preventing unneeded objects from being garbage collected 
  • where it would be advisable to force a garbage collection to improve performance
Begin by running your program under Purify.
  • If you are working in Microsoft Visual Studio .NET, IBM WSWB, or IBM WSS AD, first select the menu item PurifyPlus > Purify > Engage Purify Integration . Then run your program as usual.
  • If you are using Purify as a standalone program, not integrated with Visual Studio .NET or WSWB/WSS AD, select File > Run in the Purify user interface. In the Run Program dialog, select Collect memory profiling data and run your program.
After your program has finished its initialization procedures, use the Purify snapshot command to benchmark memory usage at that moment. The snapshot is your basis for investigating how your program uses memory as it runs.   

Once you have the snapshot, you can capture a record of the memory your program uses as it runs. Execute the parts of the program that you suspect are leaking memory. Purify displays a memory allocation graph that shows real-time variations in current memory use. When you observe an increase in allocated memory, take another snapshot.

Compare the two snapshots to identify methods that may be leaking memory. Exit your program and compare (or "diff") the two snapshots. Purify displays a call graph showing the methods that are responsible for the largest amounts of memory allocated while your program was running, between the time you took the first and second snapshots. You can focus on specific methods within the call graph to investigate them more closely.

If the amount of memory allocated to a method is unexpectedly large, examine your source code and revise it, if necessary, to free memory when there is no longer a need for it.

Once you've identified methods that appear to have memory problems, analyze these methods at the object level. Look for objects that should be, but have not been, freed and garbage-collected, perhaps because other objects retain an unneeded reference to them. 

For more information, look up the following in the Purify online Help index: 

  • running programs
  • comparing runs
  • data browser

3. Run your program under Quantify to find performance bottlenecks (Windows and UNIX).

Quantify provides a complete, accurate, and easy-to-interpret set of performance data for your program and its components, so that you can identify and eliminate performance bottlenecks in your code.

Begin by running the program under Quantify to collect performance data:

  • On a Windows system:
    • If you are working in Microsoft Visual Studio 6, first select the Visual Studio menu item Quantify > Engage Quantify Integration . Then run your program in Visual Studio as usual.
    • If you are working in Microsoft Visual Studio .NET, IBM WSWB, or IBM WSS AD, select the menu item PurifyPlus > Quantify > Engage Quantify Integration . Then run your program in as usual.
    • If you are using Quantify as a standalone program, not integrated with Visual Studio or WSWB/WSS AD, select File > Run to run your program in the Quantify user interface.
  • On a UNIX system, add the word quantify to the beginning of your compile/link line. For example:
       % quantify cc -g hello_world.c
    Then run the program as usual.

As you exercise your code, Quantify records data about your program's performance and displays the activity of its threads and fibers. When you exit your program, Quantify has an accurate profile of its performance that you can use to find and diagnose bottlenecks.

The Quantify data display includes:

  • a Call Graph window that graphically depicts the calling structure and performance of the functions in the program
  • a sortable Function List window that lists all functions with performance data
  • a Function Detail window that displays data for a specific function, its callers, and its descendants
  • an Annotated Source window that shows line-by-line performance data on a copy of the source code

With the data you collect, you will be able to identify performance bottlenecks such as needless computations and recomputations, premature computations, or excessive and expensive library calls.

After you modify your code to eliminate or minimize the bottlenecks, rerun the updated program under Quantify. Then compare the new results to the previous run by creating a "diff" dataset, which gives clear indications of performance improvements and regressions.

For more information, look up the following topics in the Quantify online Help index:

  • running programs
  • comparing runs
  • call graph window
  • annotated source window


Rational Unified Process   2003.06.13