Skip to main content

Bad software quality: Using IBM Rational PurifyPlus to avoid development problems

Aaron Lloyd (rust@us.ibm.com), New Techologies Evangelist, IBM, Software Group
Aaron (Rusty) Lloyd knows how to handle a broadsword as well as he handles technology. He is currently the New Technologies Evangelist for the Rational Developer Domain.

Summary:  This article focuses on defining what the term quality means to a software professional and why it's so crucial to developing persistent software. A walk-through example is used to illustrate PurifyPlus' Visual Trace capabilities within IBM Rational Rose XDE Developer Plus.

Date:  21 Jul 2004
Level:  Introductory
Activity:  415 views

I'm Rusty Lloyd, and during the day, I focus on evangelizing new technologies for IBM® Rational®. I'd like to welcome you to another one of my articles on developerWorks®: Rational's portal for developer news and product education. My articles explore various Rational technologies, particularly focusing on new products and updates to existing products, as well as how you, the developer, can utilize them in your software development efforts.

My earlier article discussed how RAD, or Rapid Application Development, is a key paradigm to invest in when doing software development.

This article will focus on one of the key barriers to proper software development: poor quality. That's right, this article will deal with quality as it relates to software. First, it will define what the term "quality" actually means to a software professional (to make sure that we're all on the same page) and why it is essential to developing useful and persistent software. Then we'll focus on one of our most popular offerings in this arena -- PurifyPlus. We will take an in-depth look at Purify®, one of the three tools that make up PurifyPlus, and focus on PurifyPlus' Visual Trace capabilities within Rose XDE Developer Plus with a small walk-through example. I'm confident that by the end of this article, you will be adding Purify and Visual Trace to the list of tools you use in your software development environment.

Welcome to the world of quality software development

In the previous paragraph, I mentioned the word quality. Rather than bore you with a textbook definition, the one thing I will explore is the fact that while quality is essential to producing good, persistent software -- it is one of the most misused words I have ever heard in a software development workplace.

Really, how many times have you heard a manager or a PM detail at length how they will "make sure that Quality comes first," only to see that the QA/Quality part of the schedule is the first to go when dates invariably slip? It is really simple, folks: without good code -- your program will not sell, and if it does, it will not last long in today's cutthroat marketplace. Period.

Let's take a look at a few more scenarios where the word "quality" is looked at as an afterthought.

Have you ever been in the situation in which a specific team has to take the finished code that everyone has worked on and go through it to make sure there are no glaring errors, particularly those that will crash the system, because one of the developers, in a rush to get to the feature-complete deadline, forgot to delete the new objects they created after they were finished using them?

Or maybe you've been in a certain predicament where one of your development staff put in some code long ago which they kept meaning to "remove" because it was old and outdated, and now they're onto the latest and greatest feature set, and that "old beat-up" code is still responsible for a lot of your decision processing? Or, even worse -- they didn't remove it because they wrote a new "improved" set of routines, which of course work well, except for the forgotten call to the old routines, which they forgot to remove after unit testing? So instead of only calling the new code, any program access calls both the new and the old code?

Sound familiar? Yes? No? In any case -- let's take a look at an Rational tool that can help you get through all of these trouble spots, and make sure that no matter what, you are always producing quality code when you're writing software.


Introducing Purify

One of the ways that you can insure quality is to utilize a program that goes through the code that you create and shows you all of the memory leaks that are occurring, as well as the paths through the code that your logic is taking as the code executes. This gives you rather complete coverage of your code, and helps you focus your time on the more difficult aspects of the software you're working on; algorithm's and the like.

In case you haven't guessed at this point (and not seen the heading of this section), I'm talking about IBM® Rational® Purify®. Purify is the tool within PurifyPlus that analyzes your code at runtime and packages the following functions as a set of essential tasks:

  • Memory leak and corruption checks -- find hard to catch errors in your code
  • Code instrumentation -- assists in code analysis; no re-compilation needed
  • Performance profiling -- helps in finding bottlenecks in your code
  • Code coverage -- insures that all of your code is tested properly

