VS Code Integration
VS Code Integration
Section titled “VS Code Integration”Use LeanJ directly in Visual Studio Code to see performance metrics in your code editor.
Prerequisites
Section titled “Prerequisites”- Visual Studio Code 1.80+
- LeanJ CLI installed and in PATH (or configured via settings)
- Java JDK 11+ for the profiled application
- Java Extension Pack installed (recommended)
Installation
Section titled “Installation”Install the Extension
Section titled “Install the Extension”- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search for “LeanJ”
- Click Install
- Reload VS Code when prompted
Configure CLI Path
Section titled “Configure CLI Path”The extension needs to find the CLI. It searches in this order:
- Extension settings:
leanj.cliPath - PATH environment variable
Set extension setting:
- Go to File → Preferences → Settings (or Code → Settings → Settings on macOS)
- Search for “LeanJ”
- Set LeanJ: Cli Path to your CLI executable path:
- Windows:
C:\path\to\leanj.exe - macOS/Linux:
/path/to/leanj
- Windows:
Or add CLI to PATH (recommended):
- See Installation Guide for PATH setup
Method 1: Automatic (Recommended)
Section titled “Method 1: Automatic (Recommended)”- Start LeanJ Profiling:
- Open Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
- Run: LeanJ: Start Profiling
The extension automatically:
- Calls the CLI
- Starts the controller (if not running)
- Discovers JVMs
- Attaches the agent
-
Run your application:
- Use your normal run configuration
- The agent is already attached
-
View metrics:
- Open your Java files
- See inline hints above methods
- Hover for detailed popup
- Check the LeanJ panel in the sidebar
Method 2: Manual CLI + IDE
Section titled “Method 2: Manual CLI + IDE”-
Start controller manually:
Terminal window leanj controller start -
Discover JVMs:
Terminal window leanj jvms -
Attach agent:
Terminal window leanj attach --pid <pid> -
Start profiling in VS Code:
- Command Palette → LeanJ: Start Profiling
Viewing Metrics
Section titled “Viewing Metrics”Inline Hints
Section titled “Inline Hints”Metrics appear directly above method declarations:
╰─ Estimated avg execution time: 2.1ms╰─ Max time last run: 4.8ms╰─ Allocations per call: ~12KB╰─ Call count: 150╰─ Trend: +15%
public void processPayments() { // your code}Hover Popup
Section titled “Hover Popup”Hover over a method to see detailed metrics:
- Average execution time
- Maximum time
- Allocations
- Call count
- Trend (percentage change)
- Context information
Profiler Panel
Section titled “Profiler Panel”- Open the LeanJ panel in the sidebar
- Or use Command Palette: LeanJ: Show Panel
The panel shows:
- All profiled methods
- Real-time statistics
- Filtering and sorting options
- JVM connection status
Metrics Explained
Section titled “Metrics Explained”Average Execution Time
Section titled “Average Execution Time”Cumulative average from profiling start. Shows typical performance.
Max Time
Section titled “Max Time”Maximum execution time in the last measurement window. Helps identify outliers.
Allocations
Section titled “Allocations”Memory allocated per call. Useful for finding memory-intensive operations.
Call Count
Section titled “Call Count”Total number of method invocations since profiling started.
Percentage change compared to previous measurement. Positive means slower, negative means faster.
Extension Settings
Section titled “Extension Settings”Configure the extension behavior:
- File → Preferences → Settings
- Search for “LeanJ”
Available settings:
- LeanJ: Cli Path: Path to CLI executable
- LeanJ: Auto Start Controller: Automatically start controller when profiling
- LeanJ: Refresh Interval: Metrics refresh interval in milliseconds
- LeanJ: Show Inline Hints: Enable/disable inline hints
Multiple JVM Support
Section titled “Multiple JVM Support”You can profile multiple JVMs simultaneously:
-
Attach to multiple JVMs using CLI:
Terminal window leanj attach --pid 12345leanj attach --pid 67890 -
The extension shows metrics from all attached JVMs
-
Metrics are aggregated per method
-
Use the JVM selector in the panel to filter by JVM
Docker JVMs
Section titled “Docker JVMs”Docker containers with the agent automatically appear in the JVM list:
-
Ensure agent is configured in Dockerfile:
ENV JAVA_TOOL_OPTIONS="-javaagent:/agent/agent.jar"ENV LEANJ_PROJECT=my-service -
Container starts and registers with controller
-
Appears in
leanj jvmsoutput -
Extension can attach and show metrics
Troubleshooting
Section titled “Troubleshooting”CLI Not Found
Section titled “CLI Not Found”Error: CLI not found
Solution:
- Verify CLI is installed: See Installation Guide
- Check CLI is in PATH:
leanj --version - Set extension setting:
leanj.cliPath - Reload VS Code
Controller Not Running
Section titled “Controller Not Running”Error: Controller not running
Solution:
- Start controller manually:
leanj controller start - Or enable auto-start in extension settings
- Check logs:
logs/profiler-controller.log
No Metrics Visible
Section titled “No Metrics Visible”Issue: Inline hints not showing
Solution:
- Enable inline hints in extension settings
- Ensure agent is attached:
leanj status - Check controller logs for errors
- Verify application is running and being profiled
- Reload VS Code window
Metrics Not Updating
Section titled “Metrics Not Updating”Issue: Metrics are stale
Solution:
- Check controller is receiving data:
leanj status - Verify agent is connected: check controller logs
- Restart profiling: Command Palette → LeanJ: Start Profiling
- Adjust refresh interval in settings
Advanced Configuration
Section titled “Advanced Configuration”Custom Controller Port
Section titled “Custom Controller Port”Set environment variable:
export LEANJ_CONTROLLER_PORT=8888Or use CLI:
leanj controller start --port 8888Workspace Matching
Section titled “Workspace Matching”The CLI automatically matches JVMs to your workspace:
- Compares Git root
- Matches VS Code workspace path
- Uses
user.dircomparison
This helps identify the correct JVM when multiple are running.
Next Steps
Section titled “Next Steps”- Learn about Docker integration
- Explore CLI commands
- Configure advanced settings
- Read How It Works for architecture details