This chapter gives you the information you need to get CodeWarrior Profiler installed and running. For new users, this chapter provides a brief overview of profiling code.
This chapter includes the following topics:
This section describes what kind of system you'll need in order to use CodeWarrior Profiler.
Profiler is part of a complete package that also includes the CodeWarrior IDE, MW Profiler, and the profiler libraries. You need all these elements to use the Profiler system effectively.
Your first step toward developing software for your target is to install the CodeWarrior tools. The tools include a variety of components such as the IDE, debugger, plug-in compilers and linkers, standard libraries, runtime libraries and headers, and all necessary documentation.
The CodeWarrior Installer automatically installs all necessary components. It is strongly recommended that you use the CodeWarrior Installer to ensure that you have all the required files. If you have any questions regarding the installer, read the instructions built into the CodeWarrior Installer itself.
To start the installation process, do the following:
On the Macintosh desktop, double-click the icon for the CodeWarrior CD. Then double-click the icon for the CodeWarrior Installer, located at the root level of the CD.
This section provides you with general information about what a profiler is, different kinds of profilers, and a typical strategy you would follow to measure program performance. Along the way you'll see how the CodeWarrior profiler handles the advantages and disadvantages of profiling code.
Speed and performance are important issues in most software projects. In most cases, if your code doesn't work quickly, it doesn't work well.
Programmers have regularly observed that 10% of their code does 90% of the work. Reworking code to make it more efficient is a non-trivial task. You should concentrate on improving that core 10% of your code first, and improve the infrequently-used code later, if at all.
Wouldn't it be really cool if you could determine precisely where your code spent its time? That's what a profiler does for you-it gives you clues. More than clues, the CodeWarrior profiler gives you hard and reliable data.
A good profiler analyzes the amount of time your code spends performing various tasks. Armed with this information, you can apply your efforts to improving the efficiency of core routines.
A profiler can also help you detect bottlenecks-routines your data passes through to get to other places-and routines that are just inordinately slow. Identifying these problems is the first step to solving them.
The simplest profilers count how many times a routine is called. They do not report any information about which routines are called by other routines, or the amount of time spent inside the various routines being profiled.
Clearly a good profile of the runtime performance of code requires more information than a raw count. More advanced profilers perform statistical sampling of the runtime environment. These profilers are called passive or sampling profilers.
A passive profiler divides the program being profiled into evenly-sized "buckets" in memory. It then samples the processor's program counter at regular intervals to determine which bucket the counter is in.
The main advantage of a passive profiler is that it requires no modification to the program under observation. You just run the profiler and tell it what program to observe. Also, passive profilers distribute the overhead that they incur evenly over time, allowing the post-processing steps to ignore it. On the other hand, they cannot sample too frequently or the sampling interrupt will overwhelm the program being sampled.
Passive profilers have a significant disadvantage. Although useful, bucket boundaries do not line up with routine boundaries in the program. This makes it difficult if not impossible to determine which routines are heavily used. As a result, passive profilers generate a relatively low-resolution image of what's happening in the program while it runs.
In addition, because they rely on a statistical sampling technique, the program must run for a long enough period to collect a valid sample. As a result, they do not have good repeatability-that is, the results you get from different runs may vary unless the sampling period is long.
The most advanced and accurate profilers are called active profilers. The CodeWarrior profiler is an active profiler.
An active profiler tracks the precise amount of time a program spends in each individual routine, measured directly from the system clock.
To perform this magic, an active profiler requires that you modify the code of the program to be observed. An active profiler gains control at every routine entry and exit. There must be a call to the profiler at the beginning of each profiled routine. The profiler can then track how much time is spent in the routine.
This approach has significant advantages over a passive profiler. An active profiler can report high-resolution results about exactly what your program is doing. An active profiler also tracks the dynamic call tree of a program. This information can be very useful for determining the true cost of calling a routine. The true cost of a routine call is not only the time spent in the routine, it is also the time spent in its children-the subsidiary routines it calls, the routines they call, and so on to whatever depth is necessary.
Because it uses measurements and not statistical sampling, an active profiler is much more accurate and repeatable than a passive profiler.
The requirement that you must modify the actual source code might seem like a significant disadvantage. With the CodeWarrior profiler, this disadvantage is minimal. Activating the profiler for an entire program-or for a range of routines within a program-is simple. The compiler does most of the work, inserting the necessary calls to the profiler itself. You do have to recompile the project when you turn on profiling.
Active profilers distribute their overhead by routine call frequency. This makes it harder to compensate for the overhead during post processing of the output. The CodeWarrior profiler tracks the overhead automatically, compensates for it, and also reports the overhead to you. You don't have to worry about overhead at all.
Finally, active profilers generate a large amount of raw information. This can lead to confusion and difficulty interpreting the results. The MW Profiler application that is part of the CodeWarrior profiler system handles these difficulties with aplomb. You can view and sort the data in whatever way best suits your needs.
You use a profiler to measure the runtime performance of your code. What is usually important is how your code's performance measures up to some standard. When approaching the problem of measuring performance, you might want to take these three steps:
For example, you might decide that you want the program to load in less than ten seconds, or check the spelling of a five-page document that contains no misspellings in 15 seconds. Also decide on the platform you will use for testing, since processor speeds vary.
2. Determine how to measure time.
Your measurement device may be no more complicated than a stopwatch, or you may need to add some simple code to count ticks. At this phase you want to test the code in as close to its finished form as possible, so measure time in a way that is accurate enough to suit your needs, and that has the lowest impact on your code's natural performance. You do not want to run a full-blown profile here, because profiling can add significant overhead, thus slowing down your code's raw performance.
3. Run the tests and measure results.
If you meet your performance goals, your job is done. If your code does not meet your goals, then it's time to profile your code.
To profile your code, you do three things:
1. Run a profiler on the area of the code you want tested.
This might be a single routine, a group of routines that perform a task, or even the entire application. What you profile depends upon what you are testing.
2. Analyze the data collected by the profiler and improve your code.
You study the results of your profiling and look for problems and room for improvement.
The profiling process is iterative. You repeat these two steps until you achieve the performance gain you need to meet your goals.
The rest of this manual discusses how to perform these two steps-profile your code and analyze the results-using the CodeWarrior profiler system.
3. Retest your code to verify results
When you are satisfied that you have reached your goals, you have one more step to perform. You should run your original tests-without the profiler of course-to verify that your code in its natural state meets your performance goals.
The CodeWarrior profiler will help you meet those goals quickly and easily.