You can use Purify on a variety of components, such as .dll files, embedded components, Microsoft Plug-ins, and even COM enabled applications (using OLE and Active X controls.) Purify can also check Windows API functions and validate memory handles.

Purify works with any of the major programming languages -- from C/C++ to Java, .NET and also VB6. It can be run either in standalone mode or through any of a variety of IDEs, such as WebSphere Studio, VS .NET, Visual Studio 6, and Eclipse. This means that it also runs within both flavors Rose XDE Developer Plus, allowing for a seamless, integrated interface for both creating and testing your code. In addition, it also integrates with other Rational products, such as IBM® Rational® ClearQuest®.

Of course, an article such as this would not be complete without a walk-through of some of the features of Purify, now would it? Since we need to make sure that you really do understand what I mean when I discuss these concepts, I'll be detailing a couple of tips and tricks about Purify and Visual Trace program within XDE Developer Plus that you can use when analyzing your own code. As before, if you don't have a copy of PurifyPlus, a trial copy can be downloaded -- allowing you to follow along if you wish. Traversing the links on the left hand side of the IBM developerWorks Web pages will take you to more product information, such as literature (documentation) and technical support.


Starting up Purify and viewing its easy-to-use interface

Whether standalone or through an IDE (Figures 1 and 2), all the programs within PurifyPlus have an intuitive interface which makes it very easy to immediately start analyzing and improving your code. From program startup, you can select the Purify tool, activate its run command and have it automatically instrument and check your code for leaks and errors. While other program analysis tools sometimes take you though lots of menus and checks before analysis begins, Purify lets you dive right into program analysis from the very beginning.

Running IBM Rational Purify standalone
Figure 1: Running IBM Rational Purify standalone
Purify nestled comfortably within Rose XDE Developer Plus
Figure 2: Purify nestled comfortably within Rose XDE Developer Plus
(click here to enlarge)

Analyzing program code with IBM Rational Purify

Code coverage and leak detection with Microsoft's C++ Scribble program

In the first part of this article, we're going to walk through an analysis of one of Microsoft's most used sample C++ programs, the "Scribble" program. Scribble is a neat sample asset that illustrates the use of Microsoft Foundation Classes by allowing you to draw on any of the window screens it provides. While it is not written in Java (I'll be detailing something Java specific in another article), I still think it's an excellent program to tour Purify due to its versatility and wealth of programmatic options, all in one small sample package.

That said, let's run the Scribble program (as shown in Figure 3) in Purify and see what happens. Note: For the rest of this article, I will be using Purify within Rose XDE Developer Plus, in order to illustrate how seamless the integration really is.

Tip: Depending on whether you're collecting leak and coverage data or memory profiling information, the advanced settings are a bit different. Please take a look at your settings to ensure you're covering all your bases before you start your analysis.

Running a program inside of IBM Rational Purify
Figure 3: Running a program inside of IBM Rational Purify

Before running your program within Purify, it instruments the program in order to assist in its analysis. Instrumenting code is a procedure in which code is modified in order to observe or modify its behavior1), and Purify uses this information to provide a detailed set of analysis data to the user. After it finishes instrumenting the program (Figure 4), Purify then displays any status, warning or error information it finds, as shown below (Figure 5).

Purify instruments the Scribble executable for detailed analysis
Figure 4: Purify instruments2 the Scribble executable for detailed analysis
Purify shows program loading information and partial runtime analysis
Figure 5: Purify shows program loading information and partial runtime analysis
(click here to enlarge)

In order to examine anything that Purify has discovered, simply click on the + sign in the "Error View" browser, and then right-click the corresponding error message(s). If you wish, you can also filter your error messages to work on specific ones first. Once an error message is expanded, you can even look at the exact code snippet to see where Purify has found the error and decide if you want to fix it or not.

