Skip to content

VS Code Integration

Use LeanJ directly in Visual Studio Code to see performance metrics in your code editor.

  • 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)
  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
  3. Search for “LeanJ”
  4. Click Install
  5. Reload VS Code when prompted

The extension needs to find the CLI. It searches in this order:

  1. Extension settings: leanj.cliPath
  2. PATH environment variable

Set extension setting:

  1. Go to File → Preferences → Settings (or Code → Settings → Settings on macOS)
  2. Search for “LeanJ”
  3. Set LeanJ: Cli Path to your CLI executable path:
    • Windows: C:\path\to\leanj.exe
    • macOS/Linux: /path/to/leanj

Or add CLI to PATH (recommended):

  1. 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
  1. Run your application:

    • Use your normal run configuration
    • The agent is already attached
  2. View metrics:

    • Open your Java files
    • See inline hints above methods
    • Hover for detailed popup
    • Check the LeanJ panel in the sidebar
  1. Start controller manually:

    Terminal window
    leanj controller start
  2. Discover JVMs:

    Terminal window
    leanj jvms
  3. Attach agent:

    Terminal window
    leanj attach --pid <pid>
  4. Start profiling in VS Code:

    • Command Palette → LeanJ: Start Profiling

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 over a method to see detailed metrics:

  • Average execution time
  • Maximum time
  • Allocations
  • Call count
  • Trend (percentage change)
  • Context information
  1. Open the LeanJ panel in the sidebar
  2. Or use Command Palette: LeanJ: Show Panel

The panel shows:

  • All profiled methods
  • Real-time statistics
  • Filtering and sorting options
  • JVM connection status

Cumulative average from profiling start. Shows typical performance.

Maximum execution time in the last measurement window. Helps identify outliers.

Memory allocated per call. Useful for finding memory-intensive operations.

Total number of method invocations since profiling started.

Percentage change compared to previous measurement. Positive means slower, negative means faster.

Configure the extension behavior:

  1. File → Preferences → Settings
  2. 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

You can profile multiple JVMs simultaneously:

  1. Attach to multiple JVMs using CLI:

    Terminal window
    leanj attach --pid 12345
    leanj attach --pid 67890
  2. The extension shows metrics from all attached JVMs

  3. Metrics are aggregated per method

  4. Use the JVM selector in the panel to filter by JVM

Docker containers with the agent automatically appear in the JVM list:

  1. Ensure agent is configured in Dockerfile:

    ENV JAVA_TOOL_OPTIONS="-javaagent:/agent/agent.jar"
    ENV LEANJ_PROJECT=my-service
  2. Container starts and registers with controller

  3. Appears in leanj jvms output

  4. Extension can attach and show metrics

Error: CLI not found

Solution:

  1. Verify CLI is installed: See Installation Guide
  2. Check CLI is in PATH: leanj --version
  3. Set extension setting: leanj.cliPath
  4. Reload VS Code

Error: Controller not running

Solution:

  1. Start controller manually: leanj controller start
  2. Or enable auto-start in extension settings
  3. Check logs: logs/profiler-controller.log

Issue: Inline hints not showing

Solution:

  1. Enable inline hints in extension settings
  2. Ensure agent is attached: leanj status
  3. Check controller logs for errors
  4. Verify application is running and being profiled
  5. Reload VS Code window

Issue: Metrics are stale

Solution:

  1. Check controller is receiving data: leanj status
  2. Verify agent is connected: check controller logs
  3. Restart profiling: Command Palette → LeanJ: Start Profiling
  4. Adjust refresh interval in settings

Set environment variable:

Terminal window
export LEANJ_CONTROLLER_PORT=8888

Or use CLI:

Terminal window
leanj controller start --port 8888

The CLI automatically matches JVMs to your workspace:

  • Compares Git root
  • Matches VS Code workspace path
  • Uses user.dir comparison

This helps identify the correct JVM when multiple are running.