Adobe Flex 3 Help

Using the profiler

The profiler requires Flash Player version 9.0.115 or later. You can profile applications that were compiled for Flex 2, Flex 2.0.1, and Flex 3. You can use the profiler to profile ActionScript 3.0 applications that were built with Flash Authoring, as well as Adobe® AIR™ applications.

The profiler requires debugging information in the application that you are profiling. When you compile an application and launch the profiler, Flex Builder includes the debugging information in the application by default. You can explicitly include debugging information in an application by setting the debug compiler option to true. If you export an application by using the Export Release Build option, the application does not contain debugging information in it.

Starting, stopping, and resuming the profiler

You can profile applications that you are currently developing in Flex Builder. Flex Builder includes debugging information when it compiles and runs an application during a profiling session. You can also profile external applications that you are not currently developing in Flex Builder but whose SWF file is available with a URL or on the file system. To profile an application, the application's SWF file must include the debugging information. For more information, see Profiling external applications.

Start profiling a Flex application

  1. Close all instances of your browser.
  2. Open your Flex application in Flex Builder.
  3. Click the Profile application_name button in the main toolbar. Flex Builder informs you that you should close all instances of your browsers if you have not already done so.
  4. Click the OK button. Flex Builder compiles the application and launches it in a separate browser window. Flex Builder also displays the Configure Profiler dialog box.
  5. Select the options in the Configure Profiler dialog box and click Resume. To profile an application, you must select the Enable Memory Profiling option or the Enable Performance Profiling option.

    The following table describes the options:

    Setting

    Description

    Connected From

    Shows you the server that you are launching the application from. If the application is running on the same computer as the profiler, this value is localhost. You cannot change this value. However, you can profile an application that is running on a separate computer.

    Application

    Shows you which application you are about to profile. You cannot change this value.

    Enable Memory Profiling

    Instructs the profiler to collect memory data. You use this option to detect memory leaks or find excessive object creation.

    If you are doing performance profiling, you can deselect this option.

    The default value is that the option is selected.

    Watch Live Memory Data

    Instructs the profiler to display memory data in the Live Objects view while profiling. This is not required for doing either memory or performance profiling. You can select this option only if you selected Enable Memory Profiling.

    The default value is that the option is selected.

    Generate Object Allocation Stack Traces

    Instructs the profiler to capture a stack trace each time a new object is created. Enabling this option can slow down the profiling experience, so you should only do it when absolutely necessary. You can select this option only if you selected Enable Memory Profiling.

    The default value is that the option is unselected.

    If you do not select this option, you cannot view allocation trace information on the Object References view or on the Allocation Trace view.

    Enable Performance Profiling

    Instructs the profiler to collect stack trace data at the sampling intervals. You use these samples to determine where the bulk of the execution time in your application is spent.

    If you are doing memory profiling, you can deselect this option.

    The default value is that the option is selected.

You can change the default values of these options by changing the profiling preferences. For more information, see Setting profiler preferences.

  1. You can now start interacting with your application and examining the profiler data.

Pause and resume profiling a Flex application

After you have started the profiler, you can pause and restart applications in the Profile view. You select an application and then select the action you want to perform on that application. The following example shows you the Profile view with multiple applications. One application is currently running, and all other applications have been terminated.

Profile panel.

  1. Select the application in the Profile view.
  2. Click the Suspend button. Flex marks the application in the Profile view with [Suspended].
  3. To resume profiling the application, select the application and click the Resume button. Flex marks the application in the Profile view with [Running].

Stop profiling a Flex application

  1. Select the application in the Profile view.
  2. Click the Terminate button to end the profiling session. This does not close the browser or kill the Player process. You must do that manually.
  3. To return to the Flex Development perspective, select Flex Development from the perspective drop-down list. You can also change perspectives by selecting Control+F8 on Windows.

About the profiler buttons

The following table describes the buttons in the profiler toolbar:

Button

Name

Description

Resume icon

