Skip to content

IntelliJ IDEA Integration

Use LeanJ directly in IntelliJ IDEA to see performance metrics in your code editor.

  • IntelliJ IDEA 2023.1+ (2025.2 tested)
  • LeanJ CLI installed and in PATH (or configured via system property)
  • Java JDK 11+ for the profiled application
  1. In IntelliJ IDEA, go to File → Settings → Plugins
  2. Search for “LeanJ”
  3. Click Install
  4. Restart IDE when prompted

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

  1. System property: -Dleanj.cli.path=<path>
  2. PATH environment variable
  3. Plugin bundle (future)

Set system property:

  • Go to Help → Edit Custom VM Options…
  • Add: -Dleanj.cli.path=C:\path\to\leanj.exe
  • Restart IDE

Or add CLI to PATH (recommended):

  1. Start LeanJ Profiling:
    • Go to Run → Start LeanJ Profiling

The plugin 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 Profiler tool window
  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 IntelliJ:

    • Run → Start LeanJ 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 View → Tool Windows → Profiler
  2. Or click the Profiler tab at the bottom

The tool window shows:

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

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.

Enable CodeVision in IntelliJ:

  1. File → Settings → Editor → Inlay Hints
  2. Enable Code Vision
  3. Enable LeanJ 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 plugin shows metrics from all attached JVMs

  3. Metrics are aggregated per method

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. Plugin 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. Add to PATH or set system property: -Dleanj.cli.path=<path>
  4. Restart IDE

Error: Controller not running

Solution:

  1. Start controller manually: leanj controller start
  2. Or let plugin start it automatically
  3. Check logs: logs/profiler-controller.log

Issue: CodeVision hints not showing

Solution:

  1. Enable CodeVision: Settings → Editor → Inlay Hints
  2. Ensure agent is attached: leanj status
  3. Check controller logs for errors
  4. Verify application is running and being profiled

Issue: Metrics are stale

Solution:

  1. Check controller is receiving data: leanj status
  2. Verify agent is connected: check controller logs
  3. Restart profiling: Run → Start LeanJ Profiling

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 IDE workspace path
  • Uses user.dir comparison

This helps identify the correct JVM when multiple are running.