Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling in VisualVm Using IntelliJ with Debug

I want to profile my test application started by IntelliJ. For profiling I useVisualVm.

I started the java tool with the parameter -J-Dorg.netbeans.profiler.separateConsole=true.

I started the application with the VM parameter -Xverify:none, otherwise VisualVM throws an error if I start profiling (Redefinition failed with error 62)

I want to profile my application before any important code has beed executed, so I tried to set a break point and start profiling in VisualVM. The problem is that VisualVm doesn't respond to any interaction while I'm waiting at my break point. Do I miss something?

In normal execution (without debugging) my program waits for input, so I can profile it without debugging. But what if a program doesn't has such "waiting points"?

My test application looks like that:

package my.visualvm.example;

import java.util.Scanner;

public class MainClass {

    public static void main(String[] args) {

        System.out.println("Starting Application: " + MainClass.class.getSimpleName());

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            double value = scanner.nextDouble();
            if (value == 0d) {
                break;
            }
            System.out.println(Powa.powaPowa(value));
        }

        System.out.println("Stopping Application: " + MainClass.class.getSimpleName());
    }

}

Other class:

package my.visualvm.example;

final class Powa {

    private Powa() {
    }

    static double powaPowa(double powa) {
        return Math.pow(powa, 2);
    }
}
like image 427
Klemens Morbe Avatar asked Aug 06 '17 14:08

Klemens Morbe


People also ask

Does IntelliJ have a profiler?

By default, IntelliJ IDEA runs both profilers in parallel to provide most accurate results. While it is possible to use the supported profilers separately, the combined configuration that you get out of the box is a better choice for most scenarios.

How do I enable IntelliJ profiler?

Go to Settings/Preferences | Build, Execution, Deployment | Java Profiler. Click Add New Configuration and select the profiler. Modify the profiler options as required.

How do I use spot profiler in IntelliJ?

JetBrains s.r.o. Plugin for IntelliJ IDEA which simplifies measuring execution time for selected pieces of code. Select target line(s) in a Java or Kotlin (Kotlin plugin version 1.4 or later is required) file, invoke 'Profile Code Fragment' from context menu, and run the code.

How do I add VisualVM to IntelliJ?

1 from https://visualvm.dev.java.net/download.html 2. Install it to "C:/Program Files/visualvm" 3. Configure the plugin (Settings | VisualVM) by pointing it to "C:/Program Files/visualvm" 4. Click the "Profile CPU" button (next to the "Run" and "Debug" buttons) to begin profiling.


1 Answers

Set the breakpoint to suspend the current thread only. enter image description here

like image 196
Meo Avatar answered Nov 15 '22 07:11

Meo