Resume

Resumes the profiling session. This option is enabled only when an application name is selected and is currently suspended.

Suspend icon

Suspend

Suspends the profiling session. This option is enabled only when an application name is selected and is currently running.

Terminate icon

Terminate

Terminates the profiling session. This option is enabled only when an application name is selected and it has not been terminated already.

Run Garbage Collector icon

Run Garbage Collector

Instructs Flash Player to run garbage collection. This option is enabled only when an application name is selected and the application is currently running.

For more information about garbage collection, see About garbage collection.

Take Memory Snapshot icon

Take Memory Snapshot

Stores the memory usage of an application so that you can examine it or compare it to other snapshots.

This option is enabled only when an application name is selected and that application is currently running and when you select Enable Memory Profiling in the launch dialog box. The profiler adds new memory snapshots as children of the selected application in the Profile view.

To open the new memory snapshot in the Memory Snapshot view, double-click the memory snapshot entry.

Garbage collection occurs implicitly before memory snapshots are recorded. In other words, clicking the Take Memory Snapshot button is the equivalent of clicking the Run Garbage Collection button and then clicking the Take Memory Snapshot button.

For more information about memory snapshots, see Using the Memory Snapshot view.

Find Loitering Objects icon

Find Loitering Objects

Compares two memory snapshots in the Loitering Objects view.

This option is enabled only when two memory snapshots are selected and when you selected Enable Memory Profiling in the launch dialog box.

For more information about the Loitering Objects view, see Using the Loitering Objects view.

View Allocation Trace icon

View Allocation Trace

Compares the methods between two memory snapshots in the Allocation Trace view.

This option is enabled only when two memory snapshots are selected, and when you select Enable Memory Profiling in the launch dialog box.

For more information about the Allocation Trace view, see Using the Allocation Trace view.

Reset Performance Data icon

Reset Performance Data

Clears the performance profiling data.

This option is enabled only when an application name is selected and the application is running and when you select Enable Performance Profiling in the launch dialog box.

You typically click this button, interact with your application and then click the Capture Performance Profile button to get a performance snapshot of the application from the time you reset the data.

For more information about the Performance Profile view, see Using the Performance Profile view.

Capture Performance Profile icon

Capture Performance Profile

Stores a new performance snapshot as a child of the selected application.

This option is enabled only when an application name is selected and the application is running and when you select Enable Performance Profiling in the launch dialog box.

To open the Performance Profile view, double-click the performance snapshot entry.

For more information about the Performance Profile view, see Using the Performance Profile view.

Delete Snapshot icon

Delete

Removes the selected snapshot's data from memory. Clicking this button also removes the application from the profile view, if the application has been terminated.

This option is enabled only when a performance or memory snapshot is selected.

Some views in the profiler, such as Method Statistics and Object Statistics, have navigation buttons that you use to traverse the stack or change the view. The following table describes the navigation buttons in these profiler views:

Button

Name

Description

Back icon

Back

Shows all the methods that you traversed from the first selected method to the currently displaying method.

Forward icon

Forward

Shows the currently displayed method and the methods that lead to the currently selected method. This item is enabled after you move backward.

Home icon

Home

Displays the first selected method.

Open Source icon

Open Source File

Opens a source editor that shows the source code of the selected method.

Filters icon

Filters

Lets you control which methods you want to include in the table. For more information, see About profiler filters.

Show/Hide Zero Time Methods icon

Show/Hide Zero Time Methods

Shows or hides methods that have a time of 0.00 in the average time column, which is a result of not showing up in any samples.

Saving and loading profiling data

After you run the profiler, you can save the data so that you can compare a snapshot from the current profiling session with a snapshot you take after you make changes to your code. This helps you determine if you identified the right problem areas and if your changes are improving the performance and memory usage of your application.

When you save profiling data, you save all the application data in that profile. This includes all performance profiles, memory snapshots, and allocation traces. Flex Builder writes this information to a group of binary files in the location that you specify.