You can also save the analysis runs that you are doing, and compare them after you've fixed various parts of your code to make sure that things are working the way that you want them to. Purify (and PurifyPlus) has an in-depth toolbar which can help you in all aspects of your code analysis.

Tip: All of the messages that Purify displays are referenced in the "Working with Purify Messages" section of the Help files. The Help files are a valuable resource in understanding Purify and PurifyPlus, so don't hesitate to use them.

Let's say that you want a quick way to discover where all the leaks are in your code at a given point in time. You can have Purify show you this by simply selecting the "All Leaks" menu item, as shown in Figures 6 and 7. In addition, you can also look at all the memory in use, as well as all of the memory handles in use by your program.

Showing where all the leaks are in the Scribble program
Figure 6: Showing where all the leaks are in the Scribble program
(click here to enlarge)
All the memory leaks of the Scribble program, displayed
Figure 7: All the memory leaks of the Scribble program, displayed
(click here to enlarge)

As you continue to use your program, the status line of the Error View browser window will continue to update, informing you of any new warning messages of which you'll need to be aware, as well as the total number of memory bytes leaked since you started your code analysis. The truly cool thing about this is that it is all done seamlessly. No clicking a button every 5 seconds to make sure you didn't miss anything. No piles of executables run outside of your IDE taking up space. It works quietly in the background, gathering up all the data you need to really fix your code, and tune it into something that really resembles a high-quality product for your project and your company. And that's something I think every developer needs on their desktop.

Tip: For even better code coverage, use Purify in conjunction with another tool in the PurifyPlus suite, IBM® Rational® Pure Coverage®, which automatically collects coverage data, as well as, tells you what portions of your code have been tested (and more importantly, which ones have not).

Memory profiling with the Scribble .NET Program

In order to fully analyze your program(s), it is not enough to simply look at the coverage and leak information about your code. It is just as important to profile the memory that your application is using, in order to get a better idea of how your program is running, and where your program is using memory during its execution. This is especially important with multi-threaded applications, since an errant thread can cause your application to go belly up in strange and confusing ways. Although .NET and Java programs have garbage collection capabilities, memory leaks sometimes happen; either in object references that aren't needed, or system resources that have not been freed. Purify can assist in solving these problems as well, by use of its memory profiling features.

Figure 8 below shows the same Scribble program, but this time it has been run with memory profiling, instead of coverage and leak detection. You can see that as I started to draw on the screen, the amount of memory used went up, as well as all the program threads that were in use (or not, for that matter) are displayed on the screen. The memory profiler also shows you things like the amount of memory your program is currently using, as well as, the peak amount of memory used and the number of times garbage collection was done. You can also take snapshots while your program is running in order to see exactly how memory is being used.

When you are finished profiling the memory of your running application, the entire run is saved, along with other runtime data. One of the main things saved is a graphical representation of each of the calls that your application made during the period of runtime analysis, as shown in Figure 9. This can then be saved, and compared with other runs that you make, in order to get an excellent picture of exactly how you're using memory, right down to the function call. Let's say that you want to see what has happened with your program's resources as you traverse down different logic paths. This feature lets you examine that scenario in detail. As I said before, you can also view the list of functions and objects that were called during program execution in order to find leaks and unneeded objects -- yet another way to see exactly what happened when your program was running.

Tip: When runtime memory analysis is finished, the "Guide to Using Memory Profiling" will appear. It's a good idea to use the Purify MD tool; it may help you solve a couple of memory issues that you didn't know existed.

Memory in use while the Scribble program is running
Figure 8: Memory in use while the Scribble program is running
(click here to enlarge)
The Call Graph for the Scribble application, ready for detailed analysis
Figure 9: The Call Graph for the Scribble application, ready for detailed analysis
(click here to enlarge)

