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);
}
}
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.
Go to Settings/Preferences | Build, Execution, Deployment | Java Profiler. Click Add New Configuration and select the profiler. Modify the profiler options as required.
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.
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.
Set the breakpoint to suspend the current thread only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With