Save profiling data

  1. Select the application in the Profile view.
  2. Open the drop-down list in the Profile view and select Save. The Browser for Folder dialog box appears.
  3. Choose a location to save the profile data and click OK. You should create a new folder for each set of profiling data that you want to save. Otherwise, the new data will overwrite the old data if you choose the same folder.

Retrieve saved profiling data

  1. Select the Saved Profiling Data view.
  2. Click the Open button. The Browser for Folder dialog box appears.
  3. Navigate to the folder that contains your application's profile data and click OK. Flex Builder displays the available profiling data in the Saved Profiling Data view. You cannot resume the application in this view, but you can view the memory snapshots, performance profile, or other data that you saved.

You cannot delete saved application data from within Flex Builder.

Delete profiling data

  1. Select the snapshot from the application in the Profile view.
  2. Click the Delete button.

Setting profiler preferences

You can set some profiler preferences so that your settings are applied to all profiling sessions. You can use these settings to define the Flash Player/browser that you use to profile the application in, as well as define the default filters and the port number that the application is available on, if the profiled application is running on a server.

Set Flex Builder preferences for multiple profiling sessions

 Open the Preferences dialog and select Flex > Profiler.

The following example shows the profiler preferences:

Profiler preferences dialog box.

Select the options under the Profiler menu to navigate to the various options. The following table describes the preferences you can set:

Menu Selection

Description

Profiler

Lets you select the default profiling method. Select the options to enable or disable memory profiling and performance profiling.

Connections

Lets you define the port number that Flex Builder listens to the profiled application on.

The default port number is 9999. You cannot change the port to 7935, because that port is used by the debugger.

Exclusion Filters

Lets you define the default packages that are excluded from the profiler views. For more information on using filters, see About profiler filters.

Inclusion Filters

Lets you defines the default packages that are included in the profiler views. All other packages are excluded. For more information on using filters, see About profiler filters.

Player/Browser

Lets you define the location of the Flash Player executable and browser executable that Flex Builder uses to run your profiled application.

Profiling external applications

In addition to profiling applications that you are developing in Flex Builder, you can profile external applications. External applications can be SWF files located anywhere that is accessible. This includes applications that are located on a remote web server or an application that is on your local file system.

The external application must be compiled with debugging information in it before you can profile it. To compile an application with debugging information in it, add debug=true to the compiler arguments. Flex Builder also returns this error if you specify an unknown file type, such as HTML or JSP. You can only specify SWF files as external applications to profile. If the application has no debugging information, Flex Builder returns the following error:

Flex Profiling error message.

If you get this error, recompile the application with the debug compiler option set to true and launch it again.

For the SWF file, you can specify either a URL or a file system location. If you specify a URL, Flex Builder launches the application's SWF file within the default browser. The browser must be using the debugger version of Flash Player to successfully profile the application.

If you specify a file system location for the SWF file, Flex Builder opens the application within the debugger version of the stand-alone Flash Player. In general, you should request the file by using a URL. Running applications in the stand-alone version of Flash Player can produce unexpected results, especially if your application uses remote services or network calls.

Profile an external application

  1. Change to the Flex Profiling perspective.
  2. Select Profile > Profile External Application. The Profile External Application dialog box appears.

    Profile External Application dialog box.

  3. Select the Launch the Selected Application option (the default) and click the New button. The Add an Application dialog box appears.

    Add an Application dialog box.

    You can also manually launch the application by selecting the Launch the Application Manually Outside Flex Builder option.

  4. Enter the location of the SWF file and click OK, or click the Browse button and locate your application on your file system.
  5. Click the Launch button. If you specified a URL for the location of the application, Flex Builder launches the application within the default browser. If you specified a file system location for the application, Flex Builder opens the application in the stand-alone version of Flash Player.

    If you specified a SWF file that was not compiled with debugging information, Flex Builder returns an error. Recompile the application with the debug compiler option set to true and launch it again.