In today's world, programs are expected to have incredible amounts of functionality. Sometimes, it seems that they almost need to work magic in order to get all the things done that they need to be able to accomplish. Having a memory profiler in addition to a complete code coverage and leak identification tool is mandatory to ensure that your program will not crash your computer, or make it impossible for you to run any other essential programs that you will need to get your job done. Again, quality really starts with the developer, and this really helps you create a top-notch product that will be around for years to come.


Introducing Visual Trace in Rose XDE Developer Plus

Visual Trace with the Scribble .NET program

So far, we've talked about three things you can do in order to analyze your code for quality improvement: Code coverage, memory leak detection, and memory profiling. Code coverage and leak detection are great ways to get a handle on what your code is doing (and where it's leaking) while it is running. Memory profiling is excellent as well -- you get a chance to see how much memory you use as you put your program through its paces and as you follow all the paths that you've logically created.

But sometimes, that's not enough.

Sometimes, you need to be able to take a look at what your program is doing right now, while it is running; what function you are in; what function you just went to; what function you should be going to and what your mouse is doing while it's waiting to accept input from you while you are analyzing your program.

Now, wait a minute. I just spent a lot of words talking about code coverage, memory leaks and memory profiling (pretty neat functionality that gives me all of that). After all, this program does work with runtime code, right? Well, yes -- it does. But, what if I told you that you could trace your program execution in real-time? See what it is doing with sequence diagrams that you could then save and view in order to get a pinpoint view of what is happening as you traverse program logic?

Welcome to Visual Trace. It does exactly what I said before; gives you a real-time view of program execution, by showing you a trace sequence diagram of exactly what happens while your program is running. It also keeps track of memory utilization, code coverage, and thread specific information while your program is running.

Note: Visual Trace only works with .NET and Java programs.

That being said, let's take a look at Visual Trace using our Scribble .NET program. As before, running your program with Visual Trace is as simple as loading your project in Rose XDE Developer Plus, and selecting the "Engage Visual Trace" feature under the PurifyPlus menu, as seen in Figure 10. After that, you need to select the classes that you want to see within your trace while your program executes (Figure 11), and then, start your program. Once it starts, you can follow along with the sequence trace diagram (if you can keep up -- see Figure 12), or save it and view it later for a more detailed analysis. If you wish, you can also generate a sequence diagram from the trace sequence diagram for use within XDE Developer Plus.

Enabling Visual Trace in Rose XDE Developer Plus
Figure 10: Enabling Visual Trace in Rose XDE Developer Plus
(click here to enlarge)
Selecting the classes to trace during program execution
Figure 11: Selecting the classes to trace during program execution

Tip: Once you have enabled Visual Trace, always start your program without debugging in order to see the trace sequence diagram.

As in other parts of PurifyPlus, you can also filter the trace sequence diagram to show you only a portion of the trace, as well as, look at a trace tree of the entire run. Looking at Figure 13, you can also see where memory profiling was activated in order to see both coverage data and memory used during the test run.

The Visual Trace (via sequence diagram) of the Scribble application
Figure 12: The Visual Trace (via sequence diagram) of the Scribble application3
(click here to enlarge)
Visual Trace with memory profiling turned on
Figure 13: Visual Trace with memory profiling turned on
(click here to enlarge)

Tip: In order to use Visual Trace with memory profiling, enable the Visual Trace integration under the PurifyPlus menu item.

While there may be other programs that visually trace a running application, I do not know of many that do it to this level of detail, or integrate it with memory profiling or thread tracing. Once again, Purify and Visual Trace really take software analysis to the next level, making sure that you, as a developer or a quality assurance engineer, have everything you need to make quality a product of your development efforts. Software development processes indicate that the earlier your company can find a defect and fix it, the less money it will cost you in the long run. By utilizing tools like Purify and Visual Trace, you can be well on your way to saving your company a lot of money in the long run.


Did we forget Java?

