|
| 1 | +# VisualVM for VS Code |
| 2 | + |
| 3 | +This extension integrates the [VisualVM](https://visualvm.github.io) monitoring and troubleshooting tool into Visual Studio Code (VS Code). |
| 4 | + |
| 5 | +## Features |
| 6 | +* Easy installation of VisualVM. |
| 7 | +* When starting an application from VS Code: |
| 8 | + - The application process is configured to display its folder name in VisualVM. |
| 9 | + - The application process PID is detected to invoke VisualVM actions when needed. |
| 10 | + - When started, the application process can be automatically opened in VisualVM. |
| 11 | +* Shortcuts for VisualVM actions such as Thread dump, Heap dump, Start sampling and Start flight recording are available in a dedicated view within VS Code. |
| 12 | +* The CPU Sampler filter can be automatically configured to include only application classes. |
| 13 | +* Two-way integration: the Go to Source action in VisualVM opens the source code in VS Code. |
| 14 | + |
| 15 | +## Requirements |
| 16 | + |
| 17 | +Install the following in order to use this extension: |
| 18 | +* VisualVM 2.1+ (we recommend using the latest version of VisualVM; you can [install directly from within VS Code](#configuring-visualvm)). |
| 19 | +* Any JDK 8+ to run VisualVM and detect running processes using `jps`. |
| 20 | + |
| 21 | +Either of these Java language servers must be installed to integrate VisualVM with application startup, to support application class filtering, and to provide the Go to Source feature: |
| 22 | + |
| 23 | +* [Language Server for Java by Apache NetBeans](https://marketplace.visualstudio.com/items?itemName=ASF.apache-netbeans-java) |
| 24 | +* [Extension Pack for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack) |
| 25 | + |
| 26 | +The extension also tightly integrates with the [Tools for Micronaut® framework](https://marketplace.visualstudio.com/items?itemName=oracle-labs-graalvm.micronaut-tools) to provide the best monitoring and profiling experience. For example: |
| 27 | +* The VisualVM view can be easily displayed in the Micronaut Tools activity. |
| 28 | +* CPU Sampler is configured for the selected Graal Cloud Native (GCN) application subproject. |
| 29 | +* The Go to Source feature is configured for the selected GCN application subproject. |
| 30 | + |
| 31 | +## Quick Start |
| 32 | +Follow these steps to start using VisualVM with VS Code: |
| 33 | + |
| 34 | +1. Install the **VisualVM for VS Code** extension. |
| 35 | +2. Install **Language Server for Java by Apache NetBeans** or **Extension Pack for Java** (or both). |
| 36 | +3. Open your application sources. Make sure it is configured correctly before integrating it with VisualVM. |
| 37 | +4. Click **Download Latest VisualVM** in the VisualVM view and complete the required steps. |
| 38 | +5. Invoke the **Configure** action displayed for the *When started* node in the *VisualVM* view, and select **Open Process**. |
| 39 | +6. Start the application using the **Run Without Debugging** or **Start Debugging** action. |
| 40 | + |
| 41 | +The application starts and its process is opened in VisualVM and displayed using the name of the source code folder within VS Code. |
| 42 | + |
| 43 | +The Go to Source action in the VisualVM views, such as the Heap Viewer, CPU or Memory Sampler/Profiler results, opens the associated source code within VS Code. |
| 44 | + |
| 45 | +## Configuring VisualVM |
| 46 | + |
| 47 | +To download the latest VisualVM release from [https://visualvm.github.io](https://visualvm.github.io), use the **Download Latest VisualVM** action. |
| 48 | +Depending on the host OS, this will either download a ZIP archive or a macOS disk image (.dmg) file. |
| 49 | +The ZIP archive will be automatically extracted and registered for the extension. |
| 50 | +The macOS disk image must be installed and registered manually (see the next paragraph). |
| 51 | + |
| 52 | +If an existing local VisualVM installation is already available on the system, or after manually installing a macOS disk image, use the **Select Local VisualVM Installation** action and point to the VisualVM installation directory. |
| 53 | +The extension supports **VisualVM 2.1+**, or the corresponding GraalVM component (select the GraalVM installation directory). |
| 54 | +We recommend using the latest version of VisualVM. |
| 55 | + |
| 56 | +To manually register an existing local VisualVM installation, or to configure a specific VisualVM installation for the workspace, use the `visualvm.installation.visualvmPath` property to point to the VisualVM installation directory. |
| 57 | + |
| 58 | +Custom VisualVM startup parameters (such as `--userdir`) including VM arguments (such as `-Xmx...`) can be defined using the `visualvm.startup.visualvmParameters` property. |
| 59 | + |
| 60 | +By default, VisualVM runs using a defined/automatically found local JDK (see the [Configuring a JDK](#configuring-a-jdk) section). |
| 61 | +To define a custom JDK for running VisualVM, set the `visualvm.startup.useJdkPathForVisualvm` property to `false` and use the `--jdkhome` VisualVM startup parameter. |
| 62 | + |
| 63 | +## Configuring a JDK |
| 64 | + |
| 65 | +The extension requires a JDK for: |
| 66 | + |
| 67 | +* Running VisualVM (if not disabled, see the [Configuring VisualVM](#configuring-visualvm) section). |
| 68 | +* To detect locally running processes using the `jps` utility, either when starting an application, or for a manual process selection. |
| 69 | +* For configuring the JDK source roots used by the `Go to Source` feature. |
| 70 | + |
| 71 | +The extension can use any JDK to run the VisualVM tool and detect Java processes. |
| 72 | +However, it should match the JDK running a monitored application in order to correctly support Go to Source for the JDK classes. |
| 73 | +The JDK is located by searching through the following properties in order: |
| 74 | +* Properties: `netbeans.jdkhome`, `java.jdt.ls.java.home`, `java.home`, `graalvm.home`. |
| 75 | +* Environment variables: `JDK_HOME`, `JAVA_HOME`. |
| 76 | + |
| 77 | +To override the JDK that was selected automatically, or to configure a specific JDK for the workspace, set the `visualvm.java.jdkPath` property to point to a local JDK installation directory (either in the VS Code Settings view, or manually in _settings.json_). |
| 78 | + |
| 79 | +## VisualVM Actions in VS Code |
| 80 | + |
| 81 | +### Start VisualVM |
| 82 | +* *Start VisualVM* (action in the VisualVM view toolbar) starts the VisualVM, or brings its window to the front if it is already running. |
| 83 | + |
| 84 | +### Process Node |
| 85 | +* *Select Process*: Shows a list of all running processes available for monitoring, excluding those already being monitored. |
| 86 | + |
| 87 | +* *Show in VisualVM*: Opens the currently selected process in VisualVM, and preselects the defined view. Use the `visualvm.behavior.preselectProcessView` property to define the view to be preselected (use `Current` for no change). |
| 88 | + |
| 89 | +* *Stop Monitoring*: Clears the currently selected process, but does not stop the process or its monitoring in the VisualVM tool. |
| 90 | + |
| 91 | +### When Started Node |
| 92 | +* *Configure*: Defines the action to be taken when a new application process is started by VS Code. When configured, the process can be automatically opened in VisualVM, and a preconfigured sampling or flight recording session can be started. |
| 93 | + |
| 94 | + > Note: The *When started* node is only displayed if the automatic application process selection is enabled (`visualvm.integration.automaticallySelectProjectProcess` property is set to `true`), and no process has been selected yet, or it has not been selected manually using the *Select Process* action. |
| 95 | +
|
| 96 | +### Thread Dump Node |
| 97 | +* *Take Thread Dump*: Takes a thread dump from a monitored process, and selects its view in VisualVM. |
| 98 | + |
| 99 | +### Heap Dump Node |
| 100 | +* *Take Heap Dump*: Takes a heap dump from a monitored process, and selects its view in VisualVM. |
| 101 | + |
| 102 | +### CPU Sampler Node |
| 103 | +* *Start CPU Sampling*: Starts a new CPU sampling session for a monitored process, and selects its view in VisualVM. The sampling session settings are defined by the *Filter* and *Sampling rate* subnodes. |
| 104 | + |
| 105 | +* *Take Snapshot of Sampler Results*: Takes a snapshot of the collected data, and selects its view in VisualVM. |
| 106 | + |
| 107 | +* *Stop Sampling*: Terminates the current sampling session, and selects its view in VisualVM. |
| 108 | + |
| 109 | +### Memory Sampler Node |
| 110 | +* *Start Memory Sampling*: Starts a new memory sampling session for the monitored process, and selects its view in VisualVM. The sampling session settings are defined by the *Sampling rate* subnode. |
| 111 | + |
| 112 | +* *Take Snapshot of Sampler Results*: Takes a snapshot of the collected data, and selects its view in VisualVM. |
| 113 | + |
| 114 | +* *Stop Sampling*: Terminates the current sampling session, and selects its view in VisualVM. |
| 115 | + |
| 116 | +### JFR Node |
| 117 | +* *Start Flight Recording*: Starts a new flight recording for a monitored process. The flight recorder preset to be used for the recording is defined by the *Settings* subnode. |
| 118 | + |
| 119 | +* *Dump Flight Recording Data*: Dumps the data for the current flight recording, and selects its view in VisualVM. |
| 120 | + |
| 121 | +* *Stop Flight Recording*: Terminates the current flight recording. |
| 122 | + |
| 123 | +## Monitoring Multiple Processes Simultaneously |
| 124 | + |
| 125 | +Whilst monitoring multiple processes concurrently is not a typical scenario, it is supported by the VisualVM Integration extension. |
| 126 | + |
| 127 | +To start monitoring another process using VisualVM, start another application process using the *Run Without Debugging* or *Start Debugging* action, or use the **VisualVM: Select Process** command from the Command Palette. |
| 128 | + |
| 129 | +> Note: The *When started* node is not available for a subsequent monitored process, and its respective *Process* node is removed immediately after monitoring of the process has been stopped. |
| 130 | +
|
| 131 | +## Troubleshooting |
| 132 | + |
| 133 | +The VisualVM for VS Code extension customizes the way VS Code runs an application by adding extra VM arguments to the launch configuration. |
| 134 | +If the application process fails to start, it may be required to disable these customizations by setting the following properties to `false`: |
| 135 | + |
| 136 | +* `visualvm.integration.automaticallySelectProjectProcess` |
| 137 | +* `visualvm.integration.customizeDisplayNameForProjectProcess` |
| 138 | + |
| 139 | +The extension also controls the VisualVM startup parameters. |
| 140 | +If the VisualVM fails to start, disable or tweak the following properties: |
| 141 | + |
| 142 | +* `visualvm.startup.visualvmParameters` |
| 143 | +* `visualvm.startup.useJdkPathForVisualvm` |
| 144 | +* `visualvm.integration.enableGoToSource` |
| 145 | + |
| 146 | +In case VisualVM fails to open source code using the `Go to Source` action in VS Code, or it opens another VS Code window, configure the following property: |
| 147 | + |
| 148 | +* `visualvm.integration.visualStudioCodeParameters` |
| 149 | + |
| 150 | +For detailed analysis of any issues encountered when using the extension, see the *VisualVM for VS Code* log in the VS Code *Output* view. |
| 151 | +Additionally, see the logs of any other extensions involved, or the *Extension Host* log. |
| 152 | + |
| 153 | +For VisualVM specific troubleshooting, refer to the [VisualVM Troubleshooting Guide](https://visualvm.github.io/troubleshooting.html). |
| 154 | + |
| 155 | + |
| 156 | +## Settings |
| 157 | + |
| 158 | +| Name | Description | Default Value | |
| 159 | +|---|---|---| |
| 160 | +| `visualvm.java.jdkPath` | Path to a local JDK installation directory (leave empty to find automatically) | | |
| 161 | +| `visualvm.startup.useJdkPathForVisualvm` | Use a defined/automatically found local JDK installation to run VisualVM (not applicable if the selected VisualVM installation is a GraalVM component) | `true` | |
| 162 | +| `visualvm.installation.visualvmPath` | Path to a local VisualVM 2.1+ installation directory (we recommend using the latest version of VisualVM) | | |
| 163 | +| `visualvm.startup.visualvmParameters` | Optional parameters for starting VisualVM (`--userdir`, `-J-Xmx`, and so on) | | |
| 164 | +| `visualvm.behavior.visualvmWindowToFront` | Bring a VisualVM window to front when a VisualVM action is invoked from within VS Code | `true` | |
| 165 | +| `visualvm.behavior.preselectProcessView` | Preselected view for a process shown in VisualVM (either the Show in VisualVM action, or the Open Process action when started) | Monitor | |
| 166 | +| `visualvm.integration.automaticallySelectProjectProcess` | Automatically select a started application process for monitoring | `true` | |
| 167 | +| `visualvm.integration.customizeDisplayNameForProjectProcess` | Configure a started application process to display its folder name in VisualVM | `true` | |
| 168 | +| `visualvm.integration.enableGoToSource` | Enable opening source code from VisualVM results in VS Code using the Go to Source action | `true` | |
| 169 | +| `visualvm.integration.visualStudioCodeParameters` | Optional parameters for invoking VS Code launcher to open source code from VisualVM (`--user-data-dir`, `--extensions-dir`, and so on) | | |
| 170 | + |
| 171 | +## Provide Feedback or Seek Help |
| 172 | + |
| 173 | +* [Request a feature](https://github.com/oracle/visualvm/issues/new?labels=enhancement) |
| 174 | +* [File a bug](https://github.com/oracle/visualvm/issues/new?labels=bug) |
| 175 | + |
| 176 | +## Contributing |
| 177 | + |
| 178 | +We highly appreciate any feedback! Please let us know your ideas, missing features, or bugs found. Either [file a RFE/bug](https://github.com/oracle/visualvm/issues/new/choose) or [leave us a message](https://visualvm.github.io/feedback.html). For legal reasons, we cannot accept external pull requests. See |
| 179 | +[CONTRIBUTING](./CONTRIBUTING.md) |
| 180 | +for details. |
| 181 | + |
| 182 | +## Security |
| 183 | + |
| 184 | +Please consult the [security guide](./SECURITY.md) for our responsible security vulnerability disclosure process |
| 185 | + |
| 186 | +## License |
| 187 | + |
| 188 | +Copyright (c) 2017, 2024 Oracle and/or its affiliates. |
| 189 | +Released under the GNU General Public License, version 2, with the Classpath Exception. |
| 190 | + |
| 191 | +## Release Notes |
| 192 | + |
| 193 | +See the [CHANGELOG](CHANGELOG.md). |
0 commit comments