This document provides information about profiling your code using Metrowerks CodeWarrior.
Table of Contents
-------------------------
• Building ODFCWProfilerLib
• Profiling the ODF Shared Library
• Profiling ODF Static Libraries
• Automatic Modification of ODF Libraries
• Modifying Your Part
• Enabling Profiling
It is possible to use the performance profiling tools included in the Metrowerks CodeWarrior toolset to generate performance measurements for PowerPC OpenDoc parts built with ODF. It is not currently possible to profile 68k parts built with ODF. This document describes the CWPPCProfiler library and the steps necessary to configure profiling for an ODF part. Detailed information on the Metrowerks CodeWarrior Profiler can be found in the CodeWarrior documentation.
Building ODFCWProfilerLib
Profiling of ODF-based parts is based on the ODFCWProfilerLib shared library. This library is not provided in its built state. To build the library, open the CodeWarrior project at the path “ODFDev:ODF:Tools:Mac:CWPPCProfiler:ODFCWProfilerLib.π”. Build the library by selecting “Make” from the “Project” menu in CodeWarrior. The built library will be created as “ODFDev:ODF:Tools:Mac:ODFCWProfilerLib.PPC”.
Profiling the ODF Shared Library
During the process of profiling your part editor, you may find it useful to generate profiler data for the ODF shared library. Profiling the shared libary requires the following modifications:
1. Open the “ODFDev:ODF:SLPPCDebug:ODFLibrary.π” project in CodeWarrior.
2. Open the “PPC CodeGen” panel of the preferences dialog. Check the “Use Profiler” checkbox.
3. Add the ODFCWProfilerLib.PPC library you built earlier to the ODFLibrary project. Rebuild the ODFLibrary and replace the version in your Extensions folder with the new version.
Profiling ODF Static Libraries
During the process of profiling your part editor, you may find it useful to generate profiler data for one or more of the ODF static libraries. Profiling the static libraries requires the following modifications to each of the static libraries (Foundation, OS, Framework) that you wish to profile:
1. Open the project in CodeWarrior.
2. Open the “PPC CodeGen” panel of the preferences dialog. Check the “Use Profiler” checkbox.
3. Rebuild the library.
Automatic Modification of ODF Libraries
ODF includes an AppleScript that automatically enables profiling of all static ODF libraries and, optionally, the ODF shared library. If you want to automatically enable or disable profiling of the ODF libraries, execute the script at “ODFDev:ODF:Tools:Mac:Enable CWPPCProfiler”. Usually, you will want to profile your part, not the ODF libraries, so this script may not apply.
Modifying Your Part
To enable profiling of your part, do the following:
1. Open your part’s project in CodeWarrior.
2. Open the “PPC CodeGen” panel of the preferences dialog. Check the “Use Profiler” checkbox.
3. Add the ODFCWProfilerLib.PPC library you built earlier to your project.
4. Rebuild and install your part.
Enabling Profiling
Once the appropriate projects and libraries have been configured to profile, you must explicitly enable profiling of the code you want to measure. The header file “FWProfiler.h” contains declarations and comments relevant to profiling (the Metrowerks profiler library should not be called directly). All methods are described below:
FW_ProfilerSetStatus: Pass this function a value of TRUE to turn profiling on and a value of FALSE to turn profiling off.
FW_ProfilerGetStatus: Returns TRUE if profiling is on, FALSE if profiling is off.
FW_ProfilerSetDumpFile: Optionally call this method and provide a path, as a length-prefixed pascal string, indicating where the profiling information should be dumped. If this method is not called, profiler data will be dumped into a file called “ODFProfiler Dump” at the root of the startup disk. If the dump file already exists when a dump occurs, the first unique number beginning at 1 will be added to the file name.
FW_ProfilerUseDefaultDumpFile: Calling this method resets the dump file location to its default of “ODFProfiler Dump” at the root of the boot volume.
FW_ProfilerDump: Dumps the profiler buffer into the current dump file. Calling this method does not clear the profiler buffer.
FW_ProfilerClear: Clears the profiler buffer. This method does not affect the on/off status of the profiler.
An example of how to use these methods follows:
#ifndef FWPROFILER_H
#include "FWProfiler.h" // add at beginning of source files that
#endif // call FW_Profiler methods
void CMyPart::SomeMethod()
{
FW_ProfilerSetDumpFile("\pHD:MyPartDumpFile");
FW_ProfilerSetStatus(TRUE);
... call subroutines ...
FW_ProfilerDump();
FW_ProfilerSetStatus(FALSE);
}
Consult the Metrowerks documention for information on how to view and interpret profiler dump files.