I've taken you through a grand tour of Purify and Visual Trace within Rose XDE Developer Plus, detailing a great many things. While the term "great many" certainly depends on your perspective, I can, without a doubt, say that we've discussed how to use the tools within PurifyPlus and XDE Developer Plus to do the following:

  • Analyze a program for memory leaks and errors
  • Look at code coverage for that same program
  • Use memory profiling to detail how much memory a program is using
  • Visually trace a program using a trace sequence diagram to see exactly what the program is doing during runtime

However, if you have been following along, I am pretty sure there's something that I have not covered... Well, let's see. I have talked about C++ and analysis, .NET and analysis, and Java... Wait! How could I leave out Java? Egads, man... Is something wrong with me?

Well, happily, the answer is no. Java applications share most (if not all) of the same functionality with respect to PurifyPlus that .NET applications do. So, when I talk about .NET -- those same concepts (memory profiling, Visual Trace, etc.) apply to Java applications as well! Fear not, prolific Java developer! You can use Purify for code analysis too!


Java applications within IBM Rational Purify and Visual Trace

Memory profiling and Visual Trace with Sun's Metalworks application

Well, we cannot use the Scribble program to look at how to analyze Java in IBM Rational Purify, now can we? However, we can certainly make use of some of Sun Microsystems sample Java applications and use those in order to take a look at some of the same Purify features that we detailed in the .NET application space. Figure 14 shows how we'd run the Metalworks sample application in Purify.

Running the Metalworks application in IBM Rational Purify
Figure 14: Running the Metalworks application in IBM Rational Purify

As you can see in Figure 15, we are able to look at memory profiling for a Java application in the same manner that we did previously, right down to the thread level. We can see which threads are in use, as well as, which ones are blocked and/or waiting. All of the same features for analysis of a .NET program are available to us in analysis of a Java program.

Memory profiling of the Metalworks program. Look familiar?
Figure 15: Memory profiling of the Metalworks program. Look familiar?
(click here to enlarge)

Let's not forget about Visual Trace. Figure 16 shows the Metalworks program with Visual Trace activated. In addition, you can also see that this Visual Trace contains thread-specific information (We managed to catch the program as it switched between two active threads. Cool!).

Visual Trace of the Metalworks Program
Figure 16: Visual Trace of the Metalworks Program
(click here to enlarge)

Although I have only shown you a couple of screenshots of Java specific usage -- rest assured that Purify and Visual Trace within Rose XDE Developer Plus works as well on Java as it does on the other programming languages that I have mentioned in this article. A significant segment of our customers live, breathe and code Java -- and for that reason, we will always have a lot of assets based on Sun's remarkable programming language.


Conclusion

I hope that this tour of PurifyPlus and Visual Trace within Rose XDE Developer Plus really shows why we believe it is the single most important product you can own in your coding arsenal to ensure quality. Even though there was a lot that I showed in this article, there is even more that this program can do to really help you eliminate defects and mistakes in your development process. I would wholeheartedly encourage you to download an evaluation copy of the product. For information on other features of the products described above, and to view some of the other products that make up PurifyPlus (for example, IBM® Rational® PureCoverage® and IBM® Rational® Quantify®), please take a look at the Rational area of IBM's developerWorks Web site.

If you have an idea for my next article, feel free to write in and tell me what you would like to see. Do you want me to examine a specific feature of one of our products? Create a case study based on a technology and apply it to our products? Write in and let me know what you'd like me to write about! You can contact me at rust@us.ibm.com. Take care, and see you soon!


Footnotes

1 'Instrumenting JVM's at the machine code level', Maebe, Ronsse, DeBosschere -- Ghent University, 2003

2 PurifyPlus uses Object Code Insertion (OCI) technology to instrument your code.

3 Visual Trace utilizes byte code insertion (BCI) technology in order to trace your running application.


About the author

Aaron (Rusty) Lloyd knows how to handle a broadsword as well as he handles technology. He is currently the New Technologies Evangelist for the Rational Developer Domain.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=5484
ArticleTitle=Bad software quality: Using IBM Rational PurifyPlus to avoid development problems
publish-date=07212004
author1-email=rust@us.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers