## Attaching to a Local Application

You can use the attach mode to profile a local application when you want or need to start the application outside of the IDE. For example, you may want to use the attach mode in the following cases:

- Your application needs to be started from the command line or uses a complex launch script
- You want to obtain profiling data on the startup of the appliction or target JVM
- You want to profile the application without restarting the application (Dynamic attach mode, requires JDK 1.6)

To attach to a local application, you first need to configure the attachment settings using the Attach wizard. These settings are associated with the project you are profiling. You only need to configure the attach settings for your project once, but you can modify the settings at any time by stepping through the Attach wizard again.

When you configure the settings for attaching to a local application, you can choose from the following attachment modes:

- Direct. This mode enables you to obtain profiling data on the startup of the local application.
- Dynamic. (requires JDK 1.6) This mode allows you to detach from and re-attach to the application without stopping the application.

To attach to a local application:

1. Choose Profile > Attach Profiler ( ) from the main menu to open the Select Profiling Task dialog box.
2. Select the target application from the Attach To drop-down list at the top of the dialog box.
3. Click define to open the Attach Wizard to specify the Attach mode.
4. In the Attach wizard, select the target type of the application.
5. Select Local as the Attach Method.
6. Select either Direct or Dynamic as the Attach Invocation. Click Next.
7. Step through the wizard and follow the instructions for configuring the attach settings. Click Finish to close the wizard.
8. In the Select Profiling Task dialog box, select a profiling task and any options.
9. Click Attach.

To detach from the application:

- Choose Profile > Detach from the main menu or click Detach in the Profiler window.

When you detach from the application, the connection to the target JVM is closed. When you click Detach, you can choose to stop the application upon detach or allow the application to keep running. You can reattach to the application by choosing Profile > Attach Profiler from the main menu.

### Modifying the profiling task

Once the connection is established and the profiler is attached to the target application, you can change the profiling task you are running on the target application without stopping or restarting the application.

To change the profiling task without detaching:

1. Choose Profile > Modify Profiling (Alt+Shift+F2) from the main menu or click Modify Profiling ( ) in the Profiler window.
2. Select a new profiling command and adjust any settings.
3. Click Run.

The target application is instrumented again without starting or stopping the application.

See Also
  Profiling Using Attach Mode

Legal Notices