Skip to content

Commit d2fd93d

Browse files
committed
VisualVM for VS Code integration extension
1 parent d8cbdf8 commit d2fd93d

31 files changed

+13264
-0
lines changed

integrations/vscode/.eslintrc.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
/*
27+
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
28+
https://github.com/typescript-eslint/tslint-to-eslint-config
29+
30+
It represents the closest reasonable ESLint configuration to this
31+
project's original TSLint configuration.
32+
33+
We recommend eventually switching this configuration to extend from
34+
the recommended rulesets in typescript-eslint.
35+
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
36+
37+
Happy linting! 💖
38+
*/
39+
40+
/* eslint-disable @typescript-eslint/naming-convention */
41+
42+
/**@type {import('eslint').ESLint.ConfigData}*/
43+
module.exports = {
44+
"env": {
45+
"browser": true,
46+
"es6": true,
47+
"node": true
48+
},
49+
"parser": "@typescript-eslint/parser",
50+
"parserOptions": {
51+
"project": "tsconfig.eslint.json",
52+
"tsconfigRootDir": __dirname,
53+
"sourceType": "module"
54+
},
55+
"plugins": [
56+
"@typescript-eslint"
57+
],
58+
"root": true,
59+
"rules": {
60+
"@typescript-eslint/member-delimiter-style": [
61+
"warn",
62+
{
63+
"multiline": {
64+
"delimiter": "semi",
65+
"requireLast": true
66+
},
67+
"singleline": {
68+
"delimiter": "semi",
69+
"requireLast": false
70+
}
71+
}
72+
],
73+
"@typescript-eslint/naming-convention": "off",
74+
"@typescript-eslint/no-unused-expressions": "warn",
75+
"@typescript-eslint/semi": [
76+
"warn",
77+
"always"
78+
],
79+
"curly": "off",
80+
"eqeqeq": [
81+
"warn",
82+
"always"
83+
],
84+
"no-redeclare": "warn",
85+
"no-throw-literal": "warn",
86+
"no-unused-expressions": "off",
87+
"semi": "off"
88+
}
89+
};

integrations/vscode/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
node_modules/
3+
*.vsix
4+
LICENSE.txt

integrations/vscode/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v14.16.0
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Run Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"runtimeExecutable": "${execPath}",
13+
"args": [
14+
"--extensionDevelopmentPath=${workspaceFolder}"
15+
],
16+
"outFiles": [
17+
"${workspaceFolder}/out/**/*.js",
18+
"${workspaceFolder}/dist/**/*.js"
19+
],
20+
"preLaunchTask": "npm: compile"
21+
}
22+
]
23+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"out": true // set this to false to include "out" folder in search results
8+
},
9+
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10+
"typescript.tsc.autoDetect": "off"
11+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "watch",
9+
"problemMatcher": "$tsc-watch",
10+
"isBackground": true,
11+
"presentation": {
12+
"reveal": "never"
13+
},
14+
"group": {
15+
"kind": "build",
16+
"isDefault": true
17+
}
18+
}
19+
]
20+
}

integrations/vscode/.vscodeignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.vscode/**
2+
node_modules/**
3+
out/**
4+
src/**
5+
.gitignore
6+
webpack.config.js
7+
**/tsconfig*.json
8+
**/tslint.json
9+
**/*.map
10+
**/*.ts

integrations/vscode/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
## Version 0.1.0
4+
* Initial release

integrations/vscode/README.md

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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).
10.5 KB
Loading

0 commit comments

Comments